-
Notifications
You must be signed in to change notification settings - Fork 5
/
Test.rb
80 lines (67 loc) · 1.59 KB
/
Test.rb
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
module Test
$testnum = 1
$failed = 0
$planned = 0
$started = 0
$todo_upto = 0
$todo_reason
def plan(num)
print '1..',num,"\n"
$started = 1
$testnum = 1
$todo_upto = 0
$failed = 0
$planned = num
end
def pass(desc='')
proclaim(1,desc)
end
def flunk(desc='')
proclaim(0,desc)
end
def ok(cond,desc='')
proclaim(cond, desc)
end
def nok(cond,desc='')
if cond then
flunk desc
else
pass desc
end
end
def is(got,expected,desc='')
proclaim(got == expected, desc)
end
def isgt(got,expected,desc='')
proclaim(got > expected, desc)
end
def isge(got,expected,desc='')
proclaim(got >= expected, desc)
end
def isnt(got,expected,desc='')
proclaim(got != expected, desc)
end
def todo(reason,issue="",count=1)
$todo_upto = $testnum + count
$todo_reason = " # TODO #{reason} See issue ##{issue}."
end
def skip(reason='',issue="",count=1)
1.upto(count) { flunk("# SKIP #{reason} See issue ##{issue}.") }
end
def skip_rest(reason='',issue="")
skip(reason,issue,$planned - $testnum + 1)
end
def proclaim(cond,desc)
if cond then
else
print "not "
$failed += 1 if $todo_upto < $testnum
end
print 'ok ', $testnum, ' - ', desc
$testnum += 1
if $todo_reason and $todo_upto >= $testnum then
print $todo_reason
end
puts
end
end