From 61780083cdf56976f6a09b906b616928b433f001 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Thu, 13 Dec 2018 21:57:23 +0100 Subject: [PATCH 1/3] Bootstrap: Add testsuite for compiletest tool The (currently) single unit test of the compiletest tool was never executed on CI. At least I couldn't find any references of it in the logs. This adds a test suite for compiletest so that our tester is tested, too. The compiletest tests can then also be executed with: ./x.py test src/tools/compiletest --- src/bootstrap/builder.rs | 1 + src/bootstrap/test.rs | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 32f3e573d6845..c1d56865da55c 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -416,6 +416,7 @@ impl<'a> Builder<'a> { test::Rustfmt, test::Miri, test::Clippy, + test::CompiletestTest, test::RustdocJS, test::RustdocTheme, // Run bootstrap close to the end as it's unlikely to fail diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index dc061fe5099a5..87d5737e2a0a2 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -429,6 +429,45 @@ impl Step for Miri { } } +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub struct CompiletestTest { + stage: u32, + host: Interned, +} + +impl Step for CompiletestTest { + type Output = (); + + fn should_run(run: ShouldRun) -> ShouldRun { + run.path("src/tools/compiletest") + } + + fn make_run(run: RunConfig) { + run.builder.ensure(CompiletestTest { + stage: run.builder.top_stage, + host: run.target, + }); + } + + /// Runs `cargo test` for compiletest. + fn run(self, builder: &Builder) { + let stage = self.stage; + let host = self.host; + let compiler = builder.compiler(stage, host); + + let mut cargo = tool::prepare_tool_cargo(builder, + compiler, + Mode::ToolBootstrap, + host, + "test", + "src/tools/compiletest", + SourceType::InTree, + &[]); + + try_run(builder, &mut cargo); + } +} + #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct Clippy { stage: u32, From 818f6823ad6f4faa09dd859ea83942e93e470860 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Sat, 15 Dec 2018 10:58:03 +0100 Subject: [PATCH 2/3] compiletest: Add some compiletest::util unittests --- src/tools/compiletest/src/util.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/tools/compiletest/src/util.rs b/src/tools/compiletest/src/util.rs index 2a716970ca7b9..381d808e8028f 100644 --- a/src/tools/compiletest/src/util.rs +++ b/src/tools/compiletest/src/util.rs @@ -86,6 +86,8 @@ pub fn matches_os(triple: &str, name: &str) -> bool { } panic!("Cannot determine OS from triple"); } + +/// Determine the architecture from `triple` pub fn get_arch(triple: &str) -> &'static str { let triple: Vec<_> = triple.split('-').collect(); for &(triple_arch, arch) in ARCH_TABLE { @@ -151,3 +153,29 @@ impl PathBufExt for PathBuf { } } } + +#[test] +#[should_panic(expected = "Cannot determine Architecture from triple")] +fn test_get_arch_failure() { + get_arch("abc"); +} + +#[test] +fn test_get_arch() { + assert_eq!("x86_64", get_arch("x86_64-unknown-linux-gnu")); + assert_eq!("x86_64", get_arch("amd64")); +} + +#[test] +#[should_panic(expected = "Cannot determine OS from triple")] +fn test_matches_os_failure() { + matches_os("abc", "abc"); +} + +#[test] +fn test_matches_os() { + assert!(matches_os("x86_64-unknown-linux-gnu", "linux")); + assert!(matches_os("wasm32-unknown-unknown", "emscripten")); + assert!(matches_os("wasm32-unknown-unknown", "wasm32-bare")); + assert!(!matches_os("wasm32-unknown-unknown", "windows")); +} From 9637c27fb531dc4a030bc978ebff4335baebc28d Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Sat, 15 Dec 2018 10:58:24 +0100 Subject: [PATCH 3/3] compiletest: unit test parse_normalization_string There is a FIXME inside that function and I think the unit tests can be helpful to resolve it without breaking anything else. --- src/tools/compiletest/src/header.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 003839982429f..8b3023e63dfb4 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -873,3 +873,29 @@ fn parse_normalization_string(line: &mut &str) -> Option { *line = &line[end + 1..]; Some(result) } + +#[test] +fn test_parse_normalization_string() { + let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\"."; + let first = parse_normalization_string(&mut s); + assert_eq!(first, Some("something (32 bits)".to_owned())); + assert_eq!(s, " -> \"something ($WORD bits)\"."); + + // Nothing to normalize (No quotes) + let mut s = "normalize-stderr-32bit: something (32 bits) -> something ($WORD bits)."; + let first = parse_normalization_string(&mut s); + assert_eq!(first, None); + assert_eq!(s, r#"normalize-stderr-32bit: something (32 bits) -> something ($WORD bits)."#); + + // Nothing to normalize (Only a single quote) + let mut s = "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits)."; + let first = parse_normalization_string(&mut s); + assert_eq!(first, None); + assert_eq!(s, "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits)."); + + // Nothing to normalize (Three quotes) + let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)."; + let first = parse_normalization_string(&mut s); + assert_eq!(first, Some("something (32 bits)".to_owned())); + assert_eq!(s, " -> \"something ($WORD bits)."); +}