-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest-runner-test.red
174 lines (160 loc) · 4.14 KB
/
test-runner-test.red
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
Red [
description: {Tests for the test runner}
author: loziniak
]
metatests: [
[ ;-- Test report structure and proper output interception
"hello-world"
%test/input/
%test/output/
#[
version: 3
status: "fail"
message: #(none)
tests: [#[
name: "Say Hi!"
status: "fail"
message: {FAILED. Expected: "Hello, World!", but got "Hello, Universe!"}
output: {"debug"^/debugging^/}
test_code: {[expect "Hello, World!" [hello]]}
] #[
name: "Say Hi!"
status: "pass"
message: #(none)
output: {"debug"^/debugging^/}
test_code: {[expect "Hello, Universe!" [hello]]}
]]
]
]
[ ;-- Test output leakage and task IDs
"hello-world2"
%test/input/
%test/output/
#[
version: 3
status: "fail"
message: #(none)
tests: [#[
name: "Say Hi!"
status: "pass"
message: #(none)
output: {"debug"^/debugging^/"INTERNAL_OUTPUT"^/}
test_code: {[expect "Hello, Universe!" [hello]]}
task_id: 1
] #[
name: "Say Hi!"
status: "fail"
message: {FAILED. Expected: "Hello, World!", but got "Hello, Universe!"}
output: {"debug"^/debugging^/"INTERNAL_OUTPUT"^/}
test_code: {[expect "Hello, World!" [hello]]}
task_id: 2
]]
]
]
[ ;-- Test solution errors interception and reporting
"hello-world3"
%test/input/
%test/output/
#[
version: 3
status: "fail"
message: #(none)
tests: [#[
name: "Say Hi!"
status: "error"
message: {*** Math Error: attempt to divide by zero^/*** Where: do^/*** Near : print 1 / 0 "Hello, Universe!"^/*** Stack: do-file exercism-results-from last expect hello }
output: #(none)
test_code: {[expect "Hello, World!" [hello]]}
]]
]
]
[ ;-- Test missing test files and, test framework errors reporting in general
"hello-world4"
%test/input/
%test/output/
#[
version: 3
status: "error"
message: {*** Access Error: cannot open: %hello-world4-test.red^/*** Where: read^/*** Near : code: load test-file remove find/last/only ^/*** Stack: do-file exercism-results-from }
tests: []
]
]
[ ;-- Test output leakage and error reporting
"hello-world5"
%test/input/
%test/output/
#[
version: 3
status: "fail"
message: #(none)
tests: [#[
name: "Say Hi!"
status: "error"
message: {*** Script Error: output has no value^/*** Where: append^/*** Near : reduce [form :value #"^^/"] return ()^/*** Stack: do-file exercism-results-from last expect hello }
output: "debugging^/"
test_code: {[expect "Hello, World!" [hello]]}
] #[
name: "Say Hi!"
status: "error"
message: {*** Script Error: output has no value^/*** Where: append^/*** Near : reduce [form :value #"^^/"] return ()^/*** Stack: do-file exercism-results-from last expect hello }
output: "debugging^/"
test_code: {[expect "Hello, Universe!" [hello]]}
]]
]
]
[ ;-- Test if test runner accepts paths without trailing slashes as well
"hello-world6"
%test/input ;-- trailing slashes omitted intentionally, as this is what's being tested
%test/output ;-- trailing slashes omitted intentionally, as this is what's being tested
#[
version: 3
status: "fail"
message: #(none)
tests: [#[
name: "Say Hi!"
status: "fail"
message: {FAILED. Expected: "Hello, World!", but got "Hello, Universe!"}
output: {"debug"^/debugging^/}
test_code: {[expect "Hello, World!" [hello]]}
] #[
name: "Say Hi!"
status: "pass"
message: #(none)
output: {"debug"^/debugging^/}
test_code: {[expect "Hello, Universe!" [hello]]}
]]
]
]
]
pass?: true
foreach metatest metatests [
print ["^/" metatest/1 " ..."]
trial: try [
do/args %test-runner.red rejoin [
{"} metatest/1 {" "} metatest/2 {" "} metatest/3 {"}
] ;; TODO: use 'call'?
results: load-json read %test/output/results.json
delete %test/output/results.json
either results = metatest/4 [
print "OK"
true
] [
print ["FAIL. Expected:^/" mold metatest/4 "^/but got:^/" mold results]
false
]
]
if error? trial [
print trial
pass?: false
]
pass?: all [
pass?
trial
]
unset 'results
]
either pass? [
print "^/ALL TESTS OK."
] [
quit/return 1 ; TODO: https://github.com/red/red/issues/4095
]