Skip to content

Instantly share code, notes, and snippets.

@OverHash
Created December 20, 2019 00:01
Show Gist options
  • Save OverHash/258412684aa16aed00b58858854eecc3 to your computer and use it in GitHub Desktop.
Save OverHash/258412684aa16aed00b58858854eecc3 to your computer and use it in GitHub Desktop.
-- This makes sure we can load Lemur and other libraries that depend on init.lua
package.path = package.path .. ";?/init.lua"
-- If this fails, make sure you've cloned all Git submodules.
local lemur = require("modules.lemur")
local habitat = lemur.Habitat.new()
local function newFolder(name, parent, content)
local folder
if content then
folder = habitat:loadFromFs(content)
else
folder = lemur.Instance.new("Folder")
end
folder.Name = name
folder.Parent = parent
return folder
end
local ReplicatedStorage = habitat.game:GetService("ReplicatedStorage")
local testEZFolder = newFolder("TestEZ", ReplicatedStorage, "modules/testez/lib")
-- Testing code
local testsFolder = newFolder("src", ReplicatedStorage)
local outFolder = newFolder("src", testsFolder, "src")
local function findUnitTests(container, foundTests)
foundTests = foundTests or {}
for _, child in ipairs(container:GetChildren()) do
if child:IsA("ModuleScript") and not child.Name:match('GameAnalytics') then
table.insert(foundTests, child)
end
findUnitTests(child, foundTests)
end
return foundTests
end
-- Run all unit tests, which are located in .spec.lua files next to the source
local unitTests = findUnitTests(habitat:loadFromFs('src'))
for _, module in pairs(unitTests) do
module.Parent = outFolder
end
print("Running unit tests...")
local TestEZ = habitat:require(testEZFolder)
local results = TestEZ.TestBootstrap:run({outFolder}, TestEZ.Reporters.TextReporter)
-- Did something go wrong?
if #results.errors > 0 or results.failureCount > 0 then
os.exit(1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment