-
Notifications
You must be signed in to change notification settings - Fork 0
/
fbtesting.bas
80 lines (68 loc) · 2.23 KB
/
fbtesting.bas
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
#include "fbtesting.bi"
namespace fbtesting
function StateString(byval result as const TestResult) as string
select case as const result
case TestResult.Passed
return "PASS"
case TestResult.Failed
return "FAIL"
case TestResult.Skipped
return "SKIP"
end select
end function
constructor Testing (byref name_ as const string = "")
this.name = name_
end constructor
sub Testing.Test(byref c as const sub(byref t as Testing ), byref testName as const string = "")
redim preserve this.testCases(ubound(this.testCases) + 1)
redim preserve this.testNames(ubound(this.testNames) + 1)
this.testCases(ubound(this.testCases)) = c
this.testNames(ubound(this.testNames)) = testName
end sub
sub Testing.Run()
for testIndex as integer = 0 to ubound(this.testCases)
dim testName as string = this.testNames(testIndex)
if(testName = "") then testName = "Test " & testIndex+1
print "=== RUN", testName
erase this.results
this.currentState = TestResult.Passed
this.testCases(testIndex)(this)
this.isFailed = this.isFailed or this.currentState = TestResult.Failed
if this.currentState = TestResult.Failed then
for messageIndex as integer = lbound(this.results) to ubound(this.results)
print this.results(messageIndex)
next
end if
print "--- "; StateString(this.currentState), testName
next
dim numTests as uinteger = ubound(this.testCases) - lbound(this.testCases) + 1
if numTests < 1 then
print "?", this.name
elseif this.isFailed then
print "FAIL", this.name
else
print "PASS", this.name
end if
end sub
function Testing.Failed() as boolean
return this.isFailed
end function
sub Testing.Fail()
if this.currentState <> TestResult.Skipped then
this.currentState = TestResult.Failed
end if
end sub
sub Testing.Skip()
if this.currentState <> TestResult.Failed then
this.currentState = TestResult.Skipped
end if
end sub
sub Testing.Log(byref message as const string)
redim preserve this.results(ubound(this.results) + 1)
this.results(ubound(this.results)) = message
end sub
sub Testing.Error(byref message as const string)
this.log(message)
this.Fail()
end sub
end namespace