Skip to content

Commit 3dec4ec

Browse files
authored
Merge pull request #52 from scr-oath/suite-Run-returns-count
Make suite.Run return the number of tests found and executed
2 parents 6afdfc8 + 8aebad0 commit 3dec4ec

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ end
8282

8383
function TestSuite(t)
8484
-- Same mechanism for test discovery is used, but then the suite is run as sub tests via suite.Run
85-
suite.Run(t, MySuite)
85+
assert(suite.Run(t, MySuite), "No tests were run by this Suite")
8686

8787
-- Called for every test: two tests so should be 2
8888
assert(MySuite.setupCount == 2, tostring(MySuite.setupCount))

tests/lua_const.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// GENERATED BY textFileToGoConst
22
// GitHub: github.com/logrusorgru/textFileToGoConst
33
// input file: suite.lua
4-
// generated: Sat Nov 5 20:27:23 PDT 2022
4+
// generated: Thu Nov 10 11:29:24 PST 2022
55

66
package tests
77

@@ -13,6 +13,8 @@ local suite = {
1313
}
1414
1515
function suite.Run(t, testSuite)
16+
local testCount = 0
17+
1618
-- testSuite must be subclass of suite.Suite, so will have this method
1719
testSuite:SetT(t)
1820
@@ -21,6 +23,7 @@ function suite.Run(t, testSuite)
2123
end
2224
for k, v in pairs(testSuite) do
2325
if strings.has_prefix(k, "Test") then
26+
testCount = testCount + 1
2427
if testSuite.SetupTest then
2528
testSuite:SetupTest()
2629
end
@@ -37,6 +40,8 @@ function suite.Run(t, testSuite)
3740
if testSuite.TearDownSuite then
3841
testSuite:TearDownSuite()
3942
end
43+
44+
return testCount
4045
end
4146
4247
function suite.Suite:new(o)

tests/suite.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ local suite = {
66
}
77

88
function suite.Run(t, testSuite)
9+
local testCount = 0
10+
911
-- testSuite must be subclass of suite.Suite, so will have this method
1012
testSuite:SetT(t)
1113

@@ -14,6 +16,7 @@ function suite.Run(t, testSuite)
1416
end
1517
for k, v in pairs(testSuite) do
1618
if strings.has_prefix(k, "Test") then
19+
testCount = testCount + 1
1720
if testSuite.SetupTest then
1821
testSuite:SetupTest()
1922
end
@@ -30,6 +33,8 @@ function suite.Run(t, testSuite)
3033
if testSuite.TearDownSuite then
3134
testSuite:TearDownSuite()
3235
end
36+
37+
return testCount
3338
end
3439

3540
function suite.Suite:new(o)

tests/testdata/test_suite.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ end
4242

4343
function TestSuite(t)
4444
-- Same mechanism for test discovery is used, but then the suite is run as sub tests via suite.Run
45-
suite.Run(t, MySuite)
45+
assert(suite.Run(t, MySuite), "No tests were run by this Suite")
4646

4747
-- Called for every test: two tests so should be 2
4848
assert(MySuite.setupCount == 2, tostring(MySuite.setupCount))
@@ -52,3 +52,10 @@ function TestSuite(t)
5252
assert(MySuite.setupSuiteCount == 1, tostring(MySuite.setupSuiteCount))
5353
assert(MySuite.tearDownSuiteCount == 1, tostring(MySuite.tearDownSuiteCount))
5454
end
55+
56+
local EmptySuite = suite.Suite:new()
57+
58+
function TestEmptySuiteReturnsZero(t)
59+
local testCount = suite.Run(t, EmptySuite)
60+
assert(testCount == 0, string.format('EmptySuite ran %d tests, unexpectedly', testCount))
61+
end

0 commit comments

Comments
 (0)