Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 152 lines (125 sloc) 3.69 KB
#!/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"))
Jump to Line
Something went wrong with that request. Please try again.