about summary refs log tree commit diff
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2025-01-03 19:57:30 +0800
committer许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2025-01-03 19:57:30 +0800
commit7b763031e12c6f8455ea1b4b7c39adcb00391c1b (patch)
tree5f8dc7b3a8326809e7a32930487bfe973d1446eb
parentf7d0842198df9c47a75c397cff62bd56a3c023f8 (diff)
downloadrust-7b763031e12c6f8455ea1b4b7c39adcb00391c1b.tar.gz
rust-7b763031e12c6f8455ea1b4b7c39adcb00391c1b.zip
run-make-support: add basic sanity tests for assertion helpers
-rw-r--r--src/tools/run-make-support/src/assertion_helpers/mod.rs3
-rw-r--r--src/tools/run-make-support/src/assertion_helpers/tests.rs100
2 files changed, 103 insertions, 0 deletions
diff --git a/src/tools/run-make-support/src/assertion_helpers/mod.rs b/src/tools/run-make-support/src/assertion_helpers/mod.rs
index e84a3cf633f..ae926f0c207 100644
--- a/src/tools/run-make-support/src/assertion_helpers/mod.rs
+++ b/src/tools/run-make-support/src/assertion_helpers/mod.rs
@@ -1,5 +1,8 @@
 //! Collection of assertions and assertion-related helpers.
 
+#[cfg(test)]
+mod tests;
+
 use std::panic;
 use std::path::Path;
 
diff --git a/src/tools/run-make-support/src/assertion_helpers/tests.rs b/src/tools/run-make-support/src/assertion_helpers/tests.rs
new file mode 100644
index 00000000000..8bf7740d2e6
--- /dev/null
+++ b/src/tools/run-make-support/src/assertion_helpers/tests.rs
@@ -0,0 +1,100 @@
+//! Basic sanity checks for assertion helpers.
+use super::*;
+
+mod test_assert_equals {
+    use super::*;
+
+    #[test]
+    fn assert_equals_same() {
+        assert_equals("foo", "foo");
+        assert_equals("", "");
+    }
+
+    #[test]
+    #[should_panic]
+    fn assert_equals_different() {
+        assert_equals("foo", "bar");
+    }
+}
+
+mod test_assert_contains {
+    use super::*;
+
+    #[test]
+    fn assert_contains_yes() {
+        assert_contains("", "");
+        assert_contains(" ", "");
+        assert_contains("a", "a");
+        assert_contains("ab", "a");
+    }
+
+    #[test]
+    #[should_panic]
+    fn assert_contains_no() {
+        assert_contains("a", "b");
+    }
+}
+
+mod test_assert_not_contains {
+    use super::*;
+
+    #[test]
+    fn assert_not_contains_yes() {
+        assert_not_contains("a", "b");
+    }
+
+    #[test]
+    #[should_panic]
+    fn assert_not_contains_no() {
+        assert_not_contains(" ", "");
+    }
+}
+
+mod assert_contains_regex {
+    use super::*;
+
+    #[test]
+    fn assert_contains_regex_yes() {
+        assert_contains_regex("", "");
+        assert_contains_regex("", ".*");
+        assert_contains_regex("abcde", ".*");
+        assert_contains_regex("abcde", ".+");
+    }
+
+    #[test]
+    #[should_panic]
+    fn assert_contains_regex_no() {
+        assert_contains_regex("", ".+");
+    }
+}
+
+mod assert_not_contains_regex_regex {
+    use super::*;
+
+    #[test]
+    fn assert_not_contains_regex_yes() {
+        assert_not_contains_regex("abc", "d");
+    }
+
+    #[test]
+    #[should_panic]
+    fn assert_not_contains_regex_no() {
+        assert_not_contains_regex("abc", ".*");
+    }
+}
+
+mod test_assert_count_is {
+    use super::*;
+
+    #[test]
+    fn assert_count_is_yes() {
+        assert_count_is(0, "", "b");
+        assert_count_is(3, "abcbdb", "b");
+    }
+
+    #[test]
+    #[should_panic]
+    fn assert_count_is_no() {
+        assert_count_is(2, "abcbdb", "b");
+    }
+}