Skip to content

Commit 3566812

Browse files
authored
Rollup merge of #56841 - phansch:add_various_compiletest_unittests, r=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
2 parents eed9693 + 9637c27 commit 3566812

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/tools/compiletest/src/header.rs

+26
Original file line numberDiff line numberDiff line change
@@ -873,3 +873,29 @@ fn parse_normalization_string(line: &mut &str) -> Option<String> {
873873
*line = &line[end + 1..];
874874
Some(result)
875875
}
876+
877+
#[test]
878+
fn test_parse_normalization_string() {
879+
let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\".";
880+
let first = parse_normalization_string(&mut s);
881+
assert_eq!(first, Some("something (32 bits)".to_owned()));
882+
assert_eq!(s, " -> \"something ($WORD bits)\".");
883+
884+
// Nothing to normalize (No quotes)
885+
let mut s = "normalize-stderr-32bit: something (32 bits) -> something ($WORD bits).";
886+
let first = parse_normalization_string(&mut s);
887+
assert_eq!(first, None);
888+
assert_eq!(s, r#"normalize-stderr-32bit: something (32 bits) -> something ($WORD bits)."#);
889+
890+
// Nothing to normalize (Only a single quote)
891+
let mut s = "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits).";
892+
let first = parse_normalization_string(&mut s);
893+
assert_eq!(first, None);
894+
assert_eq!(s, "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits).");
895+
896+
// Nothing to normalize (Three quotes)
897+
let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits).";
898+
let first = parse_normalization_string(&mut s);
899+
assert_eq!(first, Some("something (32 bits)".to_owned()));
900+
assert_eq!(s, " -> \"something ($WORD bits).");
901+
}

src/tools/compiletest/src/util.rs

+28
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ pub fn matches_os(triple: &str, name: &str) -> bool {
8686
}
8787
panic!("Cannot determine OS from triple");
8888
}
89+
90+
/// Determine the architecture from `triple`
8991
pub fn get_arch(triple: &str) -> &'static str {
9092
let triple: Vec<_> = triple.split('-').collect();
9193
for &(triple_arch, arch) in ARCH_TABLE {
@@ -151,3 +153,29 @@ impl PathBufExt for PathBuf {
151153
}
152154
}
153155
}
156+
157+
#[test]
158+
#[should_panic(expected = "Cannot determine Architecture from triple")]
159+
fn test_get_arch_failure() {
160+
get_arch("abc");
161+
}
162+
163+
#[test]
164+
fn test_get_arch() {
165+
assert_eq!("x86_64", get_arch("x86_64-unknown-linux-gnu"));
166+
assert_eq!("x86_64", get_arch("amd64"));
167+
}
168+
169+
#[test]
170+
#[should_panic(expected = "Cannot determine OS from triple")]
171+
fn test_matches_os_failure() {
172+
matches_os("abc", "abc");
173+
}
174+
175+
#[test]
176+
fn test_matches_os() {
177+
assert!(matches_os("x86_64-unknown-linux-gnu", "linux"));
178+
assert!(matches_os("wasm32-unknown-unknown", "emscripten"));
179+
assert!(matches_os("wasm32-unknown-unknown", "wasm32-bare"));
180+
assert!(!matches_os("wasm32-unknown-unknown", "windows"));
181+
}

0 commit comments

Comments
 (0)