Skip to content

Commit

Permalink
Rollup merge of #56841 - phansch:add_various_compiletest_unittests, r…
Browse files Browse the repository at this point in the history
…=oli-obk

Add some unit tests to compiletest

Based on #56792, otherwise the tests won't be executed on CI.

Just a small start, I would like to add more testing to compiletest in the future but that will require some refactoring first.

cc #47606
  • Loading branch information
pietroalbini committed Dec 15, 2018
2 parents eed9693 + 9637c27 commit 3566812
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,3 +873,29 @@ fn parse_normalization_string(line: &mut &str) -> Option<String> {
*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).");
}
28 changes: 28 additions & 0 deletions src/tools/compiletest/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"));
}

0 comments on commit 3566812

Please sign in to comment.