Skip to content
This repository has been archived by the owner on Sep 14, 2024. It is now read-only.

Commit

Permalink
Error on dupe (#97)
Browse files Browse the repository at this point in the history
* Collapse TestPlan/TestPlanner/TestPlanBuilder/TestEnvironment

* Fix test name. Now it works as expected the first time

* Add a more explicit check of duplicate nodes

* Update tests of duplicate it blocks to match new code

* Add expectation to environment

* Add luacheck globals for new test

* Make duplicate it blocks an explicit error

* Update test of dupes

* Remove extra TestNode def

* Refactor TestNode to keep a pointer back to plan tree

* Update comments

* Typo

* Remove odd plan-as-parent pointer since the plan is stored explicitly

* Remove reference to TestPlanBuilder

* Comment on duplicate describe

* Mention changes to planning in changelog

* Mention in changelog

Co-authored-by: Lucien Greathouse <[email protected]>
  • Loading branch information
MagiMaster and LPGhatguy authored May 20, 2020
1 parent a9d1918 commit e12ce1c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Remove `HACK_NO_XPCALL`. With recent changes to the definition of xpcall, this is no longer necessary. Since people are still using it, it will now print out a warning asking them to delete that call instead.
* Major changes to the internals of test planning.
* The major visible change is that `describe` and `it` blocks with duplicate descriptions will now not overwrite the earlier copies of those nodes.
* Duplicate `it` nodes within one `describe` will raise an error.
* TestPlanBuilder was removed from the API.
* Fixed a bug with how `beforeAll` and `afterAll` handled nested nodes.

Expand Down
8 changes: 8 additions & 0 deletions src/TestPlan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ local function getModifier(name, pattern, modifier)
end

function TestNode:addChild(phrase, nodeType, nodeModifier)
if nodeType == TestEnum.NodeType.It then
for _, child in pairs(self.children) do
if child.phrase == phrase then
error("Duplicate it block found: " .. child:getFullName())
end
end
end

local childName = self:getFullName() .. " " .. phrase
nodeModifier = getModifier(childName, self.plan.testNamePattern, nodeModifier)
local child = TestNode.new(self.plan, phrase, nodeType, nodeModifier)
Expand Down
7 changes: 2 additions & 5 deletions tests/failing/duplicateIt.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

return function()
describe("multiple it blocks with the same description", function()
it("all get run", function()
it("should raise an error", function()
end)
it("all get run", function()
error("this shouldn't get overwritten")
end)
it("all get run", function()
it("should raise an error", function()
end)
end)
end
2 changes: 2 additions & 0 deletions tests/planning/d.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ return function()

describe("test4", function()
it("test5", function()
-- Duplicate describe blocks are not merged, so this is not a
-- duplicate it block.
end)

it("test7", function()
Expand Down

0 comments on commit e12ce1c

Please sign in to comment.