-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiospec
executable file
·151 lines (125 loc) · 3.69 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env io
Importer addSearchPath("lib")
IoSpec := Object clone do(
version := "0.1.0"
Expectations
)
// What else should we do here? If it's not defined, we define it to be our current version. Probably better than nothing.
if(System getSlot("iospecVersion") isNil,
"WARNING: Your IoVM does not understand iospecVersion, defaulting to current IoSpec version." println
System iospecVersion := IoSpec version
)
AssertionFailed := Exception clone
BodyContext := Object clone do(
newSlot("setupMessage", message(nil))
newSlot("teardownMessage", message(nil))
newSlot("parent", nil)
newSlot("bodyContextName", nil)
newSlot("quiet", true)
setup := method(
setupMessage = call argAt(0)
)
teardown := method(
teardownMessage = call argAt(0)
)
describe := method(
describedState := call evalArgAt(0)
bodyMessage := call argAt(1)
if(describedState type != "Sequence",
describedState = describedState type
)
bodyContext := BodyContext clone setQuiet(quiet) setParent(self)
if(bodyContextName != nil,
bodyContext setBodyContextName(bodyContextName .. " " .. describedState)
,
bodyContext setBodyContextName(describedState)
)
bodyContext setSlot("it",
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)
quiet ifTrue(write("F"); File standardOutput flush) ifFalse(" - #{shouldName} [Error #{failureErrors size}]" interpolate println)
,
quiet ifTrue(write("."); File standardOutput flush) ifFalse(" - #{shouldName}" interpolate println)
)
)
)
bodyContext setSlot("itDependsOnVersion",
method(
versionPredicate := call argAt(0)
shouldName := call evalArgAt(1)
if(System iospecVersion doMessage(versionPredicate),
self performWithArgList("it", list(shouldName, call evalArgAt(2)))
)
)
)
bodyContext setSlot("pending",
method(str,
pendingSpecs append(str)
quiet ifTrue("*" print) ifFalse(" - #{str} [Pending #{pendingSpecs size}]" interpolate println)
)
)
hasTests := false
m := bodyMessage
while(m != nil,
if(m name == "it",
hasTests = true
break
)
m = m next
)
if(hasTests and quiet not,
writeln(bodyContext bodyContextName)
)
bodyMessage ?doInContext(bodyContext)
if(hasTests and quiet not,
writeln
)
)
)
exampleCount := 0
failureErrors := list
pendingSpecs := list
quiet := true
args := System args
if(args sort at(0) == "-v",
args removeFirst
quiet = false
)
if(System args size > 1,
specs := System args exSlice(1)
,
specs := Directory recursiveFilesOfTypes(list("-spec.io")) map(path)
)
writeln
time := Date secondsToRun(
specs foreach(spec,
BodyContext clone setQuiet(quiet) doFile(spec)
)
)
writeln("\n")
pendingSpecs foreach(i, pending,
"Pending #{i + 1}: #{pending}" interpolate println
)
writeln
failureErrors foreach(i, error,
write("Error ", i + 1, ":")
error showStack
)
failureCount := failureErrors size
writeln("\nFinished in ", time, " seconds")
writeln
writeln(if(specs size == 1, "", specs size .. " specs, "), exampleCount, if(exampleCount == 1, " example, ", " examples, "), failureCount, if(failureCount == 1, " failure,", " failures,"), if(pendingSpecs size == 1, " 1 pending", pendingSpecs size .. " pending"))