@@ -26,6 +26,10 @@ local id_sequence = 0
26
26
27
27
local tests <const> = {} -- {id=1,name=..}
28
28
29
+ local function publish (msg )
30
+ send_message (parent_pid , msg )
31
+ end
32
+
29
33
local function set_error_on_parents (parent , err )
30
34
while parent != nil do
31
35
parent .error = err
@@ -50,10 +54,7 @@ function test(name, test)
50
54
}
51
55
table.insert (tests , current_test )
52
56
53
- send_message (
54
- parent_pid ,
55
- { event = " test_started" , test = current_test }
56
- )
57
+ publish { event = " test_started" , test = current_test }
57
58
58
59
local success , err = pcall (test )
59
60
if not success then
@@ -82,19 +83,15 @@ function test(name, test)
82
83
83
84
table.remove (tests , # tests )
84
85
85
- send_message (parent_pid ,
86
- { event = " test_finished" , test = current_test , error = err })
86
+ publish { event = " test_finished" , test = current_test , error = err }
87
87
end
88
88
89
89
local originalPrint <const> = print
90
90
91
91
-- override picotron print, so all text is sent to the parent process
92
92
function print (text , x , y , color )
93
93
if x == nil and y == nil and color == nil then
94
- send_message (
95
- parent_pid ,
96
- { event = " print" , test = tests [# tests ], text = text }
97
- )
94
+ publish { event = " print" , test = tests [# tests ], text = text }
98
95
end
99
96
100
97
originalPrint (text , x , y , color )
@@ -105,12 +102,9 @@ cd(work_dir)
105
102
test (" root" , function ()
106
103
local ok = include (test_file )
107
104
if not ok then
108
- send_message (
109
- parent_pid ,
110
- { event = " fatal_error" , error = test_file .. " not found" }
111
- )
105
+ publish { event = " fatal_error" , error = test_file .. " not found" }
112
106
return
113
107
end
114
108
end )
115
109
116
- send_message ( parent_pid , { event = " done" , root_test_id = 1 })
110
+ publish { event = " done" , root_test_id = 1 }
0 commit comments