-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert to test-words; merge sieve-test.8th and test.8th
- Loading branch information
Showing
7 changed files
with
174 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
"sieve.8th" | ||
], | ||
"test": [ | ||
"sieve-tests.8th" | ||
"test.8th" | ||
], | ||
"example": [ | ||
".meta/example.8th" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
needs console/loaded | ||
|
||
\ ----------------------------------------------------------------- | ||
|
||
ns: test | ||
|
||
-1 var, test-count | ||
var tests-passed | ||
var tests-failed | ||
var tests-skipped | ||
true var, run-test | ||
|
||
\ Some utility words | ||
: test-passed \ s -- | ||
1 tests-passed n:+! | ||
con:green con:onBlack . space " ... OK" . con:white con:onBlack cr | ||
; | ||
|
||
: test-skipped \ s -- | ||
1 tests-skipped n:+! | ||
con:cyan con:onBlack . space " ... SKIPPED" . con:white con:onBlack cr | ||
; | ||
|
||
: test-failed \ s -- | ||
1 tests-failed n:+! | ||
con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr | ||
; | ||
|
||
: isword? \ x -- x f | ||
dup >kind ns:w n:= | ||
; | ||
|
||
: run-test? \ -- T | ||
run-test @ if true else "RUN_ALL_TESTS" getenv n:>bool then | ||
; | ||
|
||
\ Num passed + num skipped + num failed should == num tests | ||
: all-tests-run? \ -- T | ||
tests-passed @ tests-skipped @ tests-failed @ n:+ n:+ | ||
test-count @ n:= | ||
; | ||
|
||
\ adapted from 8th forum | ||
: eq? \ x x -- T | ||
\ are the items the same kind? | ||
2dup >kind swap >kind n:= | ||
!if 2drop false ;then | ||
|
||
\ same kind: try different comparators | ||
number? if n:= ;then | ||
string? if s:= ;then | ||
array? if ' eq? a:= 2nip ;then | ||
map? if ' eq? m:= 2nip ;then | ||
|
||
\ otherwise fall back to 'lazy evaluation' | ||
l: = | ||
; | ||
|
||
\ ----------------------------------------------------------------- | ||
|
||
\ status report at end of run | ||
( all-tests-run? | ||
!if con:red con:onBlack "... FAIL - not all tests completed" . con:white con:onBlack cr then | ||
) onexit | ||
|
||
\ Print a summary of the tests run | ||
( con:white con:onBlack | ||
test-count @ . space "tests planned - " . | ||
tests-passed @ . space "passed - " . | ||
tests-skipped @ . space "skipped - " . | ||
tests-failed @ . space "failed" . cr | ||
) onexit | ||
|
||
\ ----------------------------------------------------------------- | ||
\ The public-facing words | ||
\ ----------------------------------------------------------------- | ||
|
||
: equal? \ s x w -- | s w x -- | ||
run-test? !if 2drop test-skipped ;; then | ||
isword? !if swap then | ||
w:exec | ||
eq? if test-passed else test-failed then | ||
; | ||
|
||
: true? \ s w -- | ||
run-test? !if drop test-skipped ;; then | ||
w:exec | ||
if test-passed else test-failed then | ||
; | ||
|
||
: false? \ s w -- | ||
run-test? !if drop test-skipped ;; then | ||
w:exec | ||
!if test-passed else test-failed then | ||
; | ||
|
||
: null? \ s w -- | ||
run-test? !if drop test-skipped ;; then | ||
w:exec | ||
G:null? nip if test-passed else test-failed then | ||
; | ||
|
||
: SKIP-REST-OF-TESTS false run-test ! ; | ||
|
||
: tests \ n -- | ||
test-count ! | ||
; | ||
|
||
\ Set the exit status: | ||
\ 0 = all OK | ||
\ 1 = not all tests were run (some error occurred) | ||
\ 2 = some tests failed | ||
: end-of-tests \ -- | ||
all-tests-run? | ||
if | ||
tests-failed @ 0 n:= if 0 else 2 then | ||
else | ||
1 | ||
then | ||
die | ||
; | ||
|
||
with: test |
Oops, something went wrong.