Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7b76303

Browse files
committed
run-make-support: add basic sanity tests for assertion helpers
1 parent f7d0842 commit 7b76303

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

src/tools/run-make-support/src/assertion_helpers/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//! Collection of assertions and assertion-related helpers.
22
3+
#[cfg(test)]
4+
mod tests;
5+
36
use std::panic;
47
use std::path::Path;
58

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//! Basic sanity checks for assertion helpers.
2+
use super::*;
3+
4+
mod test_assert_equals {
5+
use super::*;
6+
7+
#[test]
8+
fn assert_equals_same() {
9+
assert_equals("foo", "foo");
10+
assert_equals("", "");
11+
}
12+
13+
#[test]
14+
#[should_panic]
15+
fn assert_equals_different() {
16+
assert_equals("foo", "bar");
17+
}
18+
}
19+
20+
mod test_assert_contains {
21+
use super::*;
22+
23+
#[test]
24+
fn assert_contains_yes() {
25+
assert_contains("", "");
26+
assert_contains(" ", "");
27+
assert_contains("a", "a");
28+
assert_contains("ab", "a");
29+
}
30+
31+
#[test]
32+
#[should_panic]
33+
fn assert_contains_no() {
34+
assert_contains("a", "b");
35+
}
36+
}
37+
38+
mod test_assert_not_contains {
39+
use super::*;
40+
41+
#[test]
42+
fn assert_not_contains_yes() {
43+
assert_not_contains("a", "b");
44+
}
45+
46+
#[test]
47+
#[should_panic]
48+
fn assert_not_contains_no() {
49+
assert_not_contains(" ", "");
50+
}
51+
}
52+
53+
mod assert_contains_regex {
54+
use super::*;
55+
56+
#[test]
57+
fn assert_contains_regex_yes() {
58+
assert_contains_regex("", "");
59+
assert_contains_regex("", ".*");
60+
assert_contains_regex("abcde", ".*");
61+
assert_contains_regex("abcde", ".+");
62+
}
63+
64+
#[test]
65+
#[should_panic]
66+
fn assert_contains_regex_no() {
67+
assert_contains_regex("", ".+");
68+
}
69+
}
70+
71+
mod assert_not_contains_regex_regex {
72+
use super::*;
73+
74+
#[test]
75+
fn assert_not_contains_regex_yes() {
76+
assert_not_contains_regex("abc", "d");
77+
}
78+
79+
#[test]
80+
#[should_panic]
81+
fn assert_not_contains_regex_no() {
82+
assert_not_contains_regex("abc", ".*");
83+
}
84+
}
85+
86+
mod test_assert_count_is {
87+
use super::*;
88+
89+
#[test]
90+
fn assert_count_is_yes() {
91+
assert_count_is(0, "", "b");
92+
assert_count_is(3, "abcbdb", "b");
93+
}
94+
95+
#[test]
96+
#[should_panic]
97+
fn assert_count_is_no() {
98+
assert_count_is(2, "abcbdb", "b");
99+
}
100+
}

0 commit comments

Comments
 (0)