1 UnitTest
:= Object clone do(
9 tearDown
:= method(nil
)
10 init
:= method(self exceptions
:= List clone)
11 testSlotNames
:= method(
12 names
:= self slotNames select(name
, name
beginsWithSeq("test"))
13 names
sortByKey(name
, self getSlot(name
) message lineNumber
)
16 testCount
:= method(testSlotNames size
)
19 testSlotNames
foreach(n
,
22 e
:= try(stopStatus(self doString(n
)))
24 write(" ", n
, " - failed")
30 //Scheduler currentCoroutine
yield
37 fail
:= method(Exception raise("fail"))
39 assertEquals
:= method(a
, b
, m
,
40 //writeln("assertEquals1 call message = ", call
message type)
43 d
:= m
argAt(0) code
.. " != " .. call
argAt(1) code
44 if(a
!= b
, Exception raise("[" .. d
.. "] [" .. a
.. " != " .. b
.. "]"))
45 //writeln("assertEquals2")
48 assertNotEquals
:= method(a
, b
, if(a
== b
, Exception raise(a
.. " == " .. b
)))
50 assertSame
:= method(a
, b
, assertEquals(a
uniqueId, b
uniqueId, call
message))
51 assertNotSame
:= method(a
, b
, assertNotEquals(a
uniqueId, b
uniqueId, call
message))
52 assertNil
:= method(a
, assertEquals(a
, nil
, call
message))
53 assertNotNil
:= method(a
, assertNotEquals(a
, nil
, call
message))
54 assertTrue
:= method(a
, assertEquals(a
, true
, call
message))
55 assertFalse
:= method(a
, assertEquals(a
, false
, call
message))
57 assertRaisesException
:= method(
59 stopStatus(call
evalArgAt(0))
60 writeln("Should have raised Exception")
62 e
ifNil(Exception raise("Should have raised Exception"))
66 //writeln(" [known bug: ", call
argAt(0) code
, "]")
69 assertEqualsWithinDelta
:= method(expected
, actual
, delta
,
70 if(((expected
- actual
) abs
> delta
),
71 Exception raise("expected " .. expected
.. " but was " .. actual
.. " (allowed delta: " .. delta
.. ")")
76 TestSuite
:= Object clone do(
82 docCategory("Testing")
85 path asMutable pathComponent lastPathComponent
92 unitTestFiles
:= Directory with(launchPath
) files
select(f
, f name
endsWithSeq("Test.io"))
93 exceptions
:= List clone
96 unitTestFiles
foreach(f
,
98 verbose(" " .. f name fileName
)
99 test
:= Lobby doString(f contents
, f path
)
103 testCount
= testCount
+ test testCount
104 exceptions
appendSeq(test exceptions
)
107 verbose(" ---------------")
109 //if(testCount
== 0, write("(no tests)"); File standardOutput flush
; return(0))
110 if(exceptions size
> 0) then(
111 //writeln(" FAILED ", testCount
, " tests, ", exceptions size
, " failures\n")
112 return(exceptions size
)
114 //writeln(" PASSED ", testCount
, " tests\n")