forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunittest.mlc
More file actions
182 lines (141 loc) · 5.54 KB
/
Copy pathunittest.mlc
File metadata and controls
182 lines (141 loc) · 5.54 KB
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
175
176
177
178
179
180
181
182
/*
Copyright (C) 2015 Runtime Revolution Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
/*
This library provides syntax for unit testing LiveCode Builder
programs. It is used by the LiveCode Builder standard library's
testsuite.
To use this library, write your tests in a Builder source code file.
Each group of tests should be a public handler with a name beginning
with "Test". If possible, use one test per handler. Otherwise, add a
"plan N tests" statement at the start of the handler.
Example:
public handler TestSelf()
plan 10 tests
test diagnostic "Normal tests"
test 2 > 1
test "Basic test" when true
test diagnostic "Skipped tests"
skip test
skip test "Skipped 2"
skip test because "Not implemented"
skip test "Skipped 4" because "Not supported on this platform"
test diagnostic "Tests which are expected to fail"
broken test false
broken test "Failed 2" when false
broken test false because "broken"
broken test "Failed 4" when false because "really broken"
end handler
The test results are output on standard output in TAP (Test Anything
Protocol) format.
*/
module com.livecode.unittest
public foreign handler MCUnitPlan(in pCount as Number) returns nothing binds to "lcb:com.livecode.unittest.__IMPL.MCUnitPlan"
public foreign handler MCUnitDiagnostic(in pMessage as String) returns nothing binds to "lcb:com.livecode.unittest.__IMPL.MCUnitDiagnostic"
foreign handler MCUnitOutputTest(in pCondition as Boolean, in pDescription as String, in pDirective as String, in pReason as String) returns nothing binds to "lcb:com.livecode.unittest.__IMPL.MCUnitOutputTest"
----------------------------------------------------------------
-- Test syntax
----------------------------------------------------------------
syntax UnitPlan is statement
"plan" <Count: Expression> "tests"
begin
MCUnitPlan(Count)
end syntax
syntax UnitDiagnostic is statement
"test" "diagnostic" <Message: Expression>
begin
MCUnitDiagnostic(Message)
end syntax
----------------------------------------------------------------
syntax UnitTest is statement
"test" <Condition: Expression>
begin
MCUnitTest(Condition)
end syntax
public handler MCUnitTest(in pCondition as Boolean)
MCUnitOutputTest(pCondition, "", "", "")
end handler
syntax UnitTestDescription is statement
"test" <Description: Expression> "when" <Condition: Expression>
begin
MCUnitTestDescription(Description, Condition)
end syntax
public handler MCUnitTestDescription(in pDescription as String, in pCondition as Boolean)
MCUnitOutputTest(pCondition, pDescription, "", "")
end handler
----------------------------------------------------------------
syntax UnitTestSkip is statement
"skip" "test"
begin
MCUnitTestSkip()
end syntax
public handler MCUnitTestSkip()
MCUnitOutputTest(true, "", "SKIP", "")
end handler
syntax UnitTestSkipDescription is statement
"skip" "test" <Description: Expression>
begin
MCUnitTestSkipDescription(Description)
end syntax
public handler MCUnitTestSkipDescription(in pDescription as String)
MCUnitOutputTest(true, pDescription, "SKIP", "")
end handler
syntax UnitTestSkipReason is statement
"skip" "test" "because" <Reason: Expression>
begin
MCUnitTestSkipReason(Reason)
end syntax
public handler MCUnitTestSkipReason(in pReason as String)
MCUnitOutputTest(true, "", "SKIP", pReason)
end handler
syntax UnitTestSkipDescriptionAndReason is statement
"skip" "test" <Description: Expression> "because" <Reason: Expression>
begin
MCUnitTestSkipDescriptionAndReason(Description, Reason)
end syntax
public handler MCUnitTestSkipDescriptionAndReason(in pDescription as String, in pReason as String)
MCUnitOutputTest(true, pDescription, "SKIP", pReason)
end handler
----------------------------------------------------------------
syntax UnitTestFails is statement
"broken" "test" <Condition: Expression>
begin
MCUnitTestFails(Condition)
end syntax
public handler MCUnitTestFails(in pCondition as Boolean)
MCUnitOutputTest(pCondition, "", "TODO", "")
end handler
syntax UnitTestFailsDescription is statement
"broken" "test" <Description: Expression> "when" <Condition: Expression>
begin
MCUnitTestFailsDescription(Description, Condition)
end syntax
public handler MCUnitTestFailsDescription(in pDescription as String, in pCondition as Boolean)
MCUnitOutputTest(pCondition, pDescription, "TODO", "")
end handler
syntax UnitTestFailsReason is statement
"broken" "test" <Condition: Expression> "because" <Reason: Expression>
begin
MCUnitTestFailsReason(Condition, Reason)
end syntax
public handler MCUnitTestFailsReason(in pCondition as Boolean, in pReason as String)
MCUnitOutputTest(pCondition, "", "TODO", pReason)
end handler
syntax UnitTestFailsDescriptionAndReason is statement
"broken" "test" <Description: Expression> "when" <Condition: Expression> "because" <Reason: Expression>
begin
MCUnitTestFailsDescriptionAndReason(Description, Condition, Reason)
end syntax
public handler MCUnitTestFailsDescriptionAndReason(in pDescription as String, in pCondition as Boolean, in pReason as String)
MCUnitOutputTest(pCondition, pDescription, "TODO", pReason)
end handler
end module