Skip to content

Commit

Permalink
Introduce new test runner scripts (Roblox#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
LPGhatguy authored Jan 21, 2020
1 parent 1191b1e commit 185d71c
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 17 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Test places and builds
/*.rbxl
/*.rbxlx
/*.rbxm
/*.rbxmx

# LuaCov output location
/luacov.*

# MkDocs build output
/site/

# Rotriever
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ install:

script:
- luacheck lib
- lua -lluacov spec.lua
- lua -lluacov test/lemur.lua

after_success:
- luacov-coveralls -e $TRAVIS_BUILD_DIR/lua_install
16 changes: 13 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,31 @@ To get started working on RoactRodux, you'll need:
* [Luacheck](https://github.com/mpeterv/luacheck) (`luarocks install luacheck`)
* [LuaCov](https://keplerproject.github.io/luacov) (`luarocks install luacov`)

Once you have all of these installed, you can run `lua bin/install-dependencies.lua` script to grab a couple additional local dependencies automatically.
Make sure to clone the repository with submodules. You can do that to your existing repository with:

```sh
git submodule update --init
```

Finally, you can run all of RoactRodux's tests with:

```sh
lua spec.lua
lua test/lemur.lua
```

Or, to generate a LuaCov coverage report:

```sh
lua -lluacov spec.lua
lua -lluacov test/lemur.lua
luacov
```

If you're an engineer at Roblox, you can skip this setup and use Roblox-CLI. Make sure it's on your `PATH` and that you have a production Roblox Studio installation. You can then run:

```sh
./test/roblox-cli.sh
```

## Pull Requests
Before starting a pull request, open an issue about the feature or bug. This helps us prevent duplicated and wasted effort. These issues are a great place to ask for help if you run into problems!

Expand Down
8 changes: 8 additions & 0 deletions place.project.json → test-place.project.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
}
},

"ServerScriptService": {
"$className": "ServerScriptService",

"Run Tests": {
"$path": "test/runner.server.lua"
}
},

"HttpService": {
"$className": "HttpService",
"$properties": {
Expand Down
19 changes: 6 additions & 13 deletions spec.lua → test/lemur.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

-- If you add any dependencies, add them to this table so they'll be loaded!
local LOAD_MODULES = {
{"lib", "Library"},
{"lib", "RoactRodux"},
{"modules/rodux/lib", "Rodux"},
{"modules/roact/lib", "Roact"},
{"modules/testez/lib", "TestEZ"},
Expand All @@ -20,22 +20,15 @@ local lemur = require("modules.lemur")
local habitat = lemur.Habitat.new()

-- We'll put all of our library code and dependencies here
local Root = lemur.Instance.new("Folder")
Root.Name = "Root"
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 = Root
container.Parent = ReplicatedStorage
end

-- Load TestEZ and run our tests
local TestEZ = habitat:require(Root.TestEZ)

local results = TestEZ.TestBootstrap:run(Root.Library, TestEZ.Reporters.TextReporter)

-- Did something go wrong?
if results.failureCount > 0 then
os.exit(1)
end
-- When Lemur implements a proper scheduling interface, we'll use that instead.
local runTests = habitat:loadFromFs("test/runner.server.lua")
habitat:require(runTests)
18 changes: 18 additions & 0 deletions test/roblox-cli.sh
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"
62 changes: 62 additions & 0 deletions test/runner.server.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--[[
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 completed, result = xpcall(function()
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Roact = require(ReplicatedStorage.Roact)
local TestEZ = require(ReplicatedStorage.TestEZ)

Roact.setGlobalConfig({
-- ["internalTypeChecks"] = true,
-- ["typeChecks"] = true,
elementTracing = true,
-- ["propValidation"] = true,
})

local results = TestEZ.TestBootstrap:run(
ReplicatedStorage.RoactRodux,
TestEZ.Reporters.TextReporter
)

return results.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

0 comments on commit 185d71c

Please sign in to comment.