ChipMaster's bwBASIC This also includes history going back to v2.10. *WARN* some binary files might have been corrupted by CRLF.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

499 lines
13 KiB

  1. OPTION VERSION BYWATER
  2. OPTION BUGS OFF
  3. REM PARSE SYNTAX DIAGRAMS AND GENERATE PARAMETER RANGE CHECK TESTS
  4. REM EXAMPLE " SYNTAX: N = ASC( A$ )"
  5. REM
  6. REM THIS PROGRAM ASSUMES A PROPERLY FORMATTED SYNTAX DIAGRAM;
  7. REM ONLY MINIMAL ERROR CHECKING IS PERFORMED.
  8. REM
  9. REM ------------------------------------------------------------
  10. REM VARIABLE USAGE
  11. REM F$ input file name, such as 'SYNTAX.INP'
  12. REM I$ inpuut line, such as 'SYNTAX: N = ASC( A$ )'
  13. REM L location of '('
  14. REM R location of ')'
  15. REM C location of ':' or '=' or or ','
  16. REM P$ current function/parameter
  17. REM N$() function/parameter name, P$(0) = 'ASC', P$(1) = 'A$'
  18. REM T() function/parameter type, T(0) = NUMBER, T(1) = STRING
  19. REM 0 == NUMBER, 1 == STRING
  20. REM N number of paameters, such as 1
  21. REM I generic loop variable
  22. REM C$ current character
  23. REM Z$ cleaned syntax diagram
  24. REM F$ cleaned function name, 'ASC'
  25. REM X$ user selevted function name, 'COS'
  26. REM U$ UniqueID, 'F_COS_X'
  27. REM VN TESTCASE ACTUAL RESULT, NUMBER
  28. REM VS$ TESTCASE ACTUAL RESULT, STRING
  29. REM Q$ CHR$(34)
  30. REM RN() RANDOM NUMBERS
  31. REM RS$() RANDOM STRINGS
  32. REM #1 INPUT FILE, 'SYNTAX.TXT'
  33. REM #2 MERGE FILE, 'SYNTAX.MRG'
  34. REM #3 OUTPUT FILE, 'F_COS_X.BAS'
  35. REM ------------------------------------------------------------
  36. REM DECLARE ARRAYS
  37. REM ------------------------------------------------------------
  38. REM RANDOMIZE ' this must be off for automated regression
  39. DIM N$(9)
  40. DIM T(9)
  41. DIM RN(100)
  42. DIM RS$(100)
  43. N = 0
  44. GOSUB 4500
  45. REM ------------------------------------------------------------
  46. REM GET THE INPUT FILE NAME
  47. REM ------------------------------------------------------------
  48. F$ = "SYNTAX.INP"
  49. X$ = "ASC"
  50. REM PRINT "F$=[";F$;"]"
  51. REM ------------------------------------------------------------
  52. REM PROCESS THE INPUT FILE
  53. REM ------------------------------------------------------------
  54. OPEN F$ FOR INPUT AS #1
  55. WHILE NOT EOF( 1 )
  56. LINE INPUT #1, I$
  57. REM PRINT "I$=[";I$;"]"
  58. REM Process Line in I$
  59. GOSUB 1000 ' ProcessLine
  60. REM IF I$ = X$ THEN
  61. GOSUB 4000 ' DetermineUniqueID
  62. GOSUB 5000 ' DumpResults
  63. REM END IF
  64. WEND
  65. CLOSE #1
  66. PRINT "OK"
  67. GOTO 9999 ' TheEnd
  68. 1000 REM ProcessLine
  69. REM ------------------------------------------------------------
  70. REM PROCESS THE SYNTAX DIAGRAM IN I$
  71. REM ------------------------------------------------------------
  72. N = 0
  73. REM PRINT "I$=[";I$;"]"
  74. I$ = TRIM$( I$ )
  75. IF LEN( I$ ) = 0 THEN RETURN
  76. REM PRINT "I$=[";I$;"]"
  77. REM CHECK MISSING COLON
  78. C = INSTR( I$, ":" )
  79. REM PRINT "C=[";C;"]"
  80. IF C = 0 THEN RETURN
  81. REM REMOVE "SYNTAX:"
  82. I$ = MID$( I$, C + 1 )
  83. I$ = TRIM$( I$ )
  84. REM PRINT "I$=[";I$;"]"
  85. IF LEN( I$ ) = 0 THEN RETURN
  86. REM SAVE CLEANED SYNTAX DIAGRAM
  87. Z$ = I$
  88. REM DETERMINE RETURN TYPE
  89. C = INSTR( I$, "=" )
  90. REM PRINT "C=[";C;"]"
  91. IF C = 0 THEN RETURN
  92. P$ = LEFT$( I$, C - 1 )
  93. P$ = TRIM$( P$ )
  94. REM PRINT "P$=[";P$;"]"
  95. IF LEN( P$ ) = 0 THEN RETURN
  96. I$ = MID$( I$, C + 1 )
  97. I$ = TRIM$( I$ )
  98. REM PRINT "I$=[";I$;"]"
  99. IF LEN( I$ ) = 0 THEN RETURN
  100. GOSUB 3000 ' DetermineTypeInP$
  101. REM I$ = "ASC( A$ )"
  102. REM PRINT "I$=[";I$;"]"
  103. L = INSTR( I$, "(" )
  104. R = INSTR( I$, ")" )
  105. REM PRINT "L=[";L;"]"
  106. REM PRINT "R=[";R;"]"
  107. IF R < L THEN RETURN ' ERROR ...)...(
  108. IF R = 0 AND L = 0 THEN
  109. REM "A$ = TIME$"
  110. REM N$(0) = I$
  111. REM PRINT "NO PARAMETERS"
  112. REM SAVE CLEANED FUNCTION NAME
  113. F$ = I$
  114. RETURN ' DONE
  115. END IF
  116. REM "...(...)"
  117. REM R > L AND L > 0
  118. REM SAVE CLEANED FUNCTION NAME
  119. F$ = LEFT$( I$, L-1 )
  120. F$ = TRIM$( F$ )
  121. REM PRINT "F$=[";F$;"]"
  122. I$ = MID$( I$, L+1, R-L-1 )
  123. REM PRINT "I$=[";I$;"]"
  124. I$ = TRIM$( I$ )
  125. REM PRINT "I$=[";I$;"]"
  126. IF LEN( I$ ) = 0 THEN RETURN ' N = POS()
  127. P$ = ""
  128. FOR I = 1 TO LEN( I$ )
  129. C$ = MID$( I$, I, 1 )
  130. REM PRINT "C$=[";C$;"]"
  131. IF C$ = "," THEN
  132. GOSUB 3000 ' DetermineTypeInP$
  133. P$ = ""
  134. ELSE
  135. P$ = P$ + C$
  136. END IF
  137. NEXT I
  138. GOSUB 3000 ' DetermineTypeInP$
  139. RETURN
  140. 3000 REM DetermineTypeInP$
  141. REM ------------------------------------------------------------
  142. REM DETERMINE THE TYPE IN P$
  143. REM ------------------------------------------------------------
  144. P$ = TRIM$( P$ )
  145. REM PRINT "P$=[";P$;"]"
  146. IF LEN( P$ ) = 0 THEN RETURN
  147. N$(N) = P$
  148. T(N) = SGN( INSTR( P$, "$" ) )
  149. N = N + 1
  150. RETURN
  151. 4000 REM DetermineUniqueID
  152. REM ------------------------------------------------------------
  153. REM DETERMINE THE UNIQUEID USING NS() AND T()
  154. REM ------------------------------------------------------------
  155. IF N <= 0 THEN RETURN
  156. U$ = "F_" + F$
  157. FOR I = 1 TO N - 1
  158. U$ = U$ + "_" + N$(I)
  159. NEXT I
  160. U$ = U$ + "_" + N$(0)
  161. REM PRINT "U$=[";U$;"]"
  162. REM REMOVE "$"
  163. J = LEN(U$)
  164. I$ = ""
  165. FOR I = 1 TO J
  166. C$ = MID$(U$,I,1)
  167. IF C$ = "$" THEN
  168. REM REMOVE
  169. ELSE
  170. I$ = I$ + C$
  171. END IF
  172. NEXT I
  173. U$ = I$
  174. REM PRINT "U$=[";U$;"]"
  175. RETURN
  176. 4500 REM LoadRandomValues
  177. REM ------------------------------------------------------------
  178. REM LOAD RANDOM VALUES
  179. REM ------------------------------------------------------------
  180. FOR I = 1 TO 100
  181. IF I < 25 THEN
  182. RN(I) = RND * 1.0 - 0.5
  183. ELSEIF I < 50 THEN
  184. RN(I) = RND * 255 - 128
  185. ELSEIF I < 75 THEN
  186. RN(I) = RND * 64535 - 32768
  187. ELSE
  188. RN(I) = RND * 10000000000 - 5000000000
  189. END IF
  190. K = 0
  191. WHILE K < 35 OR K > 126
  192. K = RND * 128
  193. WEND
  194. RS$(I) = SPACE$( RND * 5 ) + STRING$( RND * 5, K ) + SPACE$( RND * 5 )
  195. NEXT I
  196. REM CERTAIN VALUES THAT SHOULD ALWAYS BE CHECKED
  197. RN(1) = 0
  198. RN(2) = 1
  199. RN(3) = -1
  200. RN(4) = 0.4
  201. RN(5) = -0.4
  202. RN(6) = 0.6
  203. RN(7) = -0.6
  204. RN(8) = 254
  205. RN(9) = 255
  206. RN(10) = 256
  207. RN(11) = 32000
  208. RS$(1) = ""
  209. RS$(2) = " "
  210. RS$(3) = "3"
  211. RS$(4) = "z"
  212. RS$(5) = " "
  213. RS$(6) = " 3"
  214. RS$(7) = " z"
  215. RS$(8) = "3 "
  216. RS$(9) = "z "
  217. RS$(10) = " 3 "
  218. RS$(11) = " z "
  219. RETURN
  220. 5000 REM DumpResults
  221. REM ------------------------------------------------------------
  222. REM DUMP RESULTS
  223. REM ------------------------------------------------------------
  224. REM
  225. REM THE FOLLOWING FUNCTIONS SHOULD NOT BE AUTOMATED
  226. REM FOR VARIOUS REASONS
  227. REM
  228. IF N <= 0 THEN
  229. REM ERROR
  230. RETURN
  231. END IF
  232. IF INSTR( F$, " " ) THEN
  233. REM TESTCSE NOT POSSIBLE, INTERNAL FUNCTIONS
  234. REM such as "DEF FN"
  235. RETURN
  236. END IF
  237. IF N = 1 THEN
  238. REM MANUAL TESTCASE REQUIRED, NO PARAMETERS
  239. REM such as DATE$, TIME$, TIMER
  240. RETURN
  241. END IF
  242. IF INSTR(".CLOSE.EOF.GET.INPUT$.LOC.LOF.OPEN.PUT.RESET.", "." + F$ + ".") > 0 THEN
  243. REM MANUAL TESTCASE REQUIRED, FILE RELATIED
  244. RETURN
  245. END IF
  246. IF INSTR(".CHDIR.FILES.KILL.MKDIR.NAME.RMDIR.", "." + F$ + ".") > 0 THEN
  247. REM MANUAL TESTCASE REQUIRED, DIRECTORY RELATED
  248. RETURN
  249. END IF
  250. IF INSTR(".COMMAND$.ENVIRON.ENVIRON$.SHELL.", "." + F$ + ".") > 0 THEN
  251. REM MANUAL TESTCASE REQUIRED, SYSTEM RELATED
  252. RETURN
  253. END IF
  254. IF INSTR(".INP.OUT.PEEK.POKE.WAIT.", "." + F$ + ".") > 0 THEN
  255. REM MANUAL TESTCASE REQUIRED, HARDWARE RELAATED
  256. RETURN
  257. END IF
  258. IF INSTR(".COLOR.INKEY$.LOCATE.LPOS.LWIDTH.POS.WIDTH.", "." + F$ + ".") > 0 THEN
  259. REM MANUAL TESTCASE REQUIRED, SCREEN or PRINTER
  260. RETURN
  261. END IF
  262. IF INSTR(".MKC$.MKD$.MKI$.MKL$.MKS$.", "." + F$ + ".") > 0 THEN
  263. REM MANUAL TESTCASE REQUIRED, MK*
  264. RETURN
  265. END IF
  266. IF INSTR(".MOD.OPTION.", "." + F$ + ".") > 0 THEN
  267. REM MANUAL TESTCASE REQUIRED, MISCELLANEOUS
  268. RETURN
  269. END IF
  270. IF INSTR(".RANDOMIZE.RND.SPC.TAB.", "." + F$ + ".") > 0 THEN
  271. REM NO TESTCASE REQUIRED, TESTED BY P###.BAS
  272. RETURN
  273. END IF
  274. REM
  275. REM GENERATE TESTCASE
  276. REM
  277. LET X$ = U$ + ".BAS"
  278. PRINT X$
  279. OPEN X$ FOR OUTPUT AS #3
  280. PRINT #3, "REM ------------------------------------------------------------"
  281. PRINT #3, "REM PURPOSE: TEST THE PARAMETER RANGE CHECKS"
  282. PRINT #3, "REM AUTHOR: HOWARD WULF, AF5NE"
  283. PRINT #3, "REM GENERATED: ";DATE$;" ";TIME$
  284. PRINT #3, "REM FILENAME: ";X$
  285. PRINT #3, "REM SYNTAX: ";Z$
  286. PRINT #3, "REM UNIQUEID: ";U$
  287. PRINT #3, "REM FUNCTION: ";F$
  288. REM ------------------------------------------------------------
  289. REM HAS PARAMETERS
  290. REM N > 1
  291. PRINT #3, "REM "
  292. PRINT #3, "REM","VARIABLE","DESCRIPTION"
  293. PRINT #3, "REM","I" ,"CURRENT TESTCASE NUMBER"
  294. PRINT #3, "REM","E" ,"EXPECTED ERROR FLAG"
  295. PRINT #3, "REM","F" ,"ACTUAL ERROR FLAG"
  296. IF T(0) = 0 THEN
  297. PRINT #3, "REM","R" ,"EXPECTED FUNCTION RESULT"
  298. ELSE
  299. PRINT #3, "REM","R$" ,"EXPECTED FUNCTION RESULT"
  300. END IF
  301. FOR I = 0 TO N - 1
  302. IF I = 0 THEN
  303. PRINT #3, "REM",N$(I),"ACTUAL FUNCTION RESULT"
  304. ELSE
  305. PRINT #3, "REM",N$(I),"ACTUAL FUNCTION PARAMETER"
  306. END IF
  307. NEXT I
  308. PRINT #3, "REM "
  309. REM GENERATE TESTS
  310. Q$ = CHR$(34)
  311. PRINT #3, "RESTORE 2000"
  312. PRINT #3, "REM GET TESTCASE #"
  313. PRINT #3, "READ I"
  314. PRINT #3, "WHILE I > 0"
  315. PRINT #3, "REM GET TESTCASE DATA"
  316. PRINT #3, "READ E, ";
  317. IF T(0) = 0 THEN
  318. PRINT #3, "R";
  319. ELSE
  320. PRINT #3, "R$";
  321. END IF
  322. FOR J = 1 TO N - 1
  323. PRINT #3, ", ";
  324. PRINT #3, N$(J);
  325. NEXT J
  326. PRINT #3, ""
  327. PRINT #3, "REM DISPLAY TESTCASE DATA"
  328. PRINT #3, "PRINT ";Q$;"TESTCASE #";Q$;";I,";
  329. PRINT #3, Q$;"E=";Q$;";E,";
  330. IF T(0) = 0 THEN
  331. PRINT #3, Q$;"R=";Q$;";R";
  332. ELSE
  333. PRINT #3, Q$;"R$=[";Q$;";R$;";Q$;"]";Q$;
  334. END IF
  335. FOR J = 1 TO N - 1
  336. PRINT #3, ", ";
  337. IF T(J) = 0 THEN
  338. PRINT #3, Q$;N$(J);"=";Q$;";";N$(J);
  339. ELSE
  340. PRINT #3, Q$;N$(J);"=[";Q$;";";N$(J);";";Q$;"]";Q$;
  341. END IF
  342. NEXT J
  343. PRINT #3, ""
  344. PRINT #3, "REM EXECUTE TESTCASE"
  345. PRINT #3, "N = ";0
  346. PRINT #3, "S$ = ";Q$;Q$
  347. PRINT #3, "ON ERROR GOTO 9000"
  348. PRINT #3, "F = 0"
  349. PRINT #3, "999 ";Z$
  350. PRINT #3, "ERROR 0"
  351. PRINT #3, "REM DISPLAY TESTCASE RESULTS"
  352. PRINT #3, "PRINT ,";Q$;"F=";Q$;";F,";
  353. IF T(0) = 0 THEN
  354. PRINT #3, Q$;N$(0);"=";Q$;";";N$(0)
  355. ELSE
  356. PRINT #3, Q$;N$(0);"=[";Q$;";";N$(0);";";Q$;"]";Q$
  357. END IF
  358. PRINT #3, "REM VERIFY EXPECTED ERROR"
  359. PRINT #3, "IF E <> F THEN"
  360. PRINT #3, " PRINT ";Q$;"*** TEST FAILED, EXCEPTION MISMATCH ***";Q$
  361. PRINT #3, " STOP"
  362. PRINT #3, "END IF"
  363. PRINT #3, "REM VERIFY EXPECTED RESULT"
  364. IF T(0) = 0 THEN
  365. PRINT #3, "IF R > 0 THEN"
  366. PRINT #3, " LET RMIN = 0.99 * R"
  367. PRINT #3, " IF R > MAXNUM / 1.012 THEN"
  368. PRINT #3, " LET RMAX = MAXNUM"
  369. PRINT #3, " ELSE"
  370. PRINT #3, " LET RMAX = 1.01 * R"
  371. PRINT #3, " END IF"
  372. PRINT #3, "END IF"
  373. PRINT #3, "IF R < 0 THEN"
  374. PRINT #3, " IF R < - MAXNUM / 1.012 THEN"
  375. PRINT #3, " LET RMIN = -MAXNUM"
  376. PRINT #3, " ELSE"
  377. PRINT #3, " LET RMIN = 1.01 * R"
  378. PRINT #3, " END IF"
  379. PRINT #3, " LET RMAX = 0.99 * R"
  380. PRINT #3, "END IF"
  381. PRINT #3, "IF R = 0 THEN"
  382. PRINT #3, " LET RMIN = -.01"
  383. PRINT #3, " LET RMAX = +.01"
  384. PRINT #3, "END IF"
  385. PRINT #3, "IF ";N$(0);" < RMIN THEN"
  386. PRINT #3, " PRINT ";Q$;"*** TEST FAILED, RESULT MISMATCH ***";Q$
  387. PRINT #3, " STOP"
  388. PRINT #3, "END IF"
  389. PRINT #3, "IF ";N$(0);" > RMAX THEN"
  390. PRINT #3, " PRINT ";Q$;"*** TEST FAILED, RESULT MISMATCH ***";Q$
  391. PRINT #3, " STOP"
  392. PRINT #3, "END IF"
  393. ELSE
  394. PRINT #3, "IF R$ <> ";N$(0);" THEN"
  395. PRINT #3, " PRINT ";Q$;"*** TEST FAILED, RESULT MISMATCH ***";Q$
  396. PRINT #3, " STOP"
  397. PRINT #3, "END IF"
  398. END IF
  399. PRINT #3, "PRINT ";Q$;"*** TEST PASSED ***";Q$
  400. PRINT #3, "REM GET NEXT TESTCASE #"
  401. PRINT #3, "READ I"
  402. PRINT #3, "WEND"
  403. PRINT #3, "PRINT ";Q$;"*** ALL TESTS PASSED ***";Q$
  404. PRINT #3, "GOTO 9999"
  405. PRINT #3, "1999 REM TESTCASE, EXPECTED ERROR, EXPECTED RESULT, PARAMETERS..."
  406. FOR I = 1 TO 100
  407. REM ------------------------------------------------------------
  408. REM CREATE MERGE FILE
  409. REM ------------------------------------------------------------
  410. OPEN "SYNTAX.MRG" FOR OUTPUT AS #2
  411. PRINT #2, "6000 REM MERGE START";I
  412. REM PRINT #2, "6010 PRINT ";Q$;"BEFORE ERROR";Q$
  413. REM PRINT #2, "6020 ERROR 12"
  414. REM PRINT #2, "6030 PRINT ";Q$;"AFTER ERROR";Q$
  415. REM PRINT #2, "6040 RETURN"
  416. REM PRINT #2, "6050 PRINT ";Q$;"AFTER RETURN";Q$
  417. FOR J = 1 TO N - 1
  418. IF T(J) = 0 THEN
  419. K = RN(I)
  420. PRINT #2, "LET ";N$(J);" = ";K
  421. V(J) = K
  422. ELSE
  423. K$ = RS$(I)
  424. PRINT #2, "LET ";N$(J);" = ";Q$;K$;Q$
  425. V$(J) = K$
  426. END IF
  427. NEXT J
  428. PRINT #2, "6010 LET V";Z$
  429. REM PRINT #2, "6098 PRINT ";Q$;"BEFORE STOP";Q$
  430. PRINT #2, "6099 REM MERGE STOP";I
  431. CLOSE #2
  432. REM EXECUTE MERGED FILE
  433. DELETE 6000-6099
  434. MERGE "SYNTAX.MRG"
  435. REM LIST 5999-6999
  436. LET E = 0
  437. LET VN = 0
  438. LET VS$ = ""
  439. REM TRON
  440. ON ERROR RESUME NEXT
  441. GOSUB 6000
  442. REM TROFF
  443. REM DTERMINE ERROR FLAG
  444. LET E = ABS(SGN(ERR))
  445. REM CLEAR ERR, ERL, ERROR$
  446. ERROR 0
  447. ON ERROR GOTO 0
  448. REM REPORT RESULTS
  449. REM TESTCASE NUMBER, EXPECTED ERROR
  450. PRINT #3, "DATA ";I;", ";E;", ";
  451. REM EXPECTED RESULT
  452. IF T(0) = 0 THEN
  453. PRINT #3, VN;
  454. ELSE
  455. PRINT #3, Q$;VS$;Q$;
  456. END IF
  457. REM ACTUAL PARAMETERS
  458. FOR J = 1 TO N - 1
  459. PRINT #3, ", ";
  460. IF T(J) = 0 THEN
  461. PRINT #3, V(J);
  462. ELSE
  463. PRINT #3, Q$;V$(J);Q$;
  464. END IF
  465. NEXT J
  466. PRINT #3, ""
  467. NEXT I
  468. PRINT #3, "DATA 0"
  469. PRINT #3, "9000 REM ERROR HANDLER"
  470. PRINT #3, "IF ERL = 999 THEN"
  471. PRINT #3, " F = ABS(SGN(ERR))"
  472. PRINT #3, " RESUME NEXT"
  473. PRINT #3, "END IF"
  474. PRINT #3, "PRINT ";Q$;"*** UNEXPECTED ERROR ON LINE ";Q$;";ERL;";Q$;" ***";Q$
  475. PRINT #3, "9999 END"
  476. CLOSE #3
  477. RETURN
  478. 5999 REM BOUNDARY A
  479. 6000 REM MERGE START 0
  480. 6099 REM MERGE STOP 0
  481. 6100 RETURN
  482. 6999 REM BOUNDARY B
  483. REM ------------------------------------------------------------
  484. REM EOF
  485. REM ------------------------------------------------------------
  486. 9999 END