planckforth/lib/tester.fs

89 lines
1.6 KiB
Forth
Raw Normal View History

2021-01-11 04:07:49 +01:00
\ planckforth -
\ Copyright (C) 2021 nineties
2021-05-07 11:55:29 +02:00
\ test/tester.fs and test codes are base on
\ https://github.com/gerryjackson/forth2012-test-suite
2021-01-11 04:07:49 +01:00
variable verbose
2021-01-11 04:50:58 +01:00
\ true verbose !
false verbose !
2021-01-11 04:07:49 +01:00
: empty-stack sp0 sp! ;
2021-01-11 04:50:58 +01:00
variable #ok 0 #ok !
variable #error 0 #error !
variable #skip 0 #skip !
2021-01-11 04:07:49 +01:00
: ESC [ 0x1b ] literal ;
2021-01-11 04:50:58 +01:00
: red ESC emit ." [31m" ;
: green ESC emit ." [32m" ;
: yellow ESC emit ." [33m" ;
: reset ESC emit ." [m" ;
2021-01-11 04:07:49 +01:00
: error ( c-addr -- )
2021-01-11 04:50:58 +01:00
red type source type reset
2021-01-11 04:07:49 +01:00
empty-stack
2021-01-11 04:50:58 +01:00
1 #error +!
2021-01-11 04:07:49 +01:00
;
variable actual-depth
create actual-results 20 cells allot
: T{ ;
: -> ( save depth and contents )
depth dup actual-depth !
?dup if
0 do actual-results i cells + ! loop
then
;
: }T ( compare expected data and actual-results )
depth actual-depth @ <> if
s" wrong number of results: " error exit
then
2021-01-11 04:50:58 +01:00
true >r
2021-01-11 04:07:49 +01:00
depth ?dup if
0 do
actual-results i cells + @ <> if
2021-01-11 04:50:58 +01:00
s" incorrect result: " error
r> drop false >r
leave
2021-01-11 04:07:49 +01:00
then
loop
then
2021-01-11 04:50:58 +01:00
r> if
1 #ok +!
then
2021-01-11 04:07:49 +01:00
;
: testing
source verbose @ if
dup type
else
'.' emit
then
2022-08-18 04:01:58 +02:00
strlen >in ! \ skip this line
2021-01-11 04:07:49 +01:00
;
2021-01-11 04:50:58 +01:00
: skip
source verbose @ if
dup type
then
strlen >in ! \ skip this line
1 #skip +!
;
2021-01-11 06:33:11 +01:00
: report-and-exit
2021-01-11 04:50:58 +01:00
decimal
cr ." --------------------------------"
cr ." Run " #ok @ #error @ + #skip @ + . ." tests" cr
2021-01-11 06:33:11 +01:00
green ." ok:" #ok @ .
red ." failed:" #error @ .
yellow ." skipped:" #skip @ .
reset
2021-01-11 04:50:58 +01:00
cr ." --------------------------------"
cr
2021-01-11 06:33:11 +01:00
#error @ 0= if bye else abort then
2021-01-11 04:50:58 +01:00
;