Skip to content

Commit f2ad16e

Browse files
authored
Merge pull request #5 from nomennescio/feature-with-passed-failed
Add with-passed, with-failed, and with-passed-failed for custom error messages
2 parents 2eaa66b + cba1e00 commit f2ad16e

File tree

6 files changed

+160
-6
lines changed

6 files changed

+160
-6
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 nomennescio
3+
Copyright (c) 2019-2022 nomennescio
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

test/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ Simple tests to verify the Factor Testest framework is still working
33
Run all tests by executing
44
run-tests.py
55

6+
Requires Python 2 or 3 and Factor to be in your PATH
7+
68
To show more verbose output, use -v, to show less verbose output, use -q

test/run-tests.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#!/usr/bin/env python
2-
# Copyright 2019 nomennescio
2+
# Copyright 2019-2022 nomennescio
33

44
import glob, os, re, sys
55

66
passed, failed, verbose, quiet = 0, 0, 0, 0
77

8+
# run Factor on source code file
89
def run (factorfile):
910
return os.popen ("bash -c 'FACTOR_ROOTS=`pwd`/.. factor " + factorfile + "'").readlines ()
1011

12+
# remove timing information
1113
def timeless (lines):
1214
return [re.sub(r'\d+', '0', l) if "<COMPLETEDIN::>" in l else l for l in lines]
1315

16+
# test single Factor source code file
1417
def test (filename):
1518
global passed, failed
1619
actual = run (filename)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
<DESCRIBE::>custom message
3+
4+
<IT::>short strings
5+
6+
<PASSED::>Just passed
7+
8+
<PASSED::>Just passed
9+
10+
<COMPLETEDIN::>0.066171 ms
11+
12+
<IT::>failing compares
13+
14+
<FAILED::>Just failed
15+
16+
<FAILED::>Just failed
17+
18+
<COMPLETEDIN::>0.057857 ms
19+
20+
<IT::>short strings
21+
22+
<PASSED::>Test passed
23+
24+
<PASSED::>Test passed
25+
26+
<COMPLETEDIN::>0.018855 ms
27+
28+
<IT::>failing compares
29+
30+
<FAILED::>Expected :<:LF:>"Hello Worlds!"<:LF:>but got :<:LF:>"Hello World!"
31+
32+
<FAILED::>Expected :<:LF:>"Hello Worlds! "<:LF:>but got :<:LF:>"Hello Worlds!"
33+
34+
<COMPLETEDIN::>0.131308 ms
35+
36+
<IT::>short strings
37+
38+
<PASSED::>Test Passed
39+
40+
<PASSED::>Test Passed
41+
42+
<COMPLETEDIN::>0.019944 ms
43+
44+
<IT::>failing compares
45+
46+
<FAILED::>Test Failed : Expected :<:LF:>"Hello Worlds!"<:LF:>but got :<:LF:>"Hello World!"
47+
48+
<FAILED::>Test Failed : Expected :<:LF:>"Hello Worlds! "<:LF:>but got :<:LF:>"Hello Worlds!"
49+
50+
<COMPLETEDIN::>0.060291 ms
51+
52+
<COMPLETEDIN::>0.540606 ms
53+
54+
<DESCRIBE::>nested custom messages
55+
56+
<IT::>short strings
57+
58+
<PASSED::>Passed 1
59+
60+
<PASSED::>Passed 2
61+
62+
<COMPLETEDIN::>0.031492 ms
63+
64+
<IT::>failing compares
65+
66+
<FAILED::>Test failed A Expected :<:LF:>"Hello Worlds!"<:LF:>but got :<:LF:>"Hello World!"
67+
68+
<FAILED::>Test failed A Expected :<:LF:>"Hello Worlds! "<:LF:>but got :<:LF:>"Hello Worlds!"
69+
70+
<COMPLETEDIN::>0.044357 ms
71+
72+
<IT::>short strings
73+
74+
<PASSED::>Test passed B
75+
76+
<PASSED::>Test passed B
77+
78+
<COMPLETEDIN::>0.018118 ms
79+
80+
<IT::>failing compares
81+
82+
<FAILED::>Failed 3
83+
84+
<FAILED::>Failed 4
85+
86+
<COMPLETEDIN::>0.035839 ms
87+
88+
<COMPLETEDIN::>0.151897 ms
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
! Copyright 2022 nomennescio
2+
3+
USING: accessors debugger io kernel namespaces sequences tools.testest ;
4+
IN: tests
5+
6+
: pass1 ( -- ) <{ "Hello World!" -> "Hello World!" }> ;
7+
: pass2 ( -- ) <{ "Hello Worlds!" -> "Hello Worlds!" }> ;
8+
: fail1 ( -- ) <{ "Hello World!" -> "Hello Worlds!" }> ;
9+
: fail2 ( -- ) <{ "Hello Worlds!" -> "Hello Worlds! " }> ;
10+
11+
: run-test ( -- )
12+
"short strings" it#{ pass1 pass2 }#
13+
"failing compares" it#{ fail1 fail2 }#
14+
;
15+
16+
: custom1 ( -- ) [ "Just passed" write ] [ "Just failed" write drop ] [ run-test ] with-passed-failed ;
17+
: custom2 ( -- ) [ "Test passed" write ] [ error. ] [ run-test ] with-passed-failed ;
18+
: custom3 ( -- ) run-test ;
19+
20+
: run-tests ( -- )
21+
22+
"custom message" describe#{
23+
custom1
24+
custom2
25+
custom3
26+
}#
27+
28+
"nested custom messages" describe#{
29+
30+
[ "Test passed A" write ] [ "Test failed A " write error. ] [
31+
"short strings" it#{
32+
[ "Passed 1" write ] [ pass1 ] with-passed
33+
[ "Passed 2" write ] [ pass2 ] with-passed
34+
}#
35+
36+
"failing compares" it#{
37+
[ "Passed 3" write ] [ fail1 ] with-passed
38+
[ "Passed 4" write ] [ fail2 ] with-passed
39+
}#
40+
] with-passed-failed
41+
42+
[ "Test passed B" write ] [ "Test failed B " write error. ] [
43+
"short strings" it#{
44+
[ "Failed 1" write drop ] [ pass1 ] with-failed
45+
[ "Failed 2" write drop ] [ pass2 ] with-failed
46+
}#
47+
48+
"failing compares" it#{
49+
[ "Failed 3" write drop ] [ fail1 ] with-failed
50+
[ "Failed 4" write drop ] [ fail2 ] with-failed
51+
}#
52+
] with-passed-failed
53+
54+
}#
55+
;
56+
57+
MAIN: run-tests

tools/testest/testest.factor

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
! Copyright 2019 nomennescio
1+
! Copyright 2019-2022 nomennescio
22

3-
USING: accessors continuations debugger formatting io io.styles kernel locals math namespaces
4-
parser prettyprint prettyprint.config quotations sequences system ;
3+
USING: accessors continuations debugger formatting fry io io.styles kernel locals math
4+
namespaces parser prettyprint prettyprint.config quotations sequences system ;
55
IN: tools.testest
66

77
: describe#{ ( description -- starttime ) nl "<DESCRIBE::>%s" printf nl nano-count ;
@@ -22,14 +22,18 @@ IN: tools.testest
2222
] each
2323
;
2424

25-
! user redefinable test result messages
25+
! user redefinable test result message quotations
2626

2727
SYMBOL: test-passed.
2828
SYMBOL: test-failed.
2929

3030
[ "Test Passed" write ] test-passed. set-global
3131
[ "Test Failed : " write error. ] test-failed. set-global
3232

33+
: with-passed ( passed quot -- ) '[ _ test-passed. set @ ] with-scope ; inline
34+
: with-failed ( failed quot -- ) '[ _ test-failed. set @ ] with-scope ; inline
35+
: with-passed-failed ( passed failed quot -- ) '[ _ test-passed. set _ test-failed. set @ ] with-scope ; inline
36+
3337
<PRIVATE
3438

3539
: passed. ( -- ) test-passed. get call( -- ) ; inline

0 commit comments

Comments
 (0)