Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend compiletest to support subdirectories #31749

Merged
merged 7 commits into from
Feb 26, 2016
31 changes: 16 additions & 15 deletions mk/tests.mk
Original file line number Diff line number Diff line change
@@ -458,21 +458,22 @@ $(foreach host,$(CFG_HOST), \
# Rules for the compiletest tests (rpass, rfail, etc.)
######################################################################

RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
RPASS_VALGRIND_RS := $(wildcard $(S)src/test/run-pass-valgrind/*.rs)
RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
RFAIL_FULL_RS := $(wildcard $(S)src/test/run-fail-fulldeps/*.rs)
CFAIL_FULL_RS := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rs)
RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
PFAIL_RS := $(wildcard $(S)src/test/parse-fail/*.rs)
PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
DEBUGINFO_GDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
DEBUGINFO_LLDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
CODEGEN_UNITS_RS := $(wildcard $(S)src/test/codegen-units/*.rs)
RUSTDOCCK_RS := $(wildcard $(S)src/test/rustdoc/*.rs)
RPASS_RS := $(call rwildcard,$(S)src/test/run-pass/,*.rs)
RPASS_VALGRIND_RS := $(call rwildcard,$(S)src/test/run-pass-valgrind/,*.rs)
RPASS_FULL_RS := $(call rwildcard,$(S)src/test/run-pass-fulldeps/,*.rs)
RFAIL_FULL_RS := $(call rwildcard,$(S)src/test/run-fail-fulldeps/,*.rs)
CFAIL_FULL_RS := $(call rwildcard,$(S)src/test/compile-fail-fulldeps/,*.rs)
RFAIL_RS := $(call rwildcard,$(S)src/test/run-fail/,*.rs)
RFAIL_RS := $(call rwildcard,$(S)src/test/run-fail/,*.rs)
CFAIL_RS := $(call rwildcard,$(S)src/test/compile-fail/,*.rs)
PFAIL_RS := $(call rwildcard,$(S)src/test/parse-fail/,*.rs)
PRETTY_RS := $(call rwildcard,$(S)src/test/pretty/,*.rs)
DEBUGINFO_GDB_RS := $(call rwildcard,$(S)src/test/debuginfo/,*.rs)
DEBUGINFO_LLDB_RS := $(call rwildcard,$(S)src/test/debuginfo/,*.rs)
CODEGEN_RS := $(call rwildcard,$(S)src/test/codegen/,*.rs)
CODEGEN_CC := $(call rwildcard,$(S)src/test/codegen/,*.cc)
CODEGEN_UNITS_RS := $(call rwildcard,$(S)src/test/codegen-units/,*.rs)
RUSTDOCCK_RS := $(call rwildcard,$(S)src/test/rustdoc/,*.rs)

RPASS_TESTS := $(RPASS_RS)
RPASS_VALGRIND_TESTS := $(RPASS_VALGRIND_RS)
37 changes: 26 additions & 11 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
@@ -284,6 +284,16 @@ fn collect_tests_from_dir(config: &Config,
relative_dir_path: &Path,
tests: &mut Vec<test::TestDescAndFn>)
-> io::Result<()> {
// Ignore directories that contain a file
// `compiletest-ignore-dir`.
for file in try!(fs::read_dir(dir)) {
let file = try!(file);
if file.file_name() == *"compiletest-ignore-dir" {
return Ok(());
}
}

let dirs = try!(fs::read_dir(dir));
for file in dirs {
let file = try!(file);
let file_path = file.path();
@@ -295,6 +305,13 @@ fn collect_tests_from_dir(config: &Config,
relative_dir: relative_dir_path.to_path_buf(),
};
tests.push(make_test(config, &paths))
} else if file_path.is_dir() {
let relative_file_path = relative_dir_path.join(file.file_name());
try!(collect_tests_from_dir(config,
base,
&file_path,
&relative_file_path,
tests));
}
}
Ok(())
@@ -338,17 +355,15 @@ pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn
}
}

pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {

// Try to elide redundant long paths
fn shorten(path: &Path) -> String {
let filename = path.file_name().unwrap().to_str();
let p = path.parent().unwrap();
let dir = p.file_name().unwrap().to_str();
format!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
}

test::DynTestName(format!("[{}] {}", config.mode, shorten(testfile)))
pub fn make_test_name(config: &Config, testpaths: &TestPaths) -> test::TestName {
// Convert a complete path to something like
//
// run-pass/foo/bar/baz.rs
let path =
PathBuf::from(config.mode.to_string())
.join(&testpaths.relative_dir)
.join(&testpaths.file.file_name().unwrap());
test::DynTestName(format!("[{}] {}", config.mode, path.display()))
}

pub fn make_test_closure(config: &Config, testpaths: &TestPaths) -> test::TestFn {
23 changes: 20 additions & 3 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
@@ -1214,6 +1214,21 @@ fn exec_compiled_test(config: &Config, props: &TestProps,
}
}

fn compute_aux_test_paths(config: &Config,
testpaths: &TestPaths,
rel_ab: &str)
-> TestPaths
{
let abs_ab = config.aux_base.join(rel_ab);
TestPaths {
file: abs_ab,
base: testpaths.base.clone(),
relative_dir: Path::new(rel_ab).parent()
.map(|p| p.to_path_buf())
.unwrap_or_else(|| PathBuf::new())
}
}

fn compose_and_run_compiler(config: &Config, props: &TestProps,
testpaths: &TestPaths, args: ProcArgs,
input: Option<String>) -> ProcRes {
@@ -1501,9 +1516,11 @@ fn output_testname(filepath: &Path) -> PathBuf {
PathBuf::from(filepath.file_stem().unwrap())
}

fn output_base_name(config: &Config, testfile: &Path) -> PathBuf {
config.build_base
.join(&output_testname(testfile))
fn output_base_name(config: &Config, testpaths: &TestPaths) -> PathBuf {
let dir = config.build_base.join(&testpaths.relative_dir);
fs::create_dir_all(&dir).unwrap();
dir
.join(&output_testname(&testpaths.file))
.with_extension(&config.stage_id)
}