Skip to content

Commit fa99bd9

Browse files
committed
a count that stops at the member level leaves the same reading one level up
`--workspace --no-run` reported "ok. N member(s); 0 passed; 0 failed", which is what a workspace with no tests at all reports — the false reading `totalNotRun` was added to the same line to prevent, one level down. The fan-out now carries `built` through to the workspace total and to `workspace_summary` as `tests_built`, kept apart from `tests_not_run` for the reason the per-member fields are: one is a question left open, the other is a question that was not asked. Leg E of 745 covers it: two members, one test each, `--workspace --no-run`, exit 0 and "2 built, not run" in the total.
1 parent e5dc170 commit fa99bd9

4 files changed

Lines changed: 60 additions & 7 deletions

File tree

docs/50-machine-output.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,13 @@ test ran and passed. A client that read the exit code alone as pass/fail must
560560
handle 2, and a client that inferred "everything passed" from `failed == 0`
561561
must also read `not_run`.
562562

563-
`workspace_summary` adds `tests_not_run` (the sum over members) and
563+
`workspace_summary` adds `tests_not_run` (the sum over members),
564+
`tests_built` (the sum of tests built under `--no-run`) and
564565
`unrunnable_members` (members all of whose tests were `not_run`), alongside the
565566
existing `not_run` list, which continues to name members the
566-
`--workspace-timeout` stopped before they started.
567+
`--workspace-timeout` stopped before they started. `tests_built` is separate
568+
from `tests_not_run` for the reason the per-member fields are: one is a
569+
question left open, the other is a question that was not asked.
567570

568571
### The stage manifest
569572

docs/zh/50-machine-output.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,11 @@ mcpp test [pattern] [--workspace] --message-format json
485485
含义不变 —— 有测试运行并失败;0 表示每个测试都运行并通过。只读退出码判 pass/fail 的
486486
客户端必须处理 2;由 `failed == 0` 推断「全部通过」的客户端还必须读 `not_run`
487487

488-
`workspace_summary` 增加 `tests_not_run`(各成员之和)与 `unrunnable_members`(所有
489-
测试都 `not_run` 的成员),与既有的 `not_run` 列表并列;后者仍然指
490-
`--workspace-timeout` 到达时尚未开始的成员。
488+
`workspace_summary` 增加 `tests_not_run`(各成员之和)、`tests_built`(`--no-run`
489+
构建的测试数之和)与 `unrunnable_members`(所有测试都 `not_run` 的成员),与既有的
490+
`not_run` 列表并列;后者仍然指 `--workspace-timeout` 到达时尚未开始的成员。
491+
`tests_built``tests_not_run` 分开,理由和逐成员的那两个字段一样:一个是被悬着的
492+
问题,另一个是压根没问的问题。
491493

492494
### 暂存清单
493495

src/cli/cmd_build.cppm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,10 @@ export int cmd_test(const mcpplibs::cmdline::ParsedArgs& parsed,
595595
std::vector<std::string> unrunnable; // tests built, none executed (#544)
596596
std::vector<std::pair<std::string, long long>> memberTimes;
597597
int totalPassed = 0, totalFailed = 0, totalNotRun = 0;
598+
// Carried for the same reason `totalNotRun` is: without it a
599+
// `--no-run` workspace reports "0 passed; 0 failed", which is
600+
// what a workspace with no tests at all reports.
601+
int totalBuilt = 0;
598602
auto tWs = std::chrono::steady_clock::now();
599603
auto ws_ms = [&tWs] {
600604
return std::chrono::duration_cast<std::chrono::milliseconds>(
@@ -622,6 +626,7 @@ export int cmd_test(const mcpplibs::cmdline::ParsedArgs& parsed,
622626
totalPassed += sum.passed;
623627
totalFailed += sum.failed;
624628
totalNotRun += sum.notRun;
629+
totalBuilt += sum.built;
625630
memberTimes.emplace_back(mp, sum.elapsedMs);
626631
auto secs = static_cast<double>(sum.elapsedMs) / 1000.0;
627632
if (r == 2 && sum.failed == 0 && sum.notRun > 0) {
@@ -677,10 +682,11 @@ export int cmd_test(const mcpplibs::cmdline::ParsedArgs& parsed,
677682
// `unrunnable_members` are #544's — tests that were built and not
678683
// executed, and the members all of whose tests were.
679684
std::println("{{\"workspace_summary\":{{\"members\":{},\"passed\":{},\"failed\":{},"
680-
"\"tests_not_run\":{},"
685+
"\"tests_not_run\":{},\"tests_built\":{},"
681686
"\"failed_members\":[{}],\"unrunnable_members\":[{}],"
682687
"\"not_run\":[{}],\"elapsed_ms\":{}}}}}",
683688
members->size(), totalPassed, totalFailed, totalNotRun,
689+
totalBuilt,
684690
join(failed), join(unrunnable), join(notRun), wsElapsed);
685691
std::fflush(stdout);
686692
return rc;
@@ -709,6 +715,8 @@ export int cmd_test(const mcpplibs::cmdline::ParsedArgs& parsed,
709715
// built and not executed must not read as a passing member.
710716
std::string notRunCounts = totalNotRun
711717
? std::format("; {} not run", totalNotRun) : std::string{};
718+
if (totalBuilt)
719+
notRunCounts += std::format("; {} built, not run", totalBuilt);
712720
if (failed.empty() && notRun.empty() && unrunnable.empty())
713721
mcpp::ui::status("workspace result",
714722
std::format("ok. {} member(s); {} passed; 0 failed{}; finished in {:.2f}s",

tests/e2e/745_no_run_builds_the_tests_and_says_so.sh

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# same situation -- tests built, nothing run -- on every host, for the native
2323
# target, with nothing installed.
2424
#
25-
# Four legs:
25+
# Five legs:
2626
# A without `--no-run`: exit 2, and the tests are reported `not run`.
2727
# B with `--no-run`: exit 0, and the count is reported as built.
2828
# C a test that does not COMPILE is still a failure under `--no-run`.
@@ -31,6 +31,8 @@
3131
# D `--no-run` with `--no-runner` is refused. The two names differ by one
3232
# character and mean opposite things, and neither is a weaker form of the
3333
# other, so there is no reading of the pair to prefer.
34+
# E `--workspace` totals the built count. A count that stops at the member
35+
# level leaves the same false reading one level up.
3436
set -e
3537

3638
MCPP="${MCPP:-mcpp}"
@@ -141,4 +143,42 @@ case "$out_d" in
141143
*) echo "FAIL: D did not explain why the pair is refused"; printf '%s\n' "$out_d" | tail -3; exit 1 ;;
142144
esac
143145

146+
# --- E: the workspace total says it too ----------------------------------
147+
# A count that stops at the member level is the same defect one level up: a
148+
# workspace summary reading "0 passed; 0 failed" is what a workspace with no
149+
# tests reports.
150+
rm -f tests/gamma.cpp
151+
mkdir -p members/one/tests members/two/tests
152+
cat > mcpp.toml <<EOF
153+
[workspace]
154+
members = ["members/one", "members/two"]
155+
EOF
156+
for m in one two; do
157+
cat > "members/$m/mcpp.toml" <<EOF
158+
[package]
159+
name = "$m"
160+
version = "0.1.0"
161+
162+
[target.$host]
163+
runner = ["mcpp-no-such-runner-exists"]
164+
EOF
165+
cat > "members/$m/tests/t.cpp" <<'EOF'
166+
int main() { return 0; }
167+
EOF
168+
done
169+
set +e
170+
out_e="$("$MCPP" test --workspace --target "$host" --no-run 2>&1)"
171+
rc_e=$?
172+
set -e
173+
printf '%s
174+
' "$out_e" | tail -3
175+
if [ "$rc_e" != 0 ]; then
176+
echo "FAIL: E expected exit 0 from a --workspace --no-run run, got $rc_e"
177+
exit 1
178+
fi
179+
case "$out_e" in
180+
*"2 built, not run"*) ;;
181+
*) echo "FAIL: E the workspace total did not report the built tests"; exit 1 ;;
182+
esac
183+
144184
echo "PASS: --no-run builds the tests and says so, and says nothing else"

0 commit comments

Comments
 (0)