Skip to content

Commit d36080b

Browse files
committed
Add test for uninitialised parent class error
1 parent 276b197 commit d36080b

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

spec/System/TestCommon_spec.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
describe("Common", function()
2+
describe("Class creation and use", function()
3+
it("produces error when parent constructors are not called", function ()
4+
local ParentClass = newClass("ConstructorTestParentClass")
5+
function ParentClass:ConstructorTestParentClass()
6+
end
7+
local ChildClass = newClass("ConstructorTestProblemChildClass", "ConstructorTestParentClass")
8+
function ChildClass:ConstructorTestProblemChild()
9+
-- Intentionally does not call self:ConstructorTestParentClass()
10+
end
11+
common.classes.ConstructorTestParent = ParentClass
12+
common.classes.ConstructorTestProblemChild = ChildClass
13+
14+
assert.has_error(function()
15+
new("ConstructorTestProblemChild"):ConstructorTestProblemChild()
16+
end, "Parent class 'ConstructorTestParentClass' of class 'ConstructorTestProblemChild' must be initialised")
17+
common.classes.ConstructorTestParent = nil
18+
common.classes.ConstructorTestProblemChild = nil
19+
end)
20+
end)
21+
end)

0 commit comments

Comments
 (0)