This repository has been archived by the owner on Sep 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduce new test scripts * Update references to test scripts * Use success/fail/total counts * Upgrade Lemur
- Loading branch information
Showing
9 changed files
with
216 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
# Test places and build artifacts | ||
/*.rbxlx | ||
/*.rbxl | ||
/*.rbxmx | ||
/*.rbxm | ||
|
||
# LuaCov reports | ||
/luacov.* | ||
|
||
# MkDocs build output | ||
/site | ||
/lua_install | ||
|
||
# Cargo build output | ||
/target | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "TestEZ", | ||
"tree": { | ||
"$path": "src" | ||
} | ||
"name": "TestEZ", | ||
"tree": { | ||
"$path": "src" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "TestEZ Test Place", | ||
"tree": { | ||
"$className": "DataModel", | ||
|
||
"ReplicatedStorage": { | ||
"$className": "ReplicatedStorage", | ||
|
||
"TestEZ": { | ||
"$path": "src" | ||
}, | ||
|
||
"TestEZTests": { | ||
"$path": "tests" | ||
} | ||
}, | ||
|
||
"ServerScriptService": { | ||
"$className": "ServerScriptService", | ||
|
||
"Run Tests": { | ||
"$path": "test/runner.server.lua" | ||
} | ||
}, | ||
|
||
"HttpService": { | ||
"$className": "HttpService", | ||
"$properties": { | ||
"HttpEnabled": true | ||
} | ||
}, | ||
|
||
"Players": { | ||
"$className": "Players", | ||
"$properties": { | ||
"CharacterAutoLoads": false | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--[[ | ||
Loads TestEZ and all of its dependencies, then runs our test entrypoint. | ||
]] | ||
|
||
-- If you add any dependencies, add them to this table so they'll be loaded! | ||
local LOAD_MODULES = { | ||
{"src", "TestEZ"}, | ||
{"tests", "TestEZTests"}, | ||
} | ||
|
||
-- 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 of this repo! | ||
local lemur = require("modules.lemur") | ||
|
||
-- Create a virtual Roblox tree | ||
local habitat = lemur.Habitat.new() | ||
|
||
-- We'll put all of our library code and dependencies here | ||
local ReplicatedStorage = habitat.game:GetService("ReplicatedStorage") | ||
|
||
-- Load all of the modules specified above | ||
for _, module in ipairs(LOAD_MODULES) do | ||
local container = habitat:loadFromFs(module[1]) | ||
container.Name = module[2] | ||
container.Parent = ReplicatedStorage | ||
end | ||
|
||
-- When Lemur implements a proper scheduling interface, we'll use that instead. | ||
local runTests = habitat:loadFromFs("test/runner.server.lua") | ||
habitat:require(runTests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/sh | ||
|
||
# Usage: ./test/roblox-cli.sh | ||
|
||
if [ ! -z ${LOCALAPPDATA+x} ]; then | ||
# Probably Windows, look for any Roblox installation in the default path. | ||
|
||
VERSIONS_FOLDER="$LOCALAPPDATA/Roblox/Versions" | ||
INSTALL=`find "$VERSIONS_FOLDER" -maxdepth 1 -name version-* | head -1` | ||
CONTENT="$INSTALL/content" | ||
else | ||
# Probably macOS, look for Roblox Studio in its default path. | ||
|
||
CONTENT="/Applications/RobloxStudio.App/Contents/Resources/content" | ||
fi | ||
|
||
rojo build test-place.project.json -o TestPlace.rbxlx | ||
roblox-cli run --load.place TestPlace.rbxlx --assetFolder "$CONTENT" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
--[[ | ||
This test runner is invoked in all the environments that we want to test our | ||
library in. | ||
We target Lemur, Roblox Studio, and Roblox-CLI. | ||
]] | ||
|
||
-- luacheck: globals __LEMUR__ | ||
|
||
local isRobloxCli, ProcessService = pcall(game.GetService, game, "ProcessService") | ||
|
||
local function findUnitTests(container, foundTests) | ||
foundTests = foundTests or {} | ||
|
||
for _, child in ipairs(container:GetChildren()) do | ||
if child:IsA("ModuleScript") then | ||
table.insert(foundTests, child) | ||
end | ||
|
||
findUnitTests(child, foundTests) | ||
end | ||
|
||
return foundTests | ||
end | ||
|
||
local completed, result = xpcall(function() | ||
local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||
|
||
local testModules = findUnitTests(ReplicatedStorage.TestEZTests) | ||
|
||
local totalCount = 0 | ||
local failureCount = 0 | ||
local successCount = 0 | ||
local errorMessages = {} | ||
|
||
for _, testModule in ipairs(testModules) do | ||
local tests = require(testModule) | ||
|
||
print(string.format("%s", testModule.Name)) | ||
|
||
for testName, testFunction in pairs(tests) do | ||
local success, message = pcall(testFunction) | ||
totalCount = totalCount + 1 | ||
|
||
if success then | ||
print(string.format(" [PASS] %s", testName)) | ||
successCount = successCount + 1 | ||
else | ||
print(string.format(" [FAIL] %s", testName)) | ||
failureCount = failureCount + 1 | ||
|
||
local logMessage = string.format("Test: %s\nError: %s", testName, message) | ||
table.insert(errorMessages, logMessage) | ||
end | ||
end | ||
end | ||
|
||
print() | ||
print(string.format("%s tests run: %s passed, %s failed", totalCount, successCount, failureCount)) | ||
|
||
if #errorMessages > 0 then | ||
print() | ||
print(table.concat(errorMessages, "\n\n")) | ||
end | ||
|
||
return failureCount == 0 and 0 or 1 | ||
end, debug.traceback) | ||
|
||
local statusCode | ||
local errorMessage = nil | ||
if completed then | ||
statusCode = result | ||
else | ||
statusCode = 1 | ||
errorMessage = result | ||
end | ||
|
||
if __LEMUR__ then | ||
-- Lemur has access to normal Lua OS APIs | ||
|
||
if errorMessage ~= nil then | ||
print(errorMessage) | ||
end | ||
os.exit(statusCode) | ||
elseif isRobloxCli then | ||
-- Roblox CLI has a special service to terminate the process | ||
|
||
if errorMessage ~= nil then | ||
print(errorMessage) | ||
end | ||
ProcessService:Exit(statusCode) | ||
else | ||
-- In Studio, we can just throw an error to get the user's attention | ||
|
||
if errorMessage ~= nil then | ||
error(errorMessage, 0) | ||
end | ||
end |