This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy path_testlib.livecodescript
More file actions
129 lines (102 loc) · 3.78 KB
/
Copy path_testlib.livecodescript
File metadata and controls
129 lines (102 loc) · 3.78 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
script "TestLibrary"
/*
Copyright (C) 2015 LiveCode 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/>. */
----------------------------------------------------------------
-- Helper functions
----------------------------------------------------------------
private function _TestValidateDescription pDescription
if the number of lines in pDescription > 1 then
throw "Bad test description '" & line 1 of pDescription & "...': multiple lines"
end if
if "0123456789" contains codepoint 1 of pDescription then
throw "Bad test description '" & pDescription & "': starts with digit"
end if
if pDescription contains "#" then
throw "Bad test description '" & pDescription & "': contains '#'"
end if
return line 1 of pDescription
end _TestValidateDescription
private function _TestValidateReason pReason
if the number of lines in pReason > 1 then
throw "Bad test directive reason '" & line 1 of pReason & "...': multiple lines"
end if
if pReason contains "#" then
throw "Bad test directive reason '" & pReason & "': contains '#'"
end if
return line 1 of pReason
end _TestValidateReason
private function _TestValidateDirective pDirective
switch pDirective
case empty
return empty
case "TODO"
return "TODO"
case "SKIP"
return "SKIP"
default
throw "Bad test directive '" & line 1 of pDirective & "'"
end switch
end _TestValidateDirective
-- Used by top level assertion functions to generate output
private command _TestOutput pIsOkay, pDescription, pDirective, pReason
local tDescription, tDirective, tReason
put _TestValidateDescription(pDescription) into tDescription
put _TestValidateDirective(pDirective) into tDirective
put _TestValidateReason(pReason) into tReason
local tMessage
if pIsOkay then
put "ok" into tMessage
else
put "not ok" into tMessage
end if
if tDescription is not empty then
put " - " & tDEscription after tMessage
end if
if tDirective is not empty then
put " # " & tDirective after tMessage
if tReason is not empty then
put " " & tReason after tMessage
end if
end if
write tMessage & return to stdout
end _TestOutput
----------------------------------------------------------------
-- Unit test library functions
----------------------------------------------------------------
on TestDiagnostic pMessage
local tLine
repeat for each line tLine in pMessage
write "#" && tLine & return to stdout
end repeat
end TestDiagnostic
on TestSkip pDescription, pReasonSkipped
_TestOutput true, pDescription, "SKIP", pReasonSkipped
end TestSkip
on TestAssert pDescription, pExpectTrue
_TestOutput pExpectTrue, pDescription, empty, empty
end TestAssert
on TestAssertBroken pDescription, pExpectTrue, pReasonBroken
_TestOutput pExpectTrue, pDescription, "TODO", pReasonBroken
end TestAssertBroken
on TestAssertThrow pDescription, pHandler, pTarget, pErrorCode
local tError
try
dispatch pHandler to pTarget
catch tError
end try
TestAssert pDescription, pErrorCode is item 1 of line 1 of tError
end TestAssertThrow
on ErrorDialog executionError, parseError
write executionError & return to stderr
quit 1
end ErrorDialog