-
Notifications
You must be signed in to change notification settings - Fork 7
/
iospec
executable file
·135 lines (113 loc) · 2.91 KB
/
iospec
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
#!/usr/bin/env io
AssertionFailed := Exception clone
Object verify := method(
checkMessage := call argAt(0)
checkCode := call message code
if(checkMessage name == "==",
other := call sender doMessage(checkMessage argAt(0), call sender)
if(self == other,
return self
,
AssertionFailed raise(self asSimpleString .. " != " .. other asSimpleString .. ". " .. checkCode)
)
)
if(self doMessage(checkMessage, call sender),
return self
,
AssertionFailed raise(checkCode)
)
)
BodyContext := Object clone do(
newSlot("setupMessage", message(nil))
newSlot("teardownMessage", message(nil))
newSlot("parent", nil)
newSlot("bodyContextName", nil)
setup := method(
setupMessage = call argAt(0)
)
teardown := method(
teardownMessage = call argAt(0)
)
describe := method(
if(call argCount == 2,
stateSlotName := nil
describedState := call evalArgAt(0)
bodyMessage := call argAt(1)
,
stateSlotName := call argAt(0) name
describedState := call evalArgAt(1)
bodyMessage := call argAt(2)
)
if(describedState type != "Sequence",
describedState = describedState type
)
bodyContext := BodyContext clone setParent(self)
if(bodyContextName != nil,
bodyContext setBodyContextName(bodyContextName .. " " .. describedState)
,
bodyContext setBodyContextName(describedState)
)
if(stateSlotName,
bodyContext setSlot(stateSlotName,
method(shouldName,
Lobby exampleCount = exampleCount + 1
testContext := Object clone
e := try(
describeContext := self
describeContexts := list
while(describeContext != nil,
describeContexts prepend(describeContext)
describeContext = describeContext parent
)
describeContexts foreach(setupMessage doInContext(testContext))
call argAt(1) doInContext(testContext)
describeContexts foreach(teardownMessage doInContext(testContext))
)
if(e,
failureErrors append(e)
writeln(" - ", shouldName, " [Error ", failureErrors size, "]")
,
writeln(" - ", shouldName)
)
)
)
)
hasTests := false
m := bodyMessage
while(m != nil,
if(m name == stateSlotName,
hasTests = true
break
)
m = m next
)
if(hasTests,
writeln(bodyContext bodyContextName)
)
bodyMessage ?doInContext(bodyContext)
if(hasTests,
writeln
)
)
)
exampleCount := 0
failureErrors := list
if(System args size > 1,
specs := System args exSlice(1)
,
specs := Directory filesWithExtension("-spec.io") map(path)
)
writeln
time := Date cpuSecondsToRun(
specs foreach(spec,
BodyContext clone doFile(spec)
)
)
failureErrors foreach(i, error,
write("Error ", i + 1, ":")
error showStack
)
failureCount := failureErrors size
writeln("Finished in ", time, " seconds")
writeln
writeln(if(specs size == 1, "", specs size .. " specs, "), exampleCount, if(exampleCount == 1, " example, ", " examples, "), failureCount, if(failureCount == 1, " failure", " failures"))