mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-07-02 18:12:50 +00:00

- Use jacoco for Java-side coverage. Our Java coverage is /terrible (~10%), as we only really test the core libraries. Still a good thing to track for regressions though. - mcfly now tracks Lua side coverage. This works in several stages: - Replace loadfile to include the whole path - Add a debug hook which just tracks filename->(lines->count). This is then submitted to the Java test runner. - On test completion, we emit a luacov.report.out file. As the debug hook is inserted by mcfly, this does not include any computer startup (such as loading apis, or the root of bios.lua), despite they're executed. This would be possible to do (for instance, inject a custom header into bios.lua). However, we're not actually testing any of the behaviour of startup (aside from "does it not crash"), so I'm not sure whether to include it or not. Something I'll most likely re-evaluate.
75 lines
2.9 KiB
Lua
75 lines
2.9 KiB
Lua
describe("The peripheral library", function()
|
|
local it_modem = peripheral.getType("top") == "modem" and it or pending
|
|
|
|
describe("peripheral.isPresent", function()
|
|
it("validates arguments", function()
|
|
peripheral.isPresent("")
|
|
expect.error(peripheral.isPresent, nil):eq("bad argument #1 (expected string, got nil)")
|
|
end)
|
|
end)
|
|
|
|
describe("peripheral.getName", function()
|
|
it("validates arguments", function()
|
|
expect.error(peripheral.getName, nil):eq("bad argument #1 (expected table, got nil)")
|
|
expect.error(peripheral.getName, {}):eq("bad argument #1 (table is not a peripheral)")
|
|
end)
|
|
|
|
it_modem("can get the name of a wrapped peripheral", function()
|
|
expect(peripheral.getName(peripheral.wrap("top"))):eq("top")
|
|
end)
|
|
end)
|
|
|
|
describe("peripheral.getType", function()
|
|
it("validates arguments", function()
|
|
peripheral.getType("")
|
|
expect.error(peripheral.getType, nil):eq("bad argument #1 (expected string or table, got nil)")
|
|
expect.error(peripheral.getType, {}):eq("bad argument #1 (table is not a peripheral)")
|
|
end)
|
|
|
|
it_modem("can get the type of a peripheral by side", function()
|
|
expect(peripheral.getType("top")):eq("modem")
|
|
end)
|
|
|
|
it_modem("can get the type of a wrapped peripheral", function()
|
|
expect(peripheral.getType(peripheral.wrap("top"))):eq("modem")
|
|
end)
|
|
end)
|
|
|
|
describe("peripheral.getMethods", function()
|
|
it("validates arguments", function()
|
|
peripheral.getMethods("")
|
|
expect.error(peripheral.getMethods, nil):eq("bad argument #1 (expected string, got nil)")
|
|
end)
|
|
end)
|
|
|
|
describe("peripheral.call", function()
|
|
it("validates arguments", function()
|
|
peripheral.call("", "")
|
|
expect.error(peripheral.call, nil):eq("bad argument #1 (expected string, got nil)")
|
|
expect.error(peripheral.call, "", nil):eq("bad argument #2 (expected string, got nil)")
|
|
end)
|
|
|
|
it_modem("has the correct error location", function()
|
|
expect.error(function() peripheral.call("top", "isOpen", false) end)
|
|
:str_match("^[^:]+:%d+: bad argument #1 %(number expected, got boolean%)$")
|
|
end)
|
|
end)
|
|
|
|
describe("peripheral.wrap", function()
|
|
it("validates arguments", function()
|
|
peripheral.wrap("")
|
|
expect.error(peripheral.wrap, nil):eq("bad argument #1 (expected string, got nil)")
|
|
end)
|
|
end)
|
|
|
|
describe("peripheral.find", function()
|
|
it("validates arguments", function()
|
|
peripheral.find("")
|
|
peripheral.find("", function()
|
|
end)
|
|
expect.error(peripheral.find, nil):eq("bad argument #1 (expected string, got nil)")
|
|
expect.error(peripheral.find, "", false):eq("bad argument #2 (expected function, got boolean)")
|
|
end)
|
|
end)
|
|
end)
|