1717# E. Under a shipping profile, `mcpp build` and `mcpp test` are one configuration: the test
1818# compiles none of the code under test again, which is trimmed as the build trims it, and a
1919# test program's own file keeps its path (`__FILE__` finds the test's directory).
20+ # F. A case a listed case declares (protocol P3.4) is selected by its name alone; a pattern below
21+ # the listed case runs it whole.
2022set -e
2123TMP=$( mktemp -d)
2224trap ' rm -rf "$TMP"' EXIT
@@ -34,13 +36,13 @@ cat > tests/unit/a.cpp <<'CPP'
3436import mcpplibs.mtest;
3537import app.calc;
3638using namespace mcpplibs::mtest;
37- suite a{"a ", [] { "doubles"_test = [] { expect(eq(twice(2), 4)); } ; }};
39+ UTest a{"doubles ", [] { expect(eq(twice(2), 4)); }};
3840CPP
3941cat > tests/unit/b.cpp << 'CPP '
4042import std;
4143import mcpplibs.mtest;
4244using namespace mcpplibs::mtest;
43- suite b{"b", [] { " reads its data"_test = [] { expect(eq(std::string_view("tests/data/f.txt").size(), 16u)); } ; }};
45+ UTest b{"reads its data", [] { expect(eq(std::string_view("tests/data/f.txt").size(), 16u)); }};
4446CPP
4547printf ' import std;\nint main() { return 0; }\n' > tests/e2e/plain.cpp
4648printf ' data\n' > tests/data/f.txt
@@ -51,7 +53,7 @@ printf '\n[test]\nprograms = "directory"\n' >> mcpp.toml
5153grep -q ' unit \.\.\. ok (.*2 cases)' a.log || fail " A: unit is not one program of two cases" a.log
5254grep -q ' ^e2e \.\.\. ok' a.log || fail " A: the directory of a file with main" a.log
5355" $MCPP " test --cases > a-cases.log 2>&1 || fail " A: --cases" a-cases.log
54- grep -q ' a/ doubles' a-cases.log && grep -q ' b/ reads its data' a-cases.log || fail " A: the program's cases" a-cases.log
56+ grep -q ' doubles' a-cases.log && grep -q ' reads its data' a-cases.log || fail " A: the program's cases" a-cases.log
5557# B: a file of plain main beside the library's marker.
5658grep -q ' e2e: one case, its exit status' a-cases.log || fail " B: a program of plain main is listed as one case" a-cases.log
5759printf ' int main() { return 0; }\n' > tests/e2e/second.cpp
@@ -113,4 +115,23 @@ set -- target/*/*/build.ninja
113115grep -q " library rel@0.1.0/src/where.cppm" e-test.log || fail " E: the code under test is not trimmed as built" e-test.log
114116[ " $( grep -cE ' obj/where\.m\.(o|obj) ' " $( dirname " $1 " ) /.ninja_log" ) " = 1 ] || fail " E: the test compiled the library again" " $( dirname " $1 " ) /.ninja_log"
115117
118+ # F
119+ cd " $TMP "
120+ " $MCPP " new grp > /dev/null 2>&1
121+ cd grp
122+ cat > tests/test_smoke.cpp << 'CPP '
123+ import mcpplibs.mtest;
124+ using namespace mcpplibs::mtest;
125+ UTest g{"g", [] {
126+ "one"_test = [] { expect(true); };
127+ "two"_test = [] { expect(true); };
128+ }};
129+ CPP
130+ " $MCPP " test --cases > f-cases.log 2>&1 || fail " F: --cases" f-cases.log
131+ grep -q ' test_smoke: 1 case' f-cases.log || fail " F: the object is the one listed case" f-cases.log
132+ " $MCPP " test --case ' g/one' > f1.log 2>&1 || fail " F: --case g/one" f1.log
133+ grep -q ' test_smoke \.\.\. ok (.*1 case)' f1.log || fail " F: a declared case is not selected alone" f1.log
134+ " $MCPP " test --case ' g/t*' > f2.log 2>&1 || fail " F: --case g/t*" f2.log
135+ grep -q ' test_smoke \.\.\. ok (.*3 cases)' f2.log || fail " F: a pattern below the listed case does not run it whole" f2.log
136+
116137echo " PASS: 1038 test programs of a directory, and the tests a change affects"
0 commit comments