Skip to content

Commit d4dfbd1

Browse files
committed
[refactor] extract publish function
1 parent 510442f commit d4dfbd1

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

runner.lua

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ local id_sequence = 0
2626

2727
local tests <const> = {} -- {id=1,name=..}
2828

29+
local function publish(msg)
30+
send_message(parent_pid, msg)
31+
end
32+
2933
local function set_error_on_parents(parent, err)
3034
while parent != nil do
3135
parent.error = err
@@ -50,10 +54,7 @@ function test(name, test)
5054
}
5155
table.insert(tests, current_test)
5256

53-
send_message(
54-
parent_pid,
55-
{ event = "test_started", test = current_test }
56-
)
57+
publish { event = "test_started", test = current_test }
5758

5859
local success, err = pcall(test)
5960
if not success then
@@ -82,19 +83,15 @@ function test(name, test)
8283

8384
table.remove(tests, #tests)
8485

85-
send_message(parent_pid,
86-
{ event = "test_finished", test = current_test, error = err })
86+
publish { event = "test_finished", test = current_test, error = err }
8787
end
8888

8989
local originalPrint <const> = print
9090

9191
-- override picotron print, so all text is sent to the parent process
9292
function print(text, x, y, color)
9393
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 }
9895
end
9996

10097
originalPrint(text, x, y, color)
@@ -105,12 +102,9 @@ cd(work_dir)
105102
test("root", function()
106103
local ok = include(test_file)
107104
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" }
112106
return
113107
end
114108
end)
115109

116-
send_message(parent_pid, { event = "done", root_test_id = 1 })
110+
publish { event = "done", root_test_id = 1 }

0 commit comments

Comments
 (0)