1+ module gololang. testing. Suite
2+
3+ import gololang. testing. Test
4+
5+ struct Suite = {
6+ description,
7+ parent,
8+ children,
9+ befores,
10+ afters,
11+ onStart,
12+ onDone,
13+ report
14+ }
15+
16+ struct SuiteReport = {
17+ total,
18+ failures
19+ }
20+
21+ function Suite = |description, parent, onStart, onDone| - > gololang. testing. Suite. types. Suite()
22+ : description( description)
23+ : parent( parent)
24+ : children( list[])
25+ : befores( list[])
26+ : afters( list[])
27+ : onStart( onStart)
28+ : onDone( onDone)
29+ : report( SuiteReport( 0 , 0 ))
30+
31+ augment gololang. testing. Suite. types. SuiteReport {
32+ function addExcutedTest = |this , child| {
33+ if child oftype gololang. testing. Suite. types. Suite. class {
34+ this : total( this : total() + child: report() : total() )
35+ } else {
36+ this : total( this : total() + 1 )
37+ }
38+ }
39+ function addFailures = |this , child| {
40+ if child oftype gololang. testing. Suite. types. Suite. class {
41+ this : failures( this : failures() + child: report() : failures() )
42+ } else {
43+ this : failures( this : failures() + 1 )
44+ }
45+ }
46+ }
47+
48+ augment gololang. testing. Suite. types. Suite {
49+
50+ function run = |this | {
51+ this : onStart()( this )
52+ this : children() : each ( |child| {
53+ this : befores() : each ( |before| - > before())
54+ child: run()
55+ this : report() : addExcutedTest( child)
56+ if child: failed() {
57+ this : report() : addFailures( child)
58+ }
59+ this : afters() : each ( |after| - > after())
60+ })
61+ this : onDone()( this )
62+ }
63+
64+ function add = |this , it| {
65+ it: parent( this )
66+ this : children() : add( it)
67+ }
68+
69+ function failed = |this | - > this : report() : failures() isnt 0
70+
71+ function addBeforeEach = |this , before| - > this : befores() : add( before)
72+ function addAfterEach = |this , after| - > this : afters() : add( after)
73+ }
0 commit comments