about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPhilipp Hansch <dev@phansch.net>2018-12-15 10:58:03 +0100
committerPhilipp Hansch <dev@phansch.net>2018-12-15 11:00:26 +0100
commit818f6823ad6f4faa09dd859ea83942e93e470860 (patch)
tree7916b2cce979882e4b05ee53c6b54d1d6642ed7a
parent61780083cdf56976f6a09b906b616928b433f001 (diff)
downloadrust-818f6823ad6f4faa09dd859ea83942e93e470860.tar.gz
rust-818f6823ad6f4faa09dd859ea83942e93e470860.zip
compiletest: Add some compiletest::util unittests
-rw-r--r--src/tools/compiletest/src/util.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/tools/compiletest/src/util.rs b/src/tools/compiletest/src/util.rs
index 2a716970ca7..381d808e802 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"));
+}