|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Unit test for check-skip-rationales.sh |
| 3 | +# |
| 4 | +# TASK-077: every `#ifndef _WINDOWS` / `#ifndef DARWIN` (and the equivalent |
| 5 | +# `#if !defined(_WINDOWS)` form) block in `test/integ/` must carry a |
| 6 | +# `// reason:` comment within the 5 lines immediately preceding the directive |
| 7 | +# so that the underlying platform limitation is recorded in |
| 8 | +# `test/PORTABILITY.md` or a follow-up task. |
| 9 | +# |
| 10 | +# Tests use a temporary directory tree that mimics test/integ/ so the script |
| 11 | +# can be exercised against synthetic fixtures without touching the live tree. |
| 12 | +set -euo pipefail |
| 13 | + |
| 14 | +PASS=0 |
| 15 | +FAIL=0 |
| 16 | + |
| 17 | +ok() { echo " OK: $1"; PASS=$((PASS + 1)); } |
| 18 | +fail() { echo " FAIL: $1"; FAIL=$((FAIL + 1)); } |
| 19 | + |
| 20 | +SCRIPT="$(cd "$(dirname "$0")" && pwd)/check-skip-rationales.sh" |
| 21 | + |
| 22 | +TMPDIR_BASE="$(mktemp -d)" |
| 23 | +trap 'rm -rf "$TMPDIR_BASE"' EXIT |
| 24 | + |
| 25 | +FAKE_REPO="$TMPDIR_BASE/repo" |
| 26 | +mkdir -p "$FAKE_REPO/scripts" "$FAKE_REPO/test/integ" |
| 27 | + |
| 28 | +cp "$SCRIPT" "$FAKE_REPO/scripts/check-skip-rationales.sh" |
| 29 | +chmod +x "$FAKE_REPO/scripts/check-skip-rationales.sh" |
| 30 | + |
| 31 | +reset_repo() { |
| 32 | + rm -f "$FAKE_REPO"/test/integ/*.cpp "$FAKE_REPO"/test/integ/*.hpp |
| 33 | +} |
| 34 | + |
| 35 | +# Test 1: No `#ifndef _WINDOWS` directives — should exit 0. |
| 36 | +reset_repo |
| 37 | +cat > "$FAKE_REPO/test/integ/clean.cpp" <<'EOF' |
| 38 | +// No platform skips at all. |
| 39 | +int main() { return 0; } |
| 40 | +EOF |
| 41 | +if (cd "$FAKE_REPO" && bash scripts/check-skip-rationales.sh 2>/dev/null); then |
| 42 | + ok "test 1: no platform skips exits 0" |
| 43 | +else |
| 44 | + fail "test 1: no platform skips should exit 0" |
| 45 | +fi |
| 46 | + |
| 47 | +# Test 2: `#ifndef _WINDOWS` with `// reason:` on the immediately preceding |
| 48 | +# line — should exit 0. |
| 49 | +reset_repo |
| 50 | +cat > "$FAKE_REPO/test/integ/adjacent.cpp" <<'EOF' |
| 51 | +// Some code |
| 52 | +// reason: MHD's Windows path can't drive INTERNAL_SELECT thread pools. |
| 53 | +#ifndef _WINDOWS |
| 54 | +int x = 1; |
| 55 | +#endif |
| 56 | +EOF |
| 57 | +if (cd "$FAKE_REPO" && bash scripts/check-skip-rationales.sh 2>/dev/null); then |
| 58 | + ok "test 2: adjacent reason exits 0" |
| 59 | +else |
| 60 | + fail "test 2: adjacent reason should exit 0" |
| 61 | +fi |
| 62 | + |
| 63 | +# Test 3: `#ifndef _WINDOWS` with `// reason:` 3 lines above (blank lines |
| 64 | +# allowed between) — should exit 0. |
| 65 | +reset_repo |
| 66 | +cat > "$FAKE_REPO/test/integ/within_window.cpp" <<'EOF' |
| 67 | +// reason: see test/PORTABILITY.md §threaded.cpp. |
| 68 | +
|
| 69 | +// (blank line above is fine) |
| 70 | +#ifndef _WINDOWS |
| 71 | +int x = 1; |
| 72 | +#endif |
| 73 | +EOF |
| 74 | +if (cd "$FAKE_REPO" && bash scripts/check-skip-rationales.sh 2>/dev/null); then |
| 75 | + ok "test 3: reason 3 lines above exits 0" |
| 76 | +else |
| 77 | + fail "test 3: reason 3 lines above should exit 0" |
| 78 | +fi |
| 79 | + |
| 80 | +# Test 4: `#ifndef _WINDOWS` with `// reason:` 6 lines above (outside window) |
| 81 | +# — should exit 1. |
| 82 | +reset_repo |
| 83 | +cat > "$FAKE_REPO/test/integ/outside_window.cpp" <<'EOF' |
| 84 | +// reason: this comment sits more than 5 lines above the directive. |
| 85 | +// |
| 86 | +// |
| 87 | +// |
| 88 | +// |
| 89 | +// |
| 90 | +#ifndef _WINDOWS |
| 91 | +int x = 1; |
| 92 | +#endif |
| 93 | +EOF |
| 94 | +if ! (cd "$FAKE_REPO" && bash scripts/check-skip-rationales.sh 2>/dev/null); then |
| 95 | + ok "test 4: reason outside window exits 1" |
| 96 | +else |
| 97 | + fail "test 4: reason outside window should exit 1" |
| 98 | +fi |
| 99 | + |
| 100 | +# Test 5: `#ifndef _WINDOWS` with no `// reason:` anywhere — should exit 1. |
| 101 | +reset_repo |
| 102 | +cat > "$FAKE_REPO/test/integ/bare.cpp" <<'EOF' |
| 103 | +#ifndef _WINDOWS |
| 104 | +int x = 1; |
| 105 | +#endif |
| 106 | +EOF |
| 107 | +if ! (cd "$FAKE_REPO" && bash scripts/check-skip-rationales.sh 2>/dev/null); then |
| 108 | + ok "test 5: bare _WINDOWS exits 1" |
| 109 | +else |
| 110 | + fail "test 5: bare _WINDOWS should exit 1" |
| 111 | +fi |
| 112 | + |
| 113 | +# Test 6: `#ifndef DARWIN` with no `// reason:` — should exit 1 |
| 114 | +# (verifies DARWIN is also covered). |
| 115 | +reset_repo |
| 116 | +cat > "$FAKE_REPO/test/integ/darwin_bare.cpp" <<'EOF' |
| 117 | +#ifndef DARWIN |
| 118 | +int x = 1; |
| 119 | +#endif |
| 120 | +EOF |
| 121 | +if ! (cd "$FAKE_REPO" && bash scripts/check-skip-rationales.sh 2>/dev/null); then |
| 122 | + ok "test 6: bare DARWIN exits 1" |
| 123 | +else |
| 124 | + fail "test 6: bare DARWIN should exit 1" |
| 125 | +fi |
| 126 | + |
| 127 | +# Test 7: `#ifdef _WINDOWS` (opposite polarity — additive, not a skip) |
| 128 | +# does NOT require `// reason:`; should exit 0. |
| 129 | +reset_repo |
| 130 | +cat > "$FAKE_REPO/test/integ/additive.cpp" <<'EOF' |
| 131 | +// No reason comment here. |
| 132 | +#ifdef _WINDOWS |
| 133 | +int x = 1; |
| 134 | +#endif |
| 135 | +EOF |
| 136 | +if (cd "$FAKE_REPO" && bash scripts/check-skip-rationales.sh 2>/dev/null); then |
| 137 | + ok "test 7: #ifdef _WINDOWS (additive) exits 0" |
| 138 | +else |
| 139 | + fail "test 7: #ifdef _WINDOWS (additive) should exit 0" |
| 140 | +fi |
| 141 | + |
| 142 | +# Test 8: `#if !defined(_WINDOWS) && defined(HAVE_DAUTH)` form (the |
| 143 | +# authentication.cpp digest-auth guard) without a reason — should exit 1. |
| 144 | +reset_repo |
| 145 | +cat > "$FAKE_REPO/test/integ/if_not_defined.cpp" <<'EOF' |
| 146 | +#if !defined(_WINDOWS) && defined(HAVE_DAUTH) |
| 147 | +int x = 1; |
| 148 | +#endif |
| 149 | +EOF |
| 150 | +if ! (cd "$FAKE_REPO" && bash scripts/check-skip-rationales.sh 2>/dev/null); then |
| 151 | + ok "test 8: #if !defined(_WINDOWS) bare exits 1" |
| 152 | +else |
| 153 | + fail "test 8: #if !defined(_WINDOWS) bare should exit 1" |
| 154 | +fi |
| 155 | + |
| 156 | +# Test 9: same `#if !defined(_WINDOWS)` form with `// reason:` adjacent — should exit 0. |
| 157 | +reset_repo |
| 158 | +cat > "$FAKE_REPO/test/integ/if_not_defined_ok.cpp" <<'EOF' |
| 159 | +// reason: MinGW64 curl's --digest parser rejects the MHD challenge. |
| 160 | +#if !defined(_WINDOWS) && defined(HAVE_DAUTH) |
| 161 | +int x = 1; |
| 162 | +#endif |
| 163 | +EOF |
| 164 | +if (cd "$FAKE_REPO" && bash scripts/check-skip-rationales.sh 2>/dev/null); then |
| 165 | + ok "test 9: #if !defined(_WINDOWS) with reason exits 0" |
| 166 | +else |
| 167 | + fail "test 9: #if !defined(_WINDOWS) with reason should exit 0" |
| 168 | +fi |
| 169 | + |
| 170 | +# Test 10: the live repo's test/integ/ — should exit 0 after rationale |
| 171 | +# comments have been added to every skip site. Skipped if the live tree |
| 172 | +# does not exist or is in the middle of the implementation (the |
| 173 | +# regression guard runs against the real repo, not this fake one). |
| 174 | +REAL_REPO="$(cd "$(dirname "$0")/.." && pwd)" |
| 175 | +if [ -d "$REAL_REPO/test/integ" ]; then |
| 176 | + if (cd "$REAL_REPO" && bash scripts/check-skip-rationales.sh 2>/dev/null); then |
| 177 | + ok "test 10: live test/integ/ tree exits 0" |
| 178 | + else |
| 179 | + fail "test 10: live test/integ/ tree should exit 0 (add // reason: comments to all #ifndef _WINDOWS/DARWIN blocks)" |
| 180 | + fi |
| 181 | +fi |
| 182 | + |
| 183 | +echo "" |
| 184 | +echo "Results: $PASS passed, $FAIL failed" |
| 185 | +[ "$FAIL" -eq 0 ] |
0 commit comments