Skip to content

Commit 818f682

Browse files
committed
compiletest: Add some compiletest::util unittests
1 parent 6178008 commit 818f682

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

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)