Skip to content

Commit 10b3a4e

Browse files
committed
Auto merge of #31749 - nikomatsakis:compiletest-subdir, r=nikomatsakis
You can now group tests into directories like `run-pass/borrowck` or `compile-fail/borrowck`. By default, all `.rs` files within any directory are considered tests: to ignore some directory, create a placeholder file called `compiletest-ignore-dir` (I had to do this for several existing directories). r? @alexcrichton cc @brson
2 parents 0ef8d42 + c4b6037 commit 10b3a4e

File tree

171 files changed

+273
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+273
-200
lines changed

mk/tests.mk

+16-15
Original file line numberDiff line numberDiff line change
@@ -458,21 +458,22 @@ $(foreach host,$(CFG_HOST), \
458458
# Rules for the compiletest tests (rpass, rfail, etc.)
459459
######################################################################
460460

461-
RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
462-
RPASS_VALGRIND_RS := $(wildcard $(S)src/test/run-pass-valgrind/*.rs)
463-
RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
464-
RFAIL_FULL_RS := $(wildcard $(S)src/test/run-fail-fulldeps/*.rs)
465-
CFAIL_FULL_RS := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rs)
466-
RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
467-
CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
468-
PFAIL_RS := $(wildcard $(S)src/test/parse-fail/*.rs)
469-
PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
470-
DEBUGINFO_GDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
471-
DEBUGINFO_LLDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
472-
CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
473-
CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
474-
CODEGEN_UNITS_RS := $(wildcard $(S)src/test/codegen-units/*.rs)
475-
RUSTDOCCK_RS := $(wildcard $(S)src/test/rustdoc/*.rs)
461+
RPASS_RS := $(call rwildcard,$(S)src/test/run-pass/,*.rs)
462+
RPASS_VALGRIND_RS := $(call rwildcard,$(S)src/test/run-pass-valgrind/,*.rs)
463+
RPASS_FULL_RS := $(call rwildcard,$(S)src/test/run-pass-fulldeps/,*.rs)
464+
RFAIL_FULL_RS := $(call rwildcard,$(S)src/test/run-fail-fulldeps/,*.rs)
465+
CFAIL_FULL_RS := $(call rwildcard,$(S)src/test/compile-fail-fulldeps/,*.rs)
466+
RFAIL_RS := $(call rwildcard,$(S)src/test/run-fail/,*.rs)
467+
RFAIL_RS := $(call rwildcard,$(S)src/test/run-fail/,*.rs)
468+
CFAIL_RS := $(call rwildcard,$(S)src/test/compile-fail/,*.rs)
469+
PFAIL_RS := $(call rwildcard,$(S)src/test/parse-fail/,*.rs)
470+
PRETTY_RS := $(call rwildcard,$(S)src/test/pretty/,*.rs)
471+
DEBUGINFO_GDB_RS := $(call rwildcard,$(S)src/test/debuginfo/,*.rs)
472+
DEBUGINFO_LLDB_RS := $(call rwildcard,$(S)src/test/debuginfo/,*.rs)
473+
CODEGEN_RS := $(call rwildcard,$(S)src/test/codegen/,*.rs)
474+
CODEGEN_CC := $(call rwildcard,$(S)src/test/codegen/,*.cc)
475+
CODEGEN_UNITS_RS := $(call rwildcard,$(S)src/test/codegen-units/,*.rs)
476+
RUSTDOCCK_RS := $(call rwildcard,$(S)src/test/rustdoc/,*.rs)
476477

477478
RPASS_TESTS := $(RPASS_RS)
478479
RPASS_VALGRIND_TESTS := $(RPASS_VALGRIND_RS)

src/compiletest/compiletest.rs

+62-26
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,52 @@ 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<()> {
287+
// Ignore directories that contain a file
288+
// `compiletest-ignore-dir`.
289+
for file in try!(fs::read_dir(dir)) {
290+
let file = try!(file);
291+
if file.file_name() == *"compiletest-ignore-dir" {
292+
return Ok(());
293+
}
294+
}
295+
296+
let dirs = try!(fs::read_dir(dir));
271297
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))
298+
let file = try!(file);
299+
let file_path = file.path();
300+
debug!("inspecting file {:?}", file_path.display());
301+
if is_test(config, &file_path) {
302+
let paths = TestPaths {
303+
file: file_path,
304+
base: base.to_path_buf(),
305+
relative_dir: relative_dir_path.to_path_buf(),
306+
};
307+
tests.push(make_test(config, &paths))
308+
} else if file_path.is_dir() {
309+
let relative_file_path = relative_dir_path.join(file.file_name());
310+
try!(collect_tests_from_dir(config,
311+
base,
312+
&file_path,
313+
&relative_file_path,
314+
tests));
276315
}
277316
}
278-
tests
317+
Ok(())
279318
}
280319

281320
pub fn is_test(config: &Config, testfile: &Path) -> bool {
@@ -305,36 +344,33 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
305344
return valid;
306345
}
307346

308-
pub fn make_test(config: &Config, testfile: &Path) -> test::TestDescAndFn
309-
{
347+
pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn {
310348
test::TestDescAndFn {
311349
desc: test::TestDesc {
312-
name: make_test_name(config, testfile),
313-
ignore: header::is_test_ignored(config, testfile),
350+
name: make_test_name(config, testpaths),
351+
ignore: header::is_test_ignored(config, &testpaths.file),
314352
should_panic: test::ShouldPanic::No,
315353
},
316-
testfn: make_test_closure(config, &testfile),
354+
testfn: make_test_closure(config, testpaths),
317355
}
318356
}
319357

320-
pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
321-
322-
// Try to elide redundant long paths
323-
fn shorten(path: &Path) -> String {
324-
let filename = path.file_name().unwrap().to_str();
325-
let p = path.parent().unwrap();
326-
let dir = p.file_name().unwrap().to_str();
327-
format!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
328-
}
329-
330-
test::DynTestName(format!("[{}] {}", config.mode, shorten(testfile)))
358+
pub fn make_test_name(config: &Config, testpaths: &TestPaths) -> test::TestName {
359+
// Convert a complete path to something like
360+
//
361+
// run-pass/foo/bar/baz.rs
362+
let path =
363+
PathBuf::from(config.mode.to_string())
364+
.join(&testpaths.relative_dir)
365+
.join(&testpaths.file.file_name().unwrap());
366+
test::DynTestName(format!("[{}] {}", config.mode, path.display()))
331367
}
332368

333-
pub fn make_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
334-
let config = (*config).clone();
335-
let testfile = testfile.to_path_buf();
369+
pub fn make_test_closure(config: &Config, testpaths: &TestPaths) -> test::TestFn {
370+
let config = config.clone();
371+
let testpaths = testpaths.clone();
336372
test::DynTestFn(Box::new(move || {
337-
runtest::run(config, &testfile)
373+
runtest::run(config, &testpaths)
338374
}))
339375
}
340376

0 commit comments

Comments
 (0)