omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / tests / diagnostics / experiment_issue655.sh
| 1 | #!/bin/bash |
| 2 | # tests/diagnostics/experiment_issue655.sh |
| 3 | # Empirical experiment for issue #655: incremental compiler feedback for .om generation. |
| 4 | # Tests 10 held-out .om programs with known-good versions and deliberately broken drafts. |
| 5 | # Verifies: |
| 6 | # 1. Known-good programs yield zero error records (negative control: output is solely "omega-diag v1", exit code 0). |
| 7 | # 2. Deliberately broken programs yield exact diagnostics locating the first error span and matching the compiler refusal code. |
| 8 | set -euo pipefail |
| 9 | |
| 10 | ROOT=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd) |
| 11 | OMC="${OMC:-$ROOT/seed/out/omc}" |
| 12 | [ -x "$OMC" ] || { echo "FAIL: $OMC not found or not executable" >&2; exit 1; } |
| 13 | |
| 14 | PASS_COUNT=0 |
| 15 | TOTAL=54 |
| 16 | |
| 17 | echo "=== Issue #655 Milestone A Diagnostic Precision Experiment ===" |
| 18 | printf "%-14s | %-12s | %-8s | %-9s | %-14s | %s\n" "Task" "Good Result" "Bad Exit" "Span" "Span Text" "Diagnostic" |
| 19 | echo "---------------------------------------------------------------------------------------------------------" |
| 20 | |
| 21 | run_case() { |
| 22 | local name="$1" |
| 23 | local good="$2" |
| 24 | local bad="$3" |
| 25 | local exp_text="$4" |
| 26 | local exp_code="$5" |
| 27 | |
| 28 | # 1. Good program (negative control) |
| 29 | local out_good |
| 30 | local rc_good=0 |
| 31 | out_good=$(printf "check\n%s" "$good" | "$OMC" 2>&1) || rc_good=$? |
| 32 | if [ "$rc_good" -ne 0 ] || [ "$out_good" != "omega-diag v1" ]; then |
| 33 | echo "FAIL negative control on $name: rc=$rc_good out=$out_good" >&2 |
| 34 | return 1 |
| 35 | fi |
| 36 | |
| 37 | # 2. Broken draft |
| 38 | local out_bad |
| 39 | local rc_bad=0 |
| 40 | out_bad=$(printf "check\n%s" "$bad" | "$OMC" 2>&1) || rc_bad=$? |
| 41 | if [ "$rc_bad" -ne "$exp_code" ]; then |
| 42 | echo "FAIL bad exit code on $name: expected $exp_code, got $rc_bad" >&2 |
| 43 | return 1 |
| 44 | fi |
| 45 | |
| 46 | # Extract diagnostic record (line 2 of output) |
| 47 | local diag_line |
| 48 | diag_line=$(echo "$out_bad" | grep -E '^om[12] ' || true) |
| 49 | if [ -z "$diag_line" ]; then |
| 50 | echo "FAIL missing om record on $name: $out_bad" >&2 |
| 51 | return 1 |
| 52 | fi |
| 53 | |
| 54 | # Extract span |
| 55 | local span |
| 56 | span=$(echo "$diag_line" | grep -o 'span=[0-9]*-[0-9]*' | cut -d= -f2) |
| 57 | local a b |
| 58 | a=$(echo "$span" | cut -d- -f1) |
| 59 | b=$(echo "$span" | cut -d- -f2) |
| 60 | |
| 61 | # Extract span text using python |
| 62 | local span_text |
| 63 | span_text=$(python3 -c "import sys; src = sys.stdin.read(); a, b = int(sys.argv[1]), int(sys.argv[2]); print(repr(src[a:b]))" "$a" "$b" <<< "$bad") |
| 64 | |
| 65 | local exp_repr |
| 66 | exp_repr=$(python3 -c "import sys; print(repr(sys.argv[1]))" "$exp_text") |
| 67 | |
| 68 | if [ "$span_text" != "$exp_repr" ]; then |
| 69 | echo "FAIL span text mismatch on $name: expected $exp_repr, got $span_text" >&2 |
| 70 | return 1 |
| 71 | fi |
| 72 | local category |
| 73 | case "$exp_code" in |
| 74 | 3|10|13) category=NAME ;; |
| 75 | 4|5|6|9|15|16|22) category=SYNTAX ;; |
| 76 | 7|11|19) category=TYPE ;; |
| 77 | 8|21) category=RANGE ;; |
| 78 | 12|14|23|24) category=CAPACITY ;; |
| 79 | 17|18) category=FLOW ;; |
| 80 | 27|28|29|30) category=CONTRACT ;; |
| 81 | *) echo "FAIL unmapped diagnostic code $exp_code" >&2; return 1 ;; |
| 82 | esac |
| 83 | if [[ "$diag_line" != "om1 $category "* ]]; then |
| 84 | echo "FAIL category on $name: expected $category, got $diag_line" >&2 |
| 85 | return 1 |
| 86 | fi |
| 87 | # Finality and repairability are independent; these edited drafts are not capacity failures. |
| 88 | if [[ "$diag_line" != *" REPAIRABLE code=$exp_code "* ]] || [[ "$diag_line" == *" "* ]]; then |
| 89 | echo "FAIL repairability or spacing on $name: $diag_line" >&2 |
| 90 | return 1 |
| 91 | fi |
| 92 | |
| 93 | printf "%-14s | %-12s | %-8s | %-9s | %-14s | %s\n" "$name" "PASS (0 err)" "$rc_bad" "$span" "$span_text" "$diag_line" |
| 94 | PASS_COUNT=$((PASS_COUNT + 1)) |
| 95 | } |
| 96 | run_next_case() { |
| 97 | local name="$1" |
| 98 | local input="$2" |
| 99 | local expected="$3" |
| 100 | |
| 101 | local out |
| 102 | local rc=0 |
| 103 | out=$(printf "next\n%s" "$input" | "$OMC" 2>&1) || rc=$? |
| 104 | if [ "$rc" -ne 0 ]; then |
| 105 | echo "FAIL next exit code on $name: expected 0, got $rc" >&2 |
| 106 | echo "$out" >&2 |
| 107 | return 1 |
| 108 | fi |
| 109 | |
| 110 | if [ "$out" != "$expected" ]; then |
| 111 | echo "FAIL next output mismatch on $name:" >&2 |
| 112 | diff -u <(echo "$expected") <(echo "$out") >&2 || true |
| 113 | return 1 |
| 114 | fi |
| 115 | |
| 116 | printf "%-14s | %-12s | %-8s | %-9s | %-14s | %s\n" "$name" "PASS (query)" "0" "-" "-" "prefix query matches expected" |
| 117 | PASS_COUNT=$((PASS_COUNT + 1)) |
| 118 | } |
| 119 | |
| 120 | run_next_neg_control() { |
| 121 | local name="$1" |
| 122 | local input="$2" |
| 123 | local expected="$3" |
| 124 | local corrupted="$4" |
| 125 | |
| 126 | local out |
| 127 | local rc=0 |
| 128 | out=$(printf "next\n%s" "$input" | "$OMC" 2>&1) || rc=$? |
| 129 | if [ "$rc" -ne 0 ]; then |
| 130 | echo "FAIL next exit code on $name: expected 0, got $rc" >&2 |
| 131 | return 1 |
| 132 | fi |
| 133 | |
| 134 | if [ "$out" != "$expected" ]; then |
| 135 | echo "FAIL next output should match expected on $name" >&2 |
| 136 | return 1 |
| 137 | fi |
| 138 | |
| 139 | if [ "$out" = "$corrupted" ]; then |
| 140 | echo "FAIL negative control on $name: corrupted expectation was not detected" >&2 |
| 141 | return 1 |
| 142 | fi |
| 143 | |
| 144 | printf "%-14s | %-12s | %-8s | %-9s | %-14s | %s\n" "$name" "PASS (negctrl)" "0" "-" "-" "detected altered expected line" |
| 145 | PASS_COUNT=$((PASS_COUNT + 1)) |
| 146 | } |
| 147 | |
| 148 | # 1. clamp_sub |
| 149 | run_case "clamp_sub" \ |
| 150 | "fn clamp_sub a uint b uint to uint |
| 151 | if lt a b |
| 152 | ret 0 |
| 153 | end |
| 154 | ret sub a b |
| 155 | end |
| 156 | " \ |
| 157 | "fn clamp_sub a uint b uint to uint |
| 158 | if lt a b |
| 159 | ret true |
| 160 | end |
| 161 | ret sub a b |
| 162 | end |
| 163 | " \ |
| 164 | "true" 7 |
| 165 | |
| 166 | # 2. narrow_sum |
| 167 | run_case "narrow_sum" \ |
| 168 | "fn narrow_sum a short b short to byte |
| 169 | ret byte add a b |
| 170 | end |
| 171 | " \ |
| 172 | "fn narrow_sum a short b short to byte |
| 173 | ret byte add a |
| 174 | end |
| 175 | " \ |
| 176 | $'\n' 4 |
| 177 | |
| 178 | # 3. power_mod |
| 179 | run_case "power_mod" \ |
| 180 | "fn power_mod b uint e uint m uint to uint |
| 181 | r = uint 1 |
| 182 | base = rem b m |
| 183 | while gt e 0 |
| 184 | if eq rem e 2 1 |
| 185 | r = rem mul r base m |
| 186 | end |
| 187 | base = rem mul base base m |
| 188 | e = div e 2 |
| 189 | end |
| 190 | ret r |
| 191 | end |
| 192 | " \ |
| 193 | "fn power_mod b uint e uint m uint to uint |
| 194 | r = 1 |
| 195 | base = rem b m |
| 196 | while gt e 0 |
| 197 | if eq rem e 2 1 |
| 198 | r = rem mul r base m |
| 199 | end |
| 200 | base = rem mul base base m |
| 201 | e = div e 2 |
| 202 | end |
| 203 | ret r |
| 204 | end |
| 205 | " \ |
| 206 | "1" 11 |
| 207 | |
| 208 | # 4. tri_kind |
| 209 | run_case "tri_kind" \ |
| 210 | "fn tri_kind a int b int c int to int |
| 211 | if eq a b |
| 212 | ret 1 |
| 213 | end |
| 214 | ret 0 |
| 215 | end |
| 216 | " \ |
| 217 | "fn tri_kind a int b int c int to int |
| 218 | if eq a |
| 219 | ret 1 |
| 220 | end |
| 221 | ret 0 |
| 222 | end |
| 223 | " \ |
| 224 | $'\n' 4 |
| 225 | |
| 226 | # 5. t_conv |
| 227 | run_case "t_conv" \ |
| 228 | "fn main to int |
| 229 | x = ulong 3000000000 |
| 230 | ret int x |
| 231 | end |
| 232 | " \ |
| 233 | "fn main to int |
| 234 | x = ulong 3000000000 |
| 235 | ret int |
| 236 | end |
| 237 | " \ |
| 238 | $'\n' 4 |
| 239 | |
| 240 | # 6. sort |
| 241 | run_case "sort" \ |
| 242 | "fn sorted a view ulong 10 to ulong |
| 243 | bad = ulong 0 |
| 244 | for i ulong 9 |
| 245 | if gt get a i get a add i 1 |
| 246 | bad = add bad 1 |
| 247 | end |
| 248 | end |
| 249 | ret bad |
| 250 | end |
| 251 | " \ |
| 252 | "fn sorted a view ulong 10 to ulong |
| 253 | bad = ulong 0 1 |
| 254 | for i ulong 9 |
| 255 | if gt get a i get a add i 1 |
| 256 | bad = add bad 1 |
| 257 | end |
| 258 | end |
| 259 | ret bad |
| 260 | end |
| 261 | " \ |
| 262 | "1" 5 |
| 263 | |
| 264 | # 7. bytecopy |
| 265 | run_case "bytecopy" \ |
| 266 | "fn copy_one a uchar to uchar |
| 267 | ret a |
| 268 | end |
| 269 | " \ |
| 270 | "fn copy_one a uchar to uchar |
| 271 | ret 1000 |
| 272 | end |
| 273 | " \ |
| 274 | "1000" 8 |
| 275 | |
| 276 | # 8. echo |
| 277 | run_case "echo" \ |
| 278 | "fn echo_val v long to long |
| 279 | ret v |
| 280 | end |
| 281 | " \ |
| 282 | "fn echo_val v long to long |
| 283 | break |
| 284 | ret v |
| 285 | end |
| 286 | " \ |
| 287 | "break" 9 |
| 288 | |
| 289 | # 9. sum_squares |
| 290 | run_case "sum_squares" \ |
| 291 | "fn sum_sq a int b int to int |
| 292 | x = mul a a |
| 293 | y = mul b b |
| 294 | ret add x y |
| 295 | end |
| 296 | " \ |
| 297 | "fn sum_sq a int b int to int |
| 298 | x = mul a unknown_var |
| 299 | y = mul b b |
| 300 | ret add x y |
| 301 | end |
| 302 | " \ |
| 303 | "unknown_var" 13 |
| 304 | |
| 305 | # 10. t_bounds |
| 306 | run_case "t_bounds" \ |
| 307 | "fn check_bound x int to int |
| 308 | if lt x 0 |
| 309 | trap 1 |
| 310 | end |
| 311 | ret x |
| 312 | end |
| 313 | " \ |
| 314 | "fn check_bound x int to int |
| 315 | if lt x 0 |
| 316 | trap 999 |
| 317 | end |
| 318 | ret x |
| 319 | end |
| 320 | " \ |
| 321 | "999" 8 |
| 322 | # 11. next_while_loop (loop constructs break/continue, local variable, signature) |
| 323 | run_next_case "next_while" \ |
| 324 | "fn main to int |
| 325 | a = ulong 3 |
| 326 | while lt a 9 |
| 327 | " \ |
| 328 | "omega-query v1 |
| 329 | scope: function |
| 330 | constructs: ret if while for trap exit put end note break continue |
| 331 | names: |
| 332 | a ulong local |
| 333 | functions: |
| 334 | fn main to int" |
| 335 | |
| 336 | # 12. next_params (bool param vs int local, non-loop constructs, return void bool) |
| 337 | run_next_case "next_params" \ |
| 338 | "fn compute c bool to void |
| 339 | val = int 42 |
| 340 | " \ |
| 341 | "omega-query v1 |
| 342 | scope: function |
| 343 | constructs: ret if while for trap exit put end note |
| 344 | names: |
| 345 | c bool param |
| 346 | val int local |
| 347 | functions: |
| 348 | fn compute to void bool" |
| 349 | |
| 350 | # 13. next_sig_multi (multiple typed params and locals, multi-arg signature) |
| 351 | run_next_case "next_sig_multi" \ |
| 352 | "fn add_scaled x uint y uint to uint |
| 353 | s = uint 2 |
| 354 | " \ |
| 355 | "omega-query v1 |
| 356 | scope: function |
| 357 | constructs: ret if while for trap exit put end note |
| 358 | names: |
| 359 | x uint param |
| 360 | y uint param |
| 361 | s uint local |
| 362 | functions: |
| 363 | fn add_scaled to uint uint uint" |
| 364 | |
| 365 | # 14. next_toplevel (toplevel scope, global and const declarations) |
| 366 | run_next_case "next_toplevel" \ |
| 367 | "global g_buf uchar 16 |
| 368 | const MAX_LEN ulong 1024 |
| 369 | " \ |
| 370 | "omega-query v1 |
| 371 | scope: toplevel |
| 372 | constructs: fn const global text struct note |
| 373 | names: |
| 374 | g_buf uchar global |
| 375 | MAX_LEN ulong const |
| 376 | functions:" |
| 377 | |
| 378 | # 15. next_for_loop (for loop allows break and continue, loop index is local) |
| 379 | run_next_case "next_for_loop" \ |
| 380 | "fn loop_test to int |
| 381 | sum = int 0 |
| 382 | for i ulong 10 |
| 383 | " \ |
| 384 | "omega-query v1 |
| 385 | scope: function |
| 386 | constructs: ret if while for trap exit put end note break continue |
| 387 | names: |
| 388 | sum int local |
| 389 | i ulong local |
| 390 | functions: |
| 391 | fn loop_test to int" |
| 392 | |
| 393 | # 16. next_om2_func (om2 profile, completed preceding function and active function) |
| 394 | run_next_case "next_om2_func" \ |
| 395 | "om2 |
| 396 | fn helper x ulong to ulong |
| 397 | ret x |
| 398 | end |
| 399 | fn caller a ulong to ulong |
| 400 | b = ulong 1 |
| 401 | while lt b 10 |
| 402 | " \ |
| 403 | "omega-query v1 |
| 404 | scope: function |
| 405 | constructs: ret if while for trap exit put end note break continue |
| 406 | names: |
| 407 | a ulong param |
| 408 | b ulong local |
| 409 | functions: |
| 410 | fn helper to ulong ulong |
| 411 | fn caller to ulong ulong" |
| 412 | |
| 413 | # 17. next_om2_view (om2 view parameter kind) |
| 414 | run_next_case "next_om2_view" \ |
| 415 | "om2 |
| 416 | fn process buf view uchar 32 to void |
| 417 | n = ulong 0 |
| 418 | " \ |
| 419 | "omega-query v1 |
| 420 | scope: function |
| 421 | constructs: ret if while for trap exit put end note |
| 422 | names: |
| 423 | buf uchar view |
| 424 | n ulong local |
| 425 | functions: |
| 426 | fn process to void uchar" |
| 427 | |
| 428 | # 18. next_neg_control (negative control: fails if expected output has wrong kind) |
| 429 | run_next_neg_control "next_neg_ctrl" \ |
| 430 | "fn main to int |
| 431 | a = ulong 3 |
| 432 | while lt a 9 |
| 433 | " \ |
| 434 | "omega-query v1 |
| 435 | scope: function |
| 436 | constructs: ret if while for trap exit put end note break continue |
| 437 | names: |
| 438 | a ulong local |
| 439 | functions: |
| 440 | fn main to int" \ |
| 441 | "omega-query v1 |
| 442 | scope: function |
| 443 | constructs: ret if while for trap exit put end note break continue |
| 444 | names: |
| 445 | a ulong param |
| 446 | functions: |
| 447 | fn main to int" |
| 448 | |
| 449 | # qty must be preserved in names and function signatures, not reported as view. |
| 450 | run_next_case "next_qty" \ |
| 451 | $'fn grow n qty to qty\nv = qty 1\n' \ |
| 452 | $'omega-query v1\nscope: function\nconstructs: ret if while for trap exit put end note\nnames:\nn qty param\nv qty local\nfunctions:\nfn grow to qty qty' |
| 453 | |
| 454 | run_check_record() { |
| 455 | local name="$1" input="$2" code="$3" expected="$4" mode="${5:-check}" out rc=0 |
| 456 | out=$(printf "%s\n%s" "$mode" "$input" | "$OMC" 2>/dev/null) || rc=$? |
| 457 | if [ "$rc" -ne "$code" ] || [ "$out" != "$expected" ]; then |
| 458 | echo "FAIL check record on $name: rc=$rc out=$out" >&2 |
| 459 | return 1 |
| 460 | fi |
| 461 | printf '%s | PASS (exact check record)\n' "$name" |
| 462 | PASS_COUNT=$((PASS_COUNT + 1)) |
| 463 | } |
| 464 | |
| 465 | run_check_record "check_final" $'fn f to int\nret true\nend\n' 7 \ |
| 466 | $'omega-diag v1\nom1 TYPE span=16-20 FINAL REPAIRABLE code=7 line=2 expect=value found=true' |
| 467 | run_check_record "check_unknown" $'fn f to int\nret missing\nend\n' 3 \ |
| 468 | $'omega-diag v1\nom1 NAME span=16-23 UNKNOWN REPAIRABLE code=3 line=2 expect=name found=missing' |
| 469 | run_check_record "check_incomplete" $'fn f to int\n' 15 \ |
| 470 | $'omega-diag v1\nom1 SYNTAX span=12-12 INCOMPLETE REPAIRABLE code=15 line=2 expect=end found=eof' |
| 471 | |
| 472 | # Register exhaustion is still UNREPAIRABLE, regardless of finality. |
| 473 | capacity=$'fn f to int\n' |
| 474 | for i in {1..17}; do capacity+="v$i = int 0"$'\n'; done |
| 475 | capacity+=$'ret 0\nend\n' |
| 476 | run_check_record "check_capacity" "$capacity" 12 \ |
| 477 | $'omega-diag v1\nom1 CAPACITY span=201-204 FINAL UNREPAIRABLE code=12 line=18 expect=word found=int' |
| 478 | |
| 479 | # DIAG-1: exact records from the category audit, with corrected wire categories. |
| 480 | run_check_record "check_range" $'fn f to uchar\nret 1000\nend\n' 8 \ |
| 481 | $'omega-diag v1\nom1 RANGE span=18-22 FINAL REPAIRABLE code=8 line=2 expect=number found=1000' |
| 482 | run_check_record "check_flow" $'fn f to int\nend\n' 18 \ |
| 483 | $'omega-diag v1\nom1 FLOW span=15-16 FINAL REPAIRABLE code=18 line=3 expect=newline found=0a' |
| 484 | run_check_record "check_size" $'global g uchar 16777217\nfn main to int\nret 0\nend\n' 23 \ |
| 485 | $'omega-diag v1\nom1 CAPACITY span=15-23 FINAL UNREPAIRABLE code=23 line=1 expect=type found=16777217' |
| 486 | run_check_record "check_dead" $'fn f to int\nret 0\nret 1\nend\n' 17 \ |
| 487 | $'omega-diag v1\nom1 FLOW span=18-21 FINAL REPAIRABLE code=17 line=3 expect=word found=ret' |
| 488 | |
| 489 | # Cover the remaining readily constructed category mappings, independently of spans. |
| 490 | run_category_case() { |
| 491 | local name="$1" code="$2" category="$3" input="$4" out rc=0 |
| 492 | out=$(printf 'check\n%s' "$input" | "$OMC" 2>/dev/null) || rc=$? |
| 493 | if [ "$rc" -ne "$code" ] || |
| 494 | [[ "$out" != $'omega-diag v1\nom1 '"$category "* ]] || |
| 495 | [[ "$out" != *" code=$code "* ]] || |
| 496 | [ "$(printf '%s\n' "$out" | wc -l)" -ne 2 ]; then |
| 497 | echo "FAIL category on $name: rc=$rc out=$out" >&2 |
| 498 | return 1 |
| 499 | fi |
| 500 | PASS_COUNT=$((PASS_COUNT + 1)) |
| 501 | } |
| 502 | run_category_case "category_number" 6 SYNTAX $'fn f to int\nx = 12a\nret 0\nend\n' |
| 503 | run_category_case "category_duplicate" 10 NAME $'fn f x int x int to int\nret 0\nend\n' |
| 504 | run_category_case "category_syntax" 16 SYNTAX $'wat\n' |
| 505 | run_category_case "category_alias" 19 TYPE $'global g uchar 4\nfn f a edit uchar 4 to void\nend\nfn main to int\nf g\nret 0\nend\n' |
| 506 | run_category_case "category_index" 21 RANGE $'fn main to int\na = new uint 4 0\nput a 4 1\nret 0\nend\n' |
| 507 | run_category_case "category_text" 22 SYNTAX $'text t "a\\q"\nfn main to int\nret 0\nend\n' |
| 508 | table_capacity='' |
| 509 | for ((i=1; i<=8193; i++)); do table_capacity+="global g$i uchar 1"$'\n'; done |
| 510 | table_capacity+=$'fn main to int\nret 0\nend\n' |
| 511 | run_category_case "category_table" 14 CAPACITY "$table_capacity" |
| 512 | |
| 513 | # DIAG-2: compare every byte and record, including the final newline. The small |
| 514 | # control uses the same legal function names without crossing the old msg pool. |
| 515 | scratch=$(mktemp -d) |
| 516 | trap 'rm -rf "$scratch"' EXIT |
| 517 | for count in 10 1200; do |
| 518 | printf 'next\n' > "$scratch/query.om" |
| 519 | printf 'omega-query v1\nscope: toplevel\nconstructs: fn const global text struct note\nnames:\nfunctions:\n' > "$scratch/query.want" |
| 520 | for ((i=0; i<count; i++)); do |
| 521 | name="function_${i}_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
| 522 | printf 'fn %s to int\nret 0\nend\n' "$name" >> "$scratch/query.om" |
| 523 | printf 'fn %s to int\n' "$name" >> "$scratch/query.want" |
| 524 | done |
| 525 | rc=0 |
| 526 | "$OMC" < "$scratch/query.om" > "$scratch/query.out" 2> "$scratch/query.err" || rc=$? |
| 527 | if [ "$rc" -ne 0 ] || [ -s "$scratch/query.err" ] || |
| 528 | ! cmp -s "$scratch/query.want" "$scratch/query.out" || |
| 529 | [ "$(grep -c '^fn ' "$scratch/query.out")" -ne "$count" ]; then |
| 530 | echo "FAIL next complete records count=$count rc=$rc" >&2 |
| 531 | diff -u "$scratch/query.want" "$scratch/query.out" >&2 || true |
| 532 | exit 1 |
| 533 | fi |
| 534 | PASS_COUNT=$((PASS_COUNT + 1)) |
| 535 | done |
| 536 | |
| 537 | # DIAG-3: each failed-output probe has an identical successful-output control. |
| 538 | # Ordinary compilation is the independent pre-existing error-2 control. |
| 539 | [ -c /dev/full ] || { echo "FAIL: /dev/full unavailable" >&2; exit 1; } |
| 540 | for mode in check next normal; do |
| 541 | { |
| 542 | [ "$mode" = normal ] || printf '%s\n' "$mode" |
| 543 | printf 'fn main to int\nret 0\nend\n' |
| 544 | } > "$scratch/io.om" |
| 545 | rc=0 |
| 546 | "$OMC" < "$scratch/io.om" > "$scratch/io.out" 2> "$scratch/io.err" || rc=$? |
| 547 | if [ "$rc" -ne 0 ] || [ ! -s "$scratch/io.out" ] || [ -s "$scratch/io.err" ]; then |
| 548 | echo "FAIL $mode successful-output control: rc=$rc" >&2 |
| 549 | exit 1 |
| 550 | fi |
| 551 | if [ "$mode" = check ]; then |
| 552 | printf 'omega-diag v1\n' > "$scratch/io.want" |
| 553 | cmp -s "$scratch/io.want" "$scratch/io.out" || { echo "FAIL check output control" >&2; exit 1; } |
| 554 | elif [ "$mode" = next ]; then |
| 555 | printf 'omega-query v1\nscope: toplevel\nconstructs: fn const global text struct note\nnames:\nfunctions:\nfn main to int\n' > "$scratch/io.want" |
| 556 | cmp -s "$scratch/io.want" "$scratch/io.out" || { echo "FAIL next output control" >&2; exit 1; } |
| 557 | fi |
| 558 | rc=0 |
| 559 | "$OMC" < "$scratch/io.om" > /dev/full 2> "$scratch/io.err" || rc=$? |
| 560 | if [ "$rc" -ne 2 ]; then |
| 561 | echo "FAIL $mode /dev/full: expected compiler I/O error 2, got $rc" >&2 |
| 562 | exit 1 |
| 563 | fi |
| 564 | PASS_COUNT=$((PASS_COUNT + 1)) |
| 565 | done |
| 566 | |
| 567 | # Remaining audit prefixes preserve profile routing and finality boundaries. |
| 568 | run_next_case "audit_next_after_ret" $'fn f to int\nret 0\n' $'omega-query v1\nscope: function\nconstructs: ret if while for trap exit put end note\nnames:\nfunctions:\nfn f to int' |
| 569 | run_next_case "audit_next_after_break" $'fn f to int\nwhile true\nbreak\n' $'omega-query v1\nscope: function\nconstructs: ret if while for trap exit put end note break continue\nnames:\nfunctions:\nfn f to int' |
| 570 | run_next_case "audit_next_after_global" $'global g uchar 1\n' $'omega-query v1\nscope: toplevel\nconstructs: fn const global text struct note\nnames:\ng uchar global\nfunctions:' |
| 571 | run_next_case "audit_next_function_complete" $'fn f to int\nret 0\nend\n' $'omega-query v1\nscope: toplevel\nconstructs: fn const global text struct note\nnames:\nfunctions:\nfn f to int' |
| 572 | run_check_record "audit_next_in_struct" $'struct S a ulong\n' 4 $'omega-diag v1\nom1 SYNTAX span=16-17 FINAL REPAIRABLE code=4 line=2 expect=type found=0a' next |
| 573 | run_check_record "audit_check_prefix_note" $'note comment\nfn f to int\nret true\nend\n' 7 $'omega-diag v1\nom1 TYPE span=29-33 FINAL REPAIRABLE code=7 line=3 expect=value found=true' |
| 574 | run_check_record "audit_check_ir_bad" $'ir\nfn f to int\nret true\nend\n' 16 $'omega-diag v1\nom1 SYNTAX span=0-2 FINAL REPAIRABLE code=16 line=1 expect=word found=ir' |
| 575 | run_check_record "audit_check_ir" $'ir\nfn f to int\nret 0\nend\n' 16 $'omega-diag v1\nom1 SYNTAX span=0-2 FINAL REPAIRABLE code=16 line=1 expect=word found=ir' |
| 576 | run_check_record "audit_check_om2" $'om2\nfn f to int\nret true\nend\n' 7 $'omega-diag v1\nom2 TYPE span=20-24 FINAL REPAIRABLE code=7 line=3 expect=value found=true' |
| 577 | run_check_record "audit_check_om2fmt" $'om2 fmt\nfn f to int\nret true\nend\n' 16 $'omega-diag v1\nom2 SYNTAX span=0-0 FINAL REPAIRABLE code=16 line=1 expect=word found=-' |
| 578 | run_check_record "audit_check_om2diag" $'om2 diag\nfn f to int\nret true\nend\n' 7 $'omega-diag v1\nom2 TYPE span=25-29 FINAL REPAIRABLE code=7 line=3 expect=value found=true' |
| 579 | run_check_record "audit_finality_unknown" $'fn f to int\nret nosuch\nend\n' 3 $'omega-diag v1\nom1 NAME span=16-22 UNKNOWN REPAIRABLE code=3 line=2 expect=name found=nosuch' |
| 580 | run_check_record "audit_finality_bad_line" $'fn f to int\nret add 1\n' 4 $'omega-diag v1\nom1 SYNTAX span=21-22 FINAL REPAIRABLE code=4 line=3 expect=value found=0a' |
| 581 | run_check_record "audit_finality_end_type" $'fn f to int\nret true' 7 $'omega-diag v1\nom1 TYPE span=16-20 FINAL REPAIRABLE code=7 line=2 expect=value found=true' |
| 582 | run_check_record "audit_finality_badnum" $'fn f to int\nret 1z' 6 $'omega-diag v1\nom1 SYNTAX span=16-18 FINAL REPAIRABLE code=6 line=2 expect=number found=1z' |
| 583 | |
| 584 | [ "$PASS_COUNT" -eq "$TOTAL" ] || { |
| 585 | echo "FAIL case count: ran $PASS_COUNT, expected $TOTAL" >&2 |
| 586 | exit 1 |
| 587 | } |
| 588 | |
| 589 | echo "---------------------------------------------------------------------------------------------------------" |
| 590 | echo "ALL $PASS_COUNT/$TOTAL EXPERIMENT CHECKS PASSED (negative control + exact first error span matching)" |