76 lines
1.7 KiB
Lua
76 lines
1.7 KiB
Lua
local createLibTest = require('/apis/libtest');
|
|
|
|
local testlib = createLibTest({ ... });
|
|
|
|
local function runStartupWithStubs()
|
|
local calls = {
|
|
rebooted = false,
|
|
shutdown = 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,
|
|
shutdown = function()
|
|
calls.shutdown = true;
|
|
end,
|
|
sleep = function() end,
|
|
},
|
|
parallel = {
|
|
waitForAny = 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 shuts down without rebooting', function()
|
|
local calls = runStartupWithStubs();
|
|
|
|
testlib.assertEquals(calls.shellRuns[1], 'shell');
|
|
testlib.assertEquals(calls.shutdown, true);
|
|
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();
|