run_tests.sh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. #!/bin/sh
  2. # Step-1 regression: M2 -> gen_ssa/*.ssa -> qbe -> cc -> exit code.
  3. # Usage: ./run_tests.sh (from the compiler directory)
  4. pass=0; fail=0
  5. SHIM="../runtime/syslib/shim.c"
  6. modof() {
  7. sed -n 's/^MODULE \([A-Za-z][A-Za-z0-9]*\).*/\1/p' "tests/$1" | head -n 1
  8. }
  9. expect_run() {
  10. # $1 = test file (no dir), $2 = expected exit code
  11. name="$1"; want="$2"; mod=$(modof "$name")
  12. rm -f "gen_ssa/$mod.ssa" "gen_ssa/$mod.s" "gen_ssa/$mod"
  13. if ./M2 "tests/$name" 2>&1 | grep -q "Parsed correctly"; then :; else
  14. fail=$((fail+1)); echo "FAIL(run): $name rejected"; return
  15. fi
  16. if [ ! -f "gen_ssa/$mod.ssa" ]; then
  17. fail=$((fail+1)); echo "FAIL(run): $name no gen_ssa/$mod.ssa"; return
  18. fi
  19. if ! qbe -o "gen_ssa/$mod.s" "gen_ssa/$mod.ssa" 2> "gen_ssa/$mod.qbeerr"; then
  20. fail=$((fail+1)); echo "FAIL(run): $name qbe:"; cat "gen_ssa/$mod.qbeerr"; return
  21. fi
  22. if ! cc "gen_ssa/$mod.s" "$SHIM" -o "gen_ssa/$mod" 2> "gen_ssa/$mod.ccerr"; then
  23. fail=$((fail+1)); echo "FAIL(run): $name cc:"; cat "gen_ssa/$mod.ccerr"; return
  24. fi
  25. timeout 10 "gen_ssa/$mod" > /dev/null 2>&1; got=$?
  26. if [ "$got" = "$want" ]; then
  27. pass=$((pass+1)); echo "PASS(run): $name -> $got"
  28. else
  29. fail=$((fail+1)); echo "FAIL(run): $name got $got want $want"
  30. fi
  31. }
  32. expect_fail() {
  33. # $1 = test file, $2 = message text expected in the .LST
  34. name="$1"; want="$2"
  35. if ./M2 "tests/$name" 2>&1 | grep -q "Incorrect source"; then :; else
  36. fail=$((fail+1)); echo "FAIL(fail): $name accepted"; return
  37. fi
  38. lst="tests/$(basename "$name" .mod).LST"
  39. if grep -q "$want" "$lst" 2>/dev/null; then
  40. pass=$((pass+1)); echo "PASS(fail): $name [$want]"
  41. else
  42. fail=$((fail+1)); echo "FAIL(fail): [$want] not found in $lst"
  43. fi
  44. }
  45. mkdir -p gen_ssa
  46. expect_run t_minimal.mod 0
  47. expect_run t_exit.mod 7
  48. expect_run t_arith.mod 25
  49. expect_run showcase1.mod 50
  50. expect_run t_types.mod 8
  51. expect_run showcase2.mod 71
  52. expect_run t_if.mod 25
  53. expect_run t_while.mod 55
  54. expect_run t_repeat.mod 55
  55. expect_run t_loop.mod 55
  56. expect_run t_for.mod 85
  57. expect_run t_case.mod 103
  58. expect_run t_bool.mod 42
  59. expect_run t_real.mod 31
  60. expect_run t_array.mod 108
  61. expect_run t_ctor1.mod 0
  62. expect_run t_ctor2.mod 0
  63. expect_run t_ctor3.mod 0
  64. expect_run t_ctor4.mod 0
  65. expect_run t_ctor5.mod 0
  66. expect_run t_ctor6.mod 0
  67. expect_run t_ctor7.mod 42
  68. expect_run t_minmax.mod 42
  69. expect_run t_minmax2.mod 42
  70. expect_run t_setops.mod 42
  71. expect_run t_fwdtype.mod 42
  72. expect_run t_libc.mod 42
  73. expect_run t_variant2.mod 42
  74. expect_run t_addrptr.mod 42
  75. expect_run t_nestedmod.mod 42
  76. expect_run t_nestidx.mod 42
  77. expect_run t_proctype.mod 42
  78. expect_run t_compat.mod 42
  79. expect_run t_constfold.mod 42
  80. expect_run t_resultsfx.mod 42
  81. expect_run t_coroutine.mod 42
  82. expect_run t_fwdvar.mod 42
  83. expect_run t_emptystat.mod 42
  84. expect_run t_highlen.mod 18
  85. expect_run t_builtins.mod 42
  86. expect_run t_long.mod 42
  87. expect_run t_unicode.mod 31
  88. expect_run t_charbounds.mod 3
  89. expect_run t_record.mod 160
  90. expect_run t_with.mod 114
  91. expect_run t_set.mod 131
  92. expect_run t_setchar.mod 77
  93. expect_run t_setrange.mod 55
  94. expect_run t_classmethod.mod 7
  95. expect_run t_classinherit.mod 7
  96. expect_run t_virtual.mod 3
  97. expect_run t_valconv.mod 15
  98. expect_run t_classsibling.mod 7
  99. expect_run t_classinit.mod 42
  100. expect_run t_class.mod 0
  101. expect_run t_longline.mod 0
  102. expect_fail t_bad_parent.mod "undeclared identifier"
  103. expect_run showcase3.mod 183
  104. expect_run showcase4.mod 44
  105. expect_fail showcase5.mod "not supported yet"
  106. expect_run showcase6.mod 34
  107. expect_run showcase7.mod 219
  108. expect_run showcase8.mod 170
  109. expect_run showcase9.mod 140
  110. expect_run showcase10.mod 86
  111. expect_run t_pointer.mod 42
  112. expect_run t_ptrarray.mod 15
  113. expect_run t_ptrrec.mod 15
  114. expect_run t_ptrnest.mod 10
  115. expect_fail t_opaqueptr.mod ""
  116. expect_run t_enumdecl.mod 0
  117. expect_run t_enum.mod 15
  118. expect_run t_strcat.mod 63
  119. expect_run t_charcat.mod 15
  120. expect_run t_variant.mod 31
  121. expect_run t_ustrassign.mod 63
  122. expect_run t_ustrformal.mod 3
  123. expect_run t_ustrcat.mod 63
  124. expect_run t_proc.mod 0
  125. expect_run t_forward.mod 0
  126. expect_run t_call.mod 125
  127. expect_run t_varpar.mod 40
  128. expect_run t_mutual.mod 11
  129. expect_run t_withfield.mod 13
  130. expect_run t_valarray.mod 6
  131. expect_run t_openarr.mod 7
  132. expect_run t_nestedproc.mod 20
  133. expect_run t_nestdeep.mod 211
  134. expect_run t_nestrec.mod 15
  135. expect_fail t_bad_undecl.mod "undeclared identifier"
  136. expect_fail t_bad_dup.mod "duplicate identifier"
  137. expect_fail t_bad_mismatch.mod "module name mismatch"
  138. expect_fail t_bad_opaque.mod "opaque type outside definition"
  139. expect_fail t_bad_while.mod "BOOLEAN condition required"
  140. expect_fail t_bad_exit.mod "not supported yet"
  141. expect_fail t_bad_return.mod "bad RETURN"
  142. expect_fail t_bad_for.mod "FOR needs integer variable and bounds"
  143. expect_fail t_bad_mixed.mod "incompatible assignment"
  144. expect_fail t_bad_overlong.mod "invalid UTF-8"
  145. expect_fail t_bad_surrogate.mod "invalid UTF-8"
  146. expect_fail t_bad_utf8big.mod "invalid UTF-8"
  147. expect_fail t_bad_truncutf.mod "invalid UTF-8"
  148. expect_fail t_bad_arity.mod "invalid call"
  149. expect_fail t_bad_actual.mod "invalid call"
  150. expect_fail t_bad_funstmt.mod "invalid call"
  151. expect_fail t_bad_deref.mod "not a POINTER type"
  152. expect_fail t_bad_new.mod "not a POINTER type"
  153. expect_fail t_bad_field.mod "unknown field"
  154. expect_fail t_bad_with.mod "not a RECORD type"
  155. expect_fail t_bad_recassign.mod "incompatible assignment"
  156. expect_fail t_bad_setelem.mod "set operand mismatch"
  157. expect_fail t_bad_setbase.mod "not supported yet"
  158. expect_fail t_bad_in.mod "set operand mismatch"
  159. expect_fail t_bad_index.mod "array index must be integer"
  160. expect_fail t_bad_bounds.mod "not supported yet"
  161. expect_fail t_bad_varbound.mod "not supported yet"
  162. expect_fail t_bad_manydims.mod "not supported yet"
  163. expect_run t_openformal.mod 0
  164. expect_run t_valopen.mod 15
  165. expect_fail t_bad_open.mod "not supported yet"
  166. expect_trap() {
  167. # $1 = test file — must parse, assemble, link, then abort (rc=134)
  168. name="$1"; mod=$(modof "$name")
  169. rm -f "gen_ssa/$mod.ssa" "gen_ssa/$mod.s" "gen_ssa/$mod"
  170. if ./M2 "tests/$name" 2>&1 | grep -q "Parsed correctly"; then :; else
  171. fail=$((fail+1)); echo "FAIL(trap): $name rejected"; return
  172. fi
  173. if ! qbe -o "gen_ssa/$mod.s" "gen_ssa/$mod.ssa" 2> "gen_ssa/$mod.qbeerr"; then
  174. fail=$((fail+1)); echo "FAIL(trap): $name qbe"; return
  175. fi
  176. if ! cc "gen_ssa/$mod.s" "$SHIM" -o "gen_ssa/$mod" 2> "gen_ssa/$mod.ccerr"; then
  177. fail=$((fail+1)); echo "FAIL(trap): $name cc"; return
  178. fi
  179. timeout 10 "gen_ssa/$mod" > /dev/null 2>&1; got=$?
  180. if [ "$got" = "134" ]; then
  181. pass=$((pass+1)); echo "PASS(trap): $name -> abort"
  182. else
  183. fail=$((fail+1)); echo "FAIL(trap): $name rc=$got want 134"
  184. fi
  185. }
  186. expect_trap t_trap_index.mod
  187. expect_run t_strtrunc.mod 42
  188. expect_trap t_trap_setspan.mod
  189. expect_run t_strempty.mod 42
  190. expect_trap t_trap_chr8.mod
  191. expect_fail t_defunit.mod ""
  192. expect_fail t_implunit.mod ""
  193. expect_run t_nested.mod 42
  194. # --- separate compilation (step 4.3): $1 prog module, $2 exit code,
  195. # then the session's source files (program last by convention) ---
  196. # Build a session image; echoes 0 on success, non-zero on failure.
  197. build_session() {
  198. prog="$1"; shift
  199. files=""
  200. for f in "$@"; do
  201. case "$f" in */*) files="$files $f";; *) files="$files tests/$f";; esac
  202. done
  203. rm -f "gen_ssa/$prog.ssa" "gen_ssa/$prog.s" "gen_ssa/$prog"
  204. if ./M2 $files 2>&1 | grep -q "Parsed correctly"; then :; else
  205. echo "rejected"; return 1
  206. fi
  207. [ -f "gen_ssa/$prog.ssa" ] || { echo "no image"; return 1; }
  208. qbe -o "gen_ssa/$prog.s" "gen_ssa/$prog.ssa" 2> "gen_ssa/$prog.qbeerr" \
  209. || { echo "qbe"; cat "gen_ssa/$prog.qbeerr"; return 1; }
  210. cc "gen_ssa/$prog.s" "$SHIM" -o "gen_ssa/$prog" -lm 2> "gen_ssa/$prog.ccerr" \
  211. || { echo "cc"; cat "gen_ssa/$prog.ccerr"; return 1; }
  212. return 0
  213. }
  214. expect_run_files() {
  215. prog="$1"; want="$2"; shift 2
  216. if ! build_session "$prog" "$@"; then
  217. fail=$((fail+1)); echo "FAIL(session): $prog $? ($(build_session "$prog" "$@" 2>&1))"; return
  218. fi
  219. timeout 10 "gen_ssa/$prog" > /dev/null 2>&1; got=$?
  220. if [ "$got" = "$want" ]; then
  221. pass=$((pass+1)); echo "PASS(session): $prog -> $got"
  222. else
  223. fail=$((fail+1)); echo "FAIL(session): $prog got $got want $want"
  224. fi
  225. }
  226. expect_run_files_out() {
  227. # $1 prog, $2 exit code, $3 expected first output line, then files
  228. prog="$1"; want="$2"; wantline="$3"; shift 3
  229. if ! build_session "$prog" "$@"; then
  230. fail=$((fail+1)); echo "FAIL(session-out): $prog build failed"; return
  231. fi
  232. out=$(timeout 10 "gen_ssa/$prog" 2>/dev/null); got=$?
  233. first=$(printf '%s\n' "$out" | head -n 1)
  234. if [ "$got" = "$want" ] && [ "$first" = "$wantline" ]; then
  235. pass=$((pass+1)); echo "PASS(session-out): $prog -> $got [$first]"
  236. else
  237. fail=$((fail+1)); echo "FAIL(session-out): $prog rc=$got line=[$first] want=[$wantline]"
  238. fi
  239. }
  240. expect_run_files DBasicProg 49 d_basic.def d_basic.mod d_basic_prog.mod
  241. expect_run_files TClassDefProg 8 t_classdef.def t_classdef_prog.mod
  242. expect_run_files DQualProg 46 d_basic.def d_basic.mod d_qual_prog.mod
  243. expect_run_files DTypesProg 36 d_types.def d_types.mod d_types_prog.mod
  244. expect_run_files DOpaqueProg 55 d_opaque.def d_opaque.mod d_opaque_prog.mod
  245. expect_run_files TString 42 d_string.def d_string.mod t_string.mod
  246. expect_run_files FioProg 42 ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../runtime/syslib/FileIO.def ../runtime/syslib/FileIO.mod fio_prog.mod
  247. expect_run_files StorageProg 42 ../stdlib/storage.def ../stdlib/storage.mod storage_prog.mod
  248. expect_run_files TAst 42 \
  249. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  250. ../runtime/syslib/FileIO.def ../runtime/syslib/FileIO.mod \
  251. src/AST.def src/AST.mod \
  252. t_ast.mod
  253. expect_run_files WrapProg 42 \
  254. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  255. ../stdlib/iochan.def ../stdlib/iochan.mod \
  256. ../stdlib/stdchans.def ../stdlib/stdchans.mod \
  257. ../stdlib/timestring.def ../stdlib/timestring.mod \
  258. ../stdlib/wrapclock.def ../stdlib/wrapclock.mod \
  259. ../stdlib/wraptime.def ../stdlib/wraptime.mod \
  260. ../stdlib/wrapc.def ../stdlib/wrapc.mod \
  261. wrapprog.mod
  262. expect_run_files_out Showcase22 42 "showcase22 total=42" \
  263. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  264. ../stdlib/iochan.def ../stdlib/iochan.mod \
  265. ../stdlib/stdchans.def ../stdlib/stdchans.mod \
  266. ../stdlib/timestring.def ../stdlib/timestring.mod \
  267. ../stdlib/wrapclock.def ../stdlib/wrapclock.mod \
  268. ../stdlib/wraptime.def ../stdlib/wraptime.mod \
  269. ../stdlib/wrapc.def ../stdlib/wrapc.mod \
  270. showcase22.mod
  271. expect_run_files Library1 42 \
  272. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  273. ../stdlib/convtypes.def ../stdlib/convtypes.mod \
  274. ../stdlib/ioconsts.def ../stdlib/ioconsts.mod \
  275. ../stdlib/conversions.def ../stdlib/conversions.mod \
  276. ../stdlib/math.def ../stdlib/math.mod \
  277. ../stdlib/sioresult.def ../stdlib/sioresult.mod \
  278. ../stdlib/TERMINATION.def ../stdlib/TERMINATION.mod \
  279. ../stdlib/wholestr.def ../stdlib/wholestr.mod \
  280. ../stdlib/realstr.def ../stdlib/realstr.mod \
  281. ../stdlib/longstr.def ../stdlib/longstr.mod \
  282. ../stdlib/longmath.def ../stdlib/longmath.mod \
  283. ../stdlib/iochan.def ../stdlib/iochan.mod \
  284. ../stdlib/longio.def ../stdlib/longio.mod \
  285. ../stdlib/strio.def ../stdlib/strio.mod \
  286. ../stdlib/inout.def ../stdlib/inout.mod \
  287. ../stdlib/stdio.def ../stdlib/stdio.mod \
  288. ../stdlib/stextio.def ../stdlib/stextio.mod \
  289. ../stdlib/swholeio.def ../stdlib/swholeio.mod \
  290. ../stdlib/srealio.def ../stdlib/srealio.mod \
  291. library1.mod
  292. expect_run_files TDynStr 42 \
  293. ../stdlib/dynamicstrings.def ../stdlib/dynamicstrings.mod \
  294. ../stdlib/sysstorage.def ../stdlib/sysstorage.mod \
  295. t_dynstr.mod
  296. expect_run_files ClashProg 60 d_clash_a.def d_clash_a.mod d_clash_b.def d_clash_b.mod d_clash_prog.mod
  297. expect_run_files_out Hello 0 "Hello, Modula-2!" ../stdlib/sysio.def ../stdlib/sysio.mod hello.mod
  298. expect_run_files_out StringsProg 0 "Hello World" ../stdlib/sysio.def ../stdlib/sysio.mod ../stdlib/strings.def ../stdlib/strings.mod strings_prog.mod
  299. expect_run_files StringsSliceProg 255 ../stdlib/strings.def ../stdlib/strings.mod strings_slice_prog.mod
  300. expect_run_files_out Stdlib2Prog 42 "stdlib2 n=42" ../stdlib/sysio.def ../stdlib/sysio.mod ../stdlib/math.def ../stdlib/math.mod ../stdlib/strings.def ../stdlib/strings.mod ../stdlib/charclass.def ../stdlib/charclass.mod stdlib2_prog.mod
  301. expect_run_files MathProg 12 ../stdlib/sysio.def ../stdlib/sysio.mod ../stdlib/math.def ../stdlib/math.mod math_prog.mod
  302. expect_run_files Math2Prog 31 ../stdlib/math.def ../stdlib/math.mod math2_prog.mod
  303. expect_run_files SysClockProg 3 ../stdlib/sysclock.def ../stdlib/sysclock.mod sysclock_prog.mod
  304. expect_run_files Utf8Prog 127 ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod utf8_prog.mod
  305. expect_run_files ConvProg 127 ../stdlib/conversions.def ../stdlib/conversions.mod conv_prog.mod
  306. expect_run_files ConvResultsProg 127 ../stdlib/conversions.def ../stdlib/conversions.mod convresults_prog.mod
  307. expect_run_files TStrEq 15 t_streq.mod
  308. expect_run_files ProgArgsProg 7 ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../stdlib/programargs.def ../stdlib/programargs.mod progargs_prog.mod
  309. expect_run_files_out UTextProg 42 "héllo" ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod ../stdlib/textio.def ../stdlib/textio.mod utext_prog.mod
  310. expect_run_files_in() {
  311. # $1 prog, $2 exit code, $3 expected first line, $4 stdin, then files
  312. prog="$1"; want="$2"; wantline="$3"; input="$4"; shift 4
  313. if ! build_session "$prog" "$@"; then
  314. fail=$((fail+1)); echo "FAIL(session-in): $prog build failed"; return
  315. fi
  316. out=$(printf '%s\n' "$input" | timeout 10 "gen_ssa/$prog" 2>/dev/null); got=$?
  317. first=$(printf '%s\n' "$out" | head -n 1)
  318. if [ "$got" = "$want" ] && [ "$first" = "$wantline" ]; then
  319. pass=$((pass+1)); echo "PASS(session-in): $prog -> $got [$first]"
  320. else
  321. fail=$((fail+1)); echo "FAIL(session-in): $prog rc=$got line=[$first] want=[$wantline]"
  322. fi
  323. }
  324. expect_run_files_in ReadProg 0 "42" "20 22" ../stdlib/sysio.def ../stdlib/sysio.mod read_prog.mod
  325. expect_run_files_in WholeIOProg 0 "42" "6 7" ../stdlib/sysio.def ../stdlib/sysio.mod ../stdlib/wholeio.def ../stdlib/wholeio.mod wholeio_prog.mod
  326. expect_run_files_in RealProg 42 "3.500000E+00" "1.25" ../stdlib/realio.def ../stdlib/realio.mod ../stdlib/sysio.def ../stdlib/sysio.mod realio_prog.mod
  327. expect_run_files_in IOChanProg 0 "hello 42" "Z" ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../stdlib/iochan.def ../stdlib/iochan.mod iochan_prog.mod
  328. rm -f gen_ssa/_iochan_tmp.txt
  329. expect_run_files IOChanFileProg 3 ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../stdlib/strings.def ../stdlib/strings.mod ../stdlib/iochan.def ../stdlib/iochan.mod iochanfile_prog.mod
  330. rm -f gen_ssa/_iochan_tmp.txt
  331. rm -f gen_ssa/_iochanseek.txt
  332. expect_run_files IOChanSeekProg 15 ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../stdlib/strings.def ../stdlib/strings.mod ../stdlib/iochan.def ../stdlib/iochan.mod iochanseek_prog.mod
  333. rm -f gen_ssa/_iochanseek.txt
  334. expect_run_files FilesProg 42 ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../stdlib/iochan.def ../stdlib/iochan.mod ../stdlib/files.def ../stdlib/files.mod files_prog.mod
  335. expect_run_files TBadFile 42 ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../stdlib/iochan.def ../stdlib/iochan.mod ../stdlib/files.def ../stdlib/files.mod t_badfile.mod
  336. rm -f gen_ssa/_files_tmp.txt
  337. expect_run_files_in Showcase11 80 "Modula-2" "42" \
  338. ../stdlib/sysio.def ../stdlib/sysio.mod \
  339. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  340. ../stdlib/textio.def ../stdlib/textio.mod \
  341. ../stdlib/wholeio.def ../stdlib/wholeio.mod \
  342. ../stdlib/strings.def ../stdlib/strings.mod \
  343. ../stdlib/math.def ../stdlib/math.mod \
  344. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../stdlib/iochan.def ../stdlib/iochan.mod ../stdlib/files.def ../stdlib/files.mod \
  345. showcase11.mod
  346. rm -f gen_ssa/_showcase11.txt
  347. # step 8.2/8.3: const folding, forward types, trailing ';', empty
  348. # statements, 1-char strings, qualified type names.
  349. expect_run_files Showcase12 42 showcase12lib.def showcase12lib.mod showcase12.mod
  350. expect_run_files_out Showcase13 42 "Even(8)=T Odd(7)=T total=42" ../stdlib/sysio.def ../stdlib/sysio.mod showcase13.mod
  351. expect_run_files_out Showcase19 42 "showcase19 total=42" \
  352. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  353. ../stdlib/textio.def ../stdlib/textio.mod \
  354. ../stdlib/conversions.def ../stdlib/conversions.mod \
  355. showcase19.mod
  356. expect_run_files_out Showcase20 42 "showcase20 total=42" \
  357. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  358. ../stdlib/textio.def ../stdlib/textio.mod \
  359. ../stdlib/conversions.def ../stdlib/conversions.mod \
  360. showcase20.mod
  361. expect_run_files_out Showcase21 42 "showcase21 total=42" \
  362. ../stdlib/convtypes.def ../stdlib/convtypes.mod \
  363. ../stdlib/conversions.def ../stdlib/conversions.mod \
  364. ../stdlib/math.def ../stdlib/math.mod \
  365. ../stdlib/wholestr.def ../stdlib/wholestr.mod \
  366. ../stdlib/realstr.def ../stdlib/realstr.mod \
  367. ../stdlib/longmath.def ../stdlib/longmath.mod \
  368. ../stdlib/dynamicstrings.def ../stdlib/dynamicstrings.mod \
  369. ../stdlib/strio.def ../stdlib/strio.mod \
  370. showcase21.mod
  371. expect_run_files_out Showcase18 42 "showcase18 areas sum=139" \
  372. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  373. ../stdlib/textio.def ../stdlib/textio.mod \
  374. ../stdlib/conversions.def ../stdlib/conversions.mod \
  375. showcase18.mod
  376. expect_run_files_out Showcase17 42 "showcase17 total=42" \
  377. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  378. ../stdlib/textio.def ../stdlib/textio.mod \
  379. ../stdlib/conversions.def ../stdlib/conversions.mod \
  380. showcase17.mod
  381. rm -f gen_ssa/_showcase16.txt
  382. expect_run_files_out Showcase16 42 "showcase16: id=3 total=42" \
  383. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  384. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  385. ../stdlib/iochan.def ../stdlib/iochan.mod \
  386. ../stdlib/files.def ../stdlib/files.mod \
  387. ../stdlib/textio.def ../stdlib/textio.mod \
  388. ../stdlib/strings.def ../stdlib/strings.mod \
  389. ../stdlib/conversions.def ../stdlib/conversions.mod \
  390. showcase16.mod
  391. rm -f gen_ssa/_showcase16.txt
  392. rm -f gen_ssa/_showcase15.txt
  393. expect_run_files_out Showcase15 42 "read back: point 42" \
  394. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  395. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  396. ../stdlib/iochan.def ../stdlib/iochan.mod \
  397. ../stdlib/textio.def ../stdlib/textio.mod \
  398. ../stdlib/strings.def ../stdlib/strings.mod \
  399. ../stdlib/conversions.def ../stdlib/conversions.mod \
  400. showcase15lib.def showcase15lib.mod showcase15.mod
  401. rm -f gen_ssa/_showcase15.txt
  402. expect_run_files_out Showcase14 42 "showcase14 n=42" \
  403. ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod \
  404. ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
  405. ../stdlib/sysio.def ../stdlib/sysio.mod \
  406. ../stdlib/textio.def ../stdlib/textio.mod \
  407. ../stdlib/conversions.def ../stdlib/conversions.mod \
  408. ../stdlib/realio.def ../stdlib/realio.mod \
  409. ../stdlib/programargs.def ../stdlib/programargs.mod \
  410. ../stdlib/iochan.def ../stdlib/iochan.mod \
  411. showcase14.mod
  412. expect_run_files_out MixProg 0 "7" ../runtime/syslib/Utf8.def ../runtime/syslib/Utf8.mod ../stdlib/textio.def ../stdlib/textio.mod ../stdlib/sysio.def ../stdlib/sysio.mod ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod ../stdlib/iochan.def ../stdlib/iochan.mod ../stdlib/files.def ../stdlib/files.mod d_mix_prog.mod
  413. rm -f gen_ssa/_mix.txt
  414. expect_fail_files() {
  415. # $1 = listing basename, $2 = message (may be empty), then files
  416. lst="$1"; want="$2"; shift 2
  417. files=""
  418. for f in "$@"; do files="$files tests/$f"; done
  419. if ./M2 $files 2>&1 | grep -q "Incorrect source"; then :; else
  420. fail=$((fail+1)); echo "FAIL(session-rej): $lst accepted"; return
  421. fi
  422. if [ -z "$want" ]; then
  423. pass=$((pass+1)); echo "PASS(session-rej): $lst"
  424. elif grep -q "$want" "tests/$lst.LST" 2>/dev/null; then
  425. pass=$((pass+1)); echo "PASS(session-rej): $lst [$want]"
  426. else
  427. fail=$((fail+1)); echo "FAIL(session-rej): [$want] not in tests/$lst.LST"
  428. fi
  429. }
  430. expect_fail_files d_badimp_prog "undeclared identifier" d_basic.def d_basic.mod d_badimp_prog.mod
  431. expect_fail_files sig "implementation does not match definition" sig.def sig.mod sig_prog.mod
  432. # --- step 7 gate: compiler sources free of gm2-only imports.
  433. # FileIO is the last module to port (see docs/summary_step7.md);
  434. # it is excluded here so the gate guards everything else. ---
  435. if grep -qE "(IMPORT|FROM)[[:space:]]+.*\b(Environment|FileSysOp|TextIO|RawIO|WholeIO|IOChan|ProgramArgs)\b" \
  436. src/SymTab.def src/SymTab.mod src/QbeGen.def src/QbeGen.mod \
  437. src/M2S.mod src/M2P.mod src/M2.mod src/*.frm 2>/dev/null; then
  438. fail=$((fail+1)); echo "FAIL(gate): gm2-only imports present"
  439. else
  440. pass=$((pass+1)); echo "PASS(gate): no gm2-only imports (FileIO port pending)"
  441. fi
  442. echo "--- $pass passed, $fail failed ---"
  443. [ "$fail" -eq 0 ]