diff --git a/fetch-latest-releases.lua b/fetch-latest-releases.lua index 3f2104d..ad019c5 100755 --- a/fetch-latest-releases.lua +++ b/fetch-latest-releases.lua @@ -98,6 +98,13 @@ function get_releases(branch, destdir) return t end +-- return functions as module for unit testing +if not string.match(arg[0], "fetch%-latest%-releases") then + return { + fatal = fatal, + } +end + local branch = arg[1] or "edge" local destdir = arg[2] or "out" diff --git a/tests/fetch-latest-releases_spec.lua b/tests/fetch-latest-releases_spec.lua new file mode 100644 index 0000000..0842b47 --- /dev/null +++ b/tests/fetch-latest-releases_spec.lua @@ -0,0 +1,18 @@ +describe("test fetch-latest-releases functions", function() + local f + setup(function() + f = require("fetch-latest-releases") + end) + + teardown(function() + f = nil + end) + + describe("test fatal", function() + it("should call os.exit", function() + stub(os, "exit") + f.fatal("hello") + assert.stub(os.exit).was_called_with(1) + end) + end) +end)