|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | # SPDX-License-Identifier: MPL-2.0 |
3 | 3 | # Issue #734 — native Bun-ESM backend acceptance runner. |
4 | | -set -euo pipefail |
| 4 | +# |
| 5 | +# Fail-late by design: every check runs and is reported, so one red check |
| 6 | +# cannot hide the state of the checks behind it. Failures are echoed as |
| 7 | +# `::error::` lines so they survive into CI annotations. |
| 8 | +set -uo pipefail |
5 | 9 |
|
6 | 10 | ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" |
7 | 11 | TEST_DIR="$ROOT_DIR/tests/codegen-bun" |
|
14 | 18 | COMPILE_CMD=(dune exec affinescript -- compile) |
15 | 19 | fi |
16 | 20 |
|
17 | | -command -v bun >/dev/null 2>&1 || { |
18 | | - echo "error: Bun is required for the Bun-ESM acceptance tests" >&2 |
| 21 | +if ! command -v bun >/dev/null 2>&1; then |
| 22 | + echo "::error::Bun is required for the Bun-ESM acceptance tests" >&2 |
19 | 23 | exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +failures=() |
| 27 | +fail() { |
| 28 | + failures+=("$1") |
| 29 | + echo "::error::$1" >&2 |
20 | 30 | } |
21 | 31 |
|
22 | 32 | src="$TEST_DIR/host_profile.affine" |
23 | 33 | out="${src%.affine}.bun.js" |
24 | | -"${COMPILE_CMD[@]}" "$src" -o "$out" --bun-esm |
25 | | -if grep -qi 'deno' "$out"; then |
26 | | - echo "error: legacy runtime reference emitted in $(basename "$out")" >&2 |
27 | | - exit 1 |
| 34 | + |
| 35 | +# 1. Compile, then scan the artefact for legacy runtime references. |
| 36 | +compiled=1 |
| 37 | +if ! "${COMPILE_CMD[@]}" "$src" -o "$out" --bun-esm; then |
| 38 | + compiled=0 |
| 39 | + fail "compile failed for $(basename "$src")" |
| 40 | +elif grep -qi 'deno' "$out"; then |
| 41 | + fail "legacy runtime reference emitted in $(basename "$out")" |
| 42 | + grep -in 'deno' "$out" | head -4 | sed 's/^/ /' >&2 |
| 43 | +fi |
| 44 | + |
| 45 | +if [ "$compiled" = 1 ]; then |
| 46 | + # 2. The emitted module must be syntactically valid Bun/JS. |
| 47 | + if ! bun --check "$out"; then |
| 48 | + fail "bun --check rejected $(basename "$out")" |
| 49 | + fi |
| 50 | + |
| 51 | + # 3. Emission must be byte-for-byte reproducible. |
| 52 | + second="$TEST_DIR/reproducibility.bun.js" |
| 53 | + if "${COMPILE_CMD[@]}" "$src" -o "$second" --bun-esm; then |
| 54 | + if ! cmp "$out" "$second"; then |
| 55 | + fail "Bun-ESM emission is not reproducible ($(basename "$out") vs $(basename "$second"))" |
| 56 | + fi |
| 57 | + else |
| 58 | + fail "reproducibility recompile failed for $(basename "$src")" |
| 59 | + fi |
28 | 60 | fi |
29 | | -bun --check "$out" |
30 | | -second="$TEST_DIR/reproducibility.bun.js" |
31 | | -"${COMPILE_CMD[@]}" "$src" -o "$second" --bun-esm |
32 | | -cmp "$out" "$second" |
33 | 61 |
|
| 62 | +# 4. The retired --deno-esm flag must be rejected with its explanation. |
34 | 63 | removed_log="$TEST_DIR/deno-removed.log" |
35 | | -if "${COMPILE_CMD[@]}" "$src" -o "$out" --deno-esm \ |
36 | | - >"$removed_log" 2>&1; then |
37 | | - echo "error: retired --deno-esm compiled successfully" >&2 |
38 | | - exit 1 |
| 64 | +if "${COMPILE_CMD[@]}" "$src" -o "$out" --deno-esm >"$removed_log" 2>&1; then |
| 65 | + fail "retired --deno-esm compiled successfully" |
| 66 | +elif ! grep -q 'Deno-ESM was removed' "$removed_log"; then |
| 67 | + fail "retired --deno-esm rejection lacks 'Deno-ESM was removed'" |
39 | 68 | fi |
40 | | -grep -q 'Deno-ESM was removed' "$removed_log" |
41 | 69 |
|
| 70 | +# 5. The retired .deno.js output extension must be rejected as E0826. |
42 | 71 | removed_json="$TEST_DIR/deno-removed.json" |
43 | | -if "${COMPILE_CMD[@]}" "$src" -o "${out%.bun.js}.deno.js" --json \ |
44 | | - >"$removed_json" 2>&1; then |
45 | | - echo "error: retired .deno.js output compiled successfully" >&2 |
46 | | - exit 1 |
| 72 | +if "${COMPILE_CMD[@]}" "$src" -o "${out%.bun.js}.deno.js" --json >"$removed_json" 2>&1; then |
| 73 | + fail "retired .deno.js output compiled successfully" |
| 74 | +else |
| 75 | + grep -q '"code":"E0826"' "$removed_json" || |
| 76 | + fail "retired .deno.js rejection lacks error code E0826" |
| 77 | + grep -q '"success":false' "$removed_json" || |
| 78 | + fail "retired .deno.js rejection lacks success:false" |
47 | 79 | fi |
48 | | -grep -q '"code":"E0826"' "$removed_json" |
49 | | -grep -q '"success":false' "$removed_json" |
50 | 80 |
|
| 81 | +# 6. Native Bun harnesses. |
| 82 | +harness_total=0 |
51 | 83 | for js in "$TEST_DIR"/*.harness.mjs; do |
52 | | - (cd "$TEST_DIR" && AFFINESCRIPT_BUN_PROBE=estate bun "$(basename "$js")" alpha beta) |
| 84 | + name="$(basename "$js")" |
| 85 | + harness_total=$((harness_total + 1)) |
| 86 | + if ! (cd "$TEST_DIR" && AFFINESCRIPT_BUN_PROBE=estate bun "$name" alpha beta); then |
| 87 | + fail "bun harness failed: $name" |
| 88 | + fi |
53 | 89 | done |
54 | 90 |
|
| 91 | +# 7. Unsupported host operations must not compile. |
55 | 92 | if "${COMPILE_CMD[@]}" "$TEST_DIR/unsupported_host.affine" \ |
56 | 93 | -o "$TEST_DIR/unsupported_host.bun.js" --bun-esm; then |
57 | | - echo "error: unsupported Bun host operation compiled successfully" >&2 |
| 94 | + fail "unsupported Bun host operation compiled successfully" |
| 95 | +fi |
| 96 | + |
| 97 | +if [ "${#failures[@]}" -gt 0 ]; then |
| 98 | + echo "" |
| 99 | + echo "✗ ${#failures[@]} native Bun-ESM check(s) failed:" |
| 100 | + printf ' - %s\n' "${failures[@]}" |
58 | 101 | exit 1 |
59 | 102 | fi |
60 | 103 |
|
61 | | -echo "All native Bun-ESM tests passed." |
| 104 | +echo "" |
| 105 | +echo "All native Bun-ESM tests passed ($harness_total harnesses)." |
0 commit comments