diff --git a/Justfile b/Justfile index f0ffe0a..3be1ee1 100644 --- a/Justfile +++ b/Justfile @@ -114,7 +114,7 @@ test *args: rom_arg="--rom /Applications/CraftOS-PC.app/Contents/Resources"; \ fi; \ repo='{{justfile_directory()}}'; \ - mount_arg="--mount-ro /apis=$repo/apis --mount-ro /programs=$repo/programs --mount-ro /tests=$repo/tests"; \ + mount_arg="--mount-ro /apis=$repo/apis --mount-ro /programs=$repo/programs --mount-ro /startup=$repo/startup --mount-ro /tests=$repo/tests"; \ tmp="$(mktemp)"; \ data_dir="$(mktemp -d)"; \ output_path="$data_dir/computer/0/trapos-test-output"; \ diff --git a/startup/servers.lua b/startup/servers.lua index 2d7be70..0434c73 100644 --- a/startup/servers.lua +++ b/startup/servers.lua @@ -1,4 +1,4 @@ -local _VERSION = '1.3.0' +local _VERSION = '1.3.1' local LOCAL_MANIFEST_PATH = '/trapos/manifest.json'; @@ -56,8 +56,3 @@ if #SERVERS > 0 then end parallel.waitForAll(shellFn, table.unpack(servers)); - -print("Servers stopped, reboot the machine..."); - -os.sleep(1); -os.reboot(); diff --git a/tests/startup-servers.lua b/tests/startup-servers.lua new file mode 100644 index 0000000..66cc7b8 --- /dev/null +++ b/tests/startup-servers.lua @@ -0,0 +1,70 @@ +local createLibTest = require('/apis/libtest'); + +local testlib = createLibTest({ ... }); + +local function runStartupWithStubs() + local calls = { + rebooted = false, + shellRuns = {}, + prints = {}, + }; + + local env = setmetatable({ + fs = { + exists = function(path) + return path ~= '/trapos/manifest.json' and fs.exists(path); + end, + }, + os = { + reboot = function() + calls.rebooted = true; + end, + sleep = function() end, + }, + parallel = { + waitForAll = function(firstFn) + firstFn(); + end, + }, + print = function(message) + calls.prints[#calls.prints + 1] = tostring(message); + end, + shell = { + path = function() + return '/rom/programs'; + end, + run = function(program) + calls.shellRuns[#calls.shellRuns + 1] = program; + return true; + end, + setPath = function() end, + }, + }, { __index = _G }); + + local chunk, loadErr = loadfile('/startup/servers.lua', 't', env); + if not chunk then + error(loadErr, 0); + end + + local ok, err = pcall(chunk); + if not ok then + error(err, 0); + end + + return calls; +end + +testlib.test('shell exit does not force reboot', function() + local calls = runStartupWithStubs(); + + testlib.assertEquals(calls.shellRuns[1], 'shell'); + testlib.assertEquals(calls.rebooted, false); + for _, message in ipairs(calls.prints) do + testlib.assertTrue( + not string.find(message, 'Servers stopped', 1, true), + 'startup should not print a forced reboot message' + ); + end +end); + +testlib.run();