Skip to content
This repository was archived by the owner on Sep 14, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6c36a86
Collapse TestPlan/TestPlanner/TestPlanBuilder/TestEnvironment
MagiMaster May 7, 2020
a61e327
Merge remote-tracking branch 'origin/master' into masterPlan
MagiMaster May 9, 2020
b7e1877
Fix test name. Now it works as expected the first time
MagiMaster May 9, 2020
ab4a9ac
Add a more explicit check of duplicate nodes
MagiMaster May 9, 2020
7084dad
Merge branch 'fixTest' into masterPlan
MagiMaster May 9, 2020
ff58302
Update tests of duplicate it blocks to match new code
MagiMaster May 9, 2020
79c68b7
Add expectation to environment
MagiMaster May 13, 2020
ed47b2c
Add luacheck globals for new test
MagiMaster May 13, 2020
04afd68
Refactor TestNode to keep a pointer back to plan tree
MagiMaster May 14, 2020
a33e158
Update comments
MagiMaster May 14, 2020
90d935a
Typo
MagiMaster May 14, 2020
5ed50de
Remove odd plan-as-parent pointer since the plan is stored explicitly
MagiMaster May 14, 2020
0a37fb8
Remove reference to TestPlanBuilder
MagiMaster May 14, 2020
6753092
Use the node environment in test runner
MagiMaster May 15, 2020
65deace
Remove unused require
MagiMaster May 15, 2020
4cc1fed
Merge remote-tracking branch 'origin/master' into runnerEnvironment
MagiMaster May 19, 2020
035d7a3
Readd env.fail
MagiMaster May 20, 2020
53ee6e0
Remove redundant wrapper around traceback
MagiMaster May 20, 2020
c5cf5ff
Keep fail() in TestRunner for now
MagiMaster May 21, 2020
3285ab7
Remove leftover check
MagiMaster May 21, 2020
676bc73
Merge remote-tracking branch 'origin/master' into runnerEnvironment
MagiMaster May 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/TestPlan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function TestNode:addChild(phrase, nodeType, nodeModifier)
end

--[[
Join the names of all the nodes back to the parent.
Join the names of all the nodes back to the root of the tree.
]]
function TestNode:getFullName()
if self.parent then
Expand Down
31 changes: 11 additions & 20 deletions src/TestRunner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@
state is contained inside a TestSession object.
]]

local Expectation = require(script.Parent.Expectation)
local TestEnum = require(script.Parent.TestEnum)
local TestSession = require(script.Parent.TestSession)
local LifecycleHooks = require(script.Parent.LifecycleHooks)

local RUNNING_GLOBAL = "__TESTEZ_RUNNING_TEST__"

local TestRunner = {
environment = {}
}

function TestRunner.environment.expect(...)
return Expectation.new(...)
end
local TestRunner = {}

--[[
Runs the given TestPlan and returns a TestResults object representing the
Expand Down Expand Up @@ -55,30 +48,28 @@ function TestRunner.runPlanNode(session, planNode, lifecycleHooks)

messagePrefix = messagePrefix or ""

local testEnvironment = getfenv(callback)

for key, value in pairs(TestRunner.environment) do
local originalEnvironment = getfenv(callback)
local testEnvironment = setmetatable({}, { __index = originalEnvironment })
for key, value in pairs(planNode.environment) do
testEnvironment[key] = value
end

testEnvironment.fail = function(message)
if message == nil then
message = "fail() was called."
function testEnvironment.fail(message)
if not message then
message = "fail() was called"
end

errorMessage = debug.traceback(message, 2)
success = false
errorMessage = messagePrefix .. message .. "\n" .. debug.traceback()
end

local nodeSuccess, nodeResult = xpcall(callback, function(message)
return messagePrefix .. message .. "\n" .. debug.traceback()
end)
setfenv(callback, testEnvironment)
local nodeSuccess, nodeResult = xpcall(callback, debug.traceback)

-- If a node threw an error, we prefer to use that message over
-- one created by fail() if it was set.
if not nodeSuccess then
success = false
errorMessage = nodeResult
errorMessage = messagePrefix .. nodeResult
end

_G[RUNNING_GLOBAL] = nil
Expand Down