Skip to content

Commit 1adcefd

Browse files
committed
Generalize from passing around a single path to the test file to passing
around a set of paths called `TestPaths` This commit is not quite standalone; it basically contains all the borrowing plumbing bits, the interesting stuff comes in the next commit.
1 parent a9430a3 commit 1adcefd

File tree

3 files changed

+208
-171
lines changed

3 files changed

+208
-171
lines changed

src/compiletest/compiletest.rs

+36-15
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ extern crate log;
2828

2929
use std::env;
3030
use std::fs;
31+
use std::io;
3132
use std::path::{Path, PathBuf};
3233
use getopts::{optopt, optflag, reqopt};
3334
use common::Config;
3435
use common::{Pretty, DebugInfoGdb, DebugInfoLldb};
36+
use test::TestPaths;
3537
use util::logv;
3638

3739
pub mod procsrv;
@@ -267,15 +269,35 @@ pub fn make_tests(config: &Config) -> Vec<test::TestDescAndFn> {
267269
debug!("making tests from {:?}",
268270
config.src_base.display());
269271
let mut tests = Vec::new();
270-
let dirs = fs::read_dir(&config.src_base).unwrap();
272+
collect_tests_from_dir(config,
273+
&config.src_base,
274+
&config.src_base,
275+
&PathBuf::new(),
276+
&mut tests)
277+
.unwrap();
278+
tests
279+
}
280+
281+
fn collect_tests_from_dir(config: &Config,
282+
base: &Path,
283+
dir: &Path,
284+
relative_dir_path: &Path,
285+
tests: &mut Vec<test::TestDescAndFn>)
286+
-> io::Result<()> {
271287
for file in dirs {
272-
let file = file.unwrap().path();
273-
debug!("inspecting file {:?}", file.display());
274-
if is_test(config, &file) {
275-
tests.push(make_test(config, &file))
288+
let file = try!(file);
289+
let file_path = file.path();
290+
debug!("inspecting file {:?}", file_path.display());
291+
if is_test(config, &file_path) {
292+
let paths = TestPaths {
293+
file: file_path,
294+
base: base.to_path_buf(),
295+
relative_dir: relative_dir_path.to_path_buf(),
296+
};
297+
tests.push(make_test(config, &paths))
276298
}
277299
}
278-
tests
300+
Ok(())
279301
}
280302

281303
pub fn is_test(config: &Config, testfile: &Path) -> bool {
@@ -305,15 +327,14 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
305327
return valid;
306328
}
307329

308-
pub fn make_test(config: &Config, testfile: &Path) -> test::TestDescAndFn
309-
{
330+
pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn {
310331
test::TestDescAndFn {
311332
desc: test::TestDesc {
312-
name: make_test_name(config, testfile),
313-
ignore: header::is_test_ignored(config, testfile),
333+
name: make_test_name(config, testpaths),
334+
ignore: header::is_test_ignored(config, &testpaths.file),
314335
should_panic: test::ShouldPanic::No,
315336
},
316-
testfn: make_test_closure(config, &testfile),
337+
testfn: make_test_closure(config, testpaths),
317338
}
318339
}
319340

@@ -330,11 +351,11 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
330351
test::DynTestName(format!("[{}] {}", config.mode, shorten(testfile)))
331352
}
332353

333-
pub fn make_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
334-
let config = (*config).clone();
335-
let testfile = testfile.to_path_buf();
354+
pub fn make_test_closure(config: &Config, testpaths: &TestPaths) -> test::TestFn {
355+
let config = config.clone();
356+
let testpaths = testpaths.clone();
336357
test::DynTestFn(Box::new(move || {
337-
runtest::run(config, &testfile)
358+
runtest::run(config, &testpaths)
338359
}))
339360
}
340361

0 commit comments

Comments
 (0)