-
-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathtest_check_littletest_skip_exit_code.sh
More file actions
executable file
·169 lines (140 loc) · 5.05 KB
/
Copy pathtest_check_littletest_skip_exit_code.sh
File metadata and controls
executable file
·169 lines (140 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env bash
#
# TASK-076 Cycle 1 / sentinel for `LT_SKIP` exit-code plumbing.
#
# Asserts that the littletest binary semantics for SKIP are:
#
# (a) A binary whose only outcomes are SKIPs exits 77 (Automake's SKIP
# code from `test-driver` line 131: `77:*) col=$blu res=SKIP …`).
# This is what makes "all dependencies missing" reportable to
# Automake as SKIP rather than PASS — the regression the rest of
# TASK-076 patches at every TLS test site.
#
# (b) A binary that mixes passes and skips exits 0 (the existing
# behaviour; SKIPs do not "infect" a successful run).
#
# (c) A binary that mixes a failure and a skip exits with the failure
# count (neither 0 nor 77) — failures dominate skips, per
# test_runner::operator()() in littletest.hpp: `to_ret` is only
# overridden to 77 when failures_counter == 0 && success_counter
# == 0 && skip_counter > 0; any failure short-circuits that.
#
# The script compiles three tiny throwaway TUs against the in-tree
# `test/littletest.hpp` and runs them. It is wired into Makefile.am as a
# `lint-`-style script (no library link required); it does NOT depend on
# anything libhttpserver-specific so it can run on any host with a C++
# compiler.
#
# Exit codes:
# 0 — both assertions held.
# 1 — at least one assertion failed.
#
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
LITTLETEST_HDR="$REPO_ROOT/test/littletest.hpp"
if [ ! -f "$LITTLETEST_HDR" ]; then
echo "ERROR: $LITTLETEST_HDR missing" >&2
exit 1
fi
# $CXX may carry flags (CI sets e.g. "g++ -std=c++20"), so split it into an
# array and expand with "${CXX_CMD[@]}" rather than quoting the whole string
# as a single command word (which would fail with "command not found").
# Mirrors scripts/check-deprecated-cookie-overload.sh.
read -r -a CXX_CMD <<< "${CXX:-c++}"
TMPDIR_=$(mktemp -d)
trap 'rm -rf "$TMPDIR_"' EXIT
# ---- (a) all-skip → exit 77 -------------------------------------------------
cat > "$TMPDIR_/only_skips.cpp" <<'EOF'
#include "littletest.hpp"
LT_BEGIN_SUITE(only_skips_suite)
void set_up() {}
void tear_down() {}
LT_END_SUITE(only_skips_suite)
LT_BEGIN_AUTO_TEST(only_skips_suite, this_test_only_skips)
LT_SKIP("dependency missing");
LT_END_AUTO_TEST(this_test_only_skips)
LT_BEGIN_AUTO_TEST_ENV()
AUTORUN_TESTS()
LT_END_AUTO_TEST_ENV()
EOF
"${CXX_CMD[@]}" -std=c++20 -I"$REPO_ROOT/test" \
"$TMPDIR_/only_skips.cpp" -o "$TMPDIR_/only_skips"
set +e
"$TMPDIR_/only_skips" > "$TMPDIR_/only_skips.log" 2>&1
ec_a=$?
set -e
if [ "$ec_a" -ne 77 ]; then
echo "FAIL (a): all-skip binary exited $ec_a, expected 77" >&2
cat "$TMPDIR_/only_skips.log" >&2
exit 1
fi
# ---- (b) pass + skip → exit 0 ----------------------------------------------
cat > "$TMPDIR_/mixed.cpp" <<'EOF'
#include "littletest.hpp"
LT_BEGIN_SUITE(mixed_suite)
void set_up() {}
void tear_down() {}
LT_END_SUITE(mixed_suite)
LT_BEGIN_AUTO_TEST(mixed_suite, this_passes)
LT_CHECK_EQ(1 + 1, 2);
LT_END_AUTO_TEST(this_passes)
LT_BEGIN_AUTO_TEST(mixed_suite, this_skips)
LT_SKIP("dependency missing");
LT_END_AUTO_TEST(this_skips)
LT_BEGIN_AUTO_TEST_ENV()
AUTORUN_TESTS()
LT_END_AUTO_TEST_ENV()
EOF
"${CXX_CMD[@]}" -std=c++20 -I"$REPO_ROOT/test" \
"$TMPDIR_/mixed.cpp" -o "$TMPDIR_/mixed"
set +e
"$TMPDIR_/mixed" > "$TMPDIR_/mixed.log" 2>&1
ec_b=$?
set -e
if [ "$ec_b" -ne 0 ]; then
echo "FAIL (b): mixed pass+skip binary exited $ec_b, expected 0" >&2
cat "$TMPDIR_/mixed.log" >&2
exit 1
fi
# Confirm the binary emitted the `[SKIP]` marker and the `-> N skipped`
# runner summary line — these are the textual contracts the CI lane
# greps for to assert per-test SKIPs in ws_start_stop fired.
if ! grep -q '^\[SKIP\] ' "$TMPDIR_/mixed.log"; then
echo "FAIL (b): mixed binary stdout missing '[SKIP] ' marker" >&2
cat "$TMPDIR_/mixed.log" >&2
exit 1
fi
if ! grep -qE '^-> [0-9]+ skipped' "$TMPDIR_/mixed.log"; then
echo "FAIL (b): runner summary missing '-> N skipped' line" >&2
cat "$TMPDIR_/mixed.log" >&2
exit 1
fi
# ---- (c) fail + skip → exit == failure count (neither 0 nor 77) ------------
cat > "$TMPDIR_/fail_and_skip.cpp" <<'EOF'
#include "littletest.hpp"
LT_BEGIN_SUITE(fail_and_skip_suite)
void set_up() {}
void tear_down() {}
LT_END_SUITE(fail_and_skip_suite)
LT_BEGIN_AUTO_TEST(fail_and_skip_suite, this_fails)
LT_CHECK_EQ(1, 2);
LT_END_AUTO_TEST(this_fails)
LT_BEGIN_AUTO_TEST(fail_and_skip_suite, this_skips)
LT_SKIP("dependency missing");
LT_END_AUTO_TEST(this_skips)
LT_BEGIN_AUTO_TEST_ENV()
AUTORUN_TESTS()
LT_END_AUTO_TEST_ENV()
EOF
"${CXX_CMD[@]}" -std=c++20 -I"$REPO_ROOT/test" \
"$TMPDIR_/fail_and_skip.cpp" -o "$TMPDIR_/fail_and_skip"
set +e
"$TMPDIR_/fail_and_skip" > "$TMPDIR_/fail_and_skip.log" 2>&1
ec_c=$?
set -e
if [ "$ec_c" -ne 1 ]; then
echo "FAIL (c): fail+skip binary exited $ec_c, expected 1 (the failure count)" >&2
cat "$TMPDIR_/fail_and_skip.log" >&2
exit 1
fi
echo "PASS — littletest SKIP exit-code semantics held (77 for all-skip, 0 for mixed pass+skip, failure count for fail+skip)"