-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.lua
More file actions
160 lines (138 loc) · 2.61 KB
/
Copy pathtest.lua
File metadata and controls
160 lines (138 loc) · 2.61 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
local event=require("event")
local test={}
local total=0
local pass=0
local errors=0
local lastTest
local log, err=io.open("log.txt", "wb")
if not log then
error(err)
end
local function passed()
pass=pass + 1
lastTest=true
local _, err=pcall(error, "Test Passed", 5)
log:write(err .. "\n")
log:flush()
end
local function failed()
lastTest=false
local _, err=pcall(error, "Test Failed", 5)
log:write(err .. "\n")
log:flush()
end
local function errored()
errors=errors + 1
lastTest=false
local _, err=pcall(error, "Test Errored", 5)
log:write(err .. "\n")
log:flush()
end
function test.evaluate(something, ...)
total=total + 1
local ok, val=pcall(...);
if ok then
((val == something) and passed or failed)()
else
errored()
end
end
function test.compare(something, another)
total=total + 1
((something == another) and passed or failed)()
end
function test.shouldError(...)
total=total + 1
((not pcall(...)) and passed or failed)()
end
function test.shouldNotError(...)
total=total + 1
((pcall(...)) and passed or failed)()
end
function test.typeMatch(types, ...)
total=total + 1
local good=true
local results=table.pack(pcall(...))
if not results[1] then
errored()
else
if results.n - 1 == #types then
for i=1, #types do
if type(results[i + 1]) ~= types[i] then
good=false
break
end
end
else
good=false
end
(good and passed or failed)()
end
end
function test.valueMatch(values, ...)
total=total + 1
local good=true
local results=table.pack(pcall(...))
if not results[1] then
errored()
else
if results.n - 1 == values.n then
for i=1, values.n do
if results[i + 1] ~= values[i] then
good=false
break
end
end
else
good=false
end
(good and passed or failed)()
end
end
function test.pause()
while select(3, event.pull("key_down")) ~= 13 do end
end
function test.input()
while true do
local code=select(4, event.pull("key_down"))
if code == 49 then -- N
return false
elseif code == 21 then -- Y
return true
end
end
end
function test.getTotal()
if log then
log:write(string.format("%d tests, %d passed, %d failed, %d errors\n", total, pass, total - pass - errors, errors))
log:close()
log=nil
end
return total
end
function test.getPassed()
return pass
end
function test.getFailed()
return total - pass - errors
end
function test.getErrors()
return errors
end
function test.getLast()
return lastTest
end
function test.log(message)
if log then
log:write(message .. "\n")
log:flush()
end
end
function test.logp(message)
print(message)
if log then
log:write(message .. "\n")
log:flush()
end
end
return test