Skip to content

Commit

Permalink
fixes #5 checking for test naming collisions needs improvements with …
Browse files Browse the repository at this point in the history
…Params tests - can lead to vague error messages for params

 - updates names of duplicate groups, and adds a very clear warning
  • Loading branch information
George Cook committed Oct 1, 2018
1 parent 309dbb5 commit 2c130c6
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 20 deletions.
14 changes: 13 additions & 1 deletion samples/Overview/source/rooibos.cat.brs
Original file line number Diff line number Diff line change
Expand Up @@ -2079,8 +2079,9 @@ function UnitTestSuite(filePath as string, maxLinesWithoutSuiteDirective = 100,
this.ProcessSuite = RBS_TS_ProcessSuite
this.ResetCurrentTestCase = RBS_TS_ResetCurrentTestCase
this.ProcessLegacySuite = RBS_TS_ProcessLegacySuite
this.ProcessSuite(maxLinesWithoutSuiteDirective, supportLegacyTests )
this.currentGroup = invalid
this.groupNames = {}
this.ProcessSuite(maxLinesWithoutSuiteDirective, supportLegacyTests )
return this
end function
function RBS_TS_ProcessSuite(maxLinesWithoutSuiteDirective, supportLegacyTests )
Expand Down Expand Up @@ -2159,6 +2160,17 @@ function RBS_TS_ProcessSuite(maxLinesWithoutSuiteDirective, supportLegacyTests )
if (name = "")
name = "UNNAMED TAG_TEST GROUP - name this group for better readability - e.g. 'Tests the Load method... '"
end if
if (m.groupNames[name] = invalid)
m.groupNames[name] = 0
end if
nameCount = m.groupNames[name]
nameCount++
m.groupNames[name] = nameCount
if (nameCount > 1)
? "WARNING A Group already exists with the name '"; name ; " changing name to avoid collisions. New Name:"
name = "WARNING!! DUPLICATE_" + stri(nameCount - 1).trim() + ": " + name
? name
end if
m.currentGroup = UnitTestItGroup(name, isNextTokenSolo, isNextTokenIgnore)
m.currentGroup.setupFunctionName = m.setupFunctionName
m.currentGroup.setupFunction = m.setupFunction
Expand Down
4 changes: 2 additions & 2 deletions source/buildinfo.brs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Function BuildDate()
return "Oct 1 2018 19:47:45"
return "Oct 1 2018 20:03:00"
End Function
Function BuildCommit()
return "e9f42a4"
return "309dbb5"
End Function
14 changes: 13 additions & 1 deletion source/rooibos.cat.brs
Original file line number Diff line number Diff line change
Expand Up @@ -2079,8 +2079,9 @@ function UnitTestSuite(filePath as string, maxLinesWithoutSuiteDirective = 100,
this.ProcessSuite = RBS_TS_ProcessSuite
this.ResetCurrentTestCase = RBS_TS_ResetCurrentTestCase
this.ProcessLegacySuite = RBS_TS_ProcessLegacySuite
this.ProcessSuite(maxLinesWithoutSuiteDirective, supportLegacyTests )
this.currentGroup = invalid
this.groupNames = {}
this.ProcessSuite(maxLinesWithoutSuiteDirective, supportLegacyTests )
return this
end function
function RBS_TS_ProcessSuite(maxLinesWithoutSuiteDirective, supportLegacyTests )
Expand Down Expand Up @@ -2159,6 +2160,17 @@ function RBS_TS_ProcessSuite(maxLinesWithoutSuiteDirective, supportLegacyTests )
if (name = "")
name = "UNNAMED TAG_TEST GROUP - name this group for better readability - e.g. 'Tests the Load method... '"
end if
if (m.groupNames[name] = invalid)
m.groupNames[name] = 0
end if
nameCount = m.groupNames[name]
nameCount++
m.groupNames[name] = nameCount
if (nameCount > 1)
? "WARNING A Group already exists with the name '"; name ; " changing name to avoid collisions. New Name:"
name = "WARNING!! DUPLICATE_" + stri(nameCount - 1).trim() + ": " + name
? name
end if
m.currentGroup = UnitTestItGroup(name, isNextTokenSolo, isNextTokenIgnore)
m.currentGroup.setupFunctionName = m.setupFunctionName
m.currentGroup.setupFunction = m.setupFunction
Expand Down
50 changes: 35 additions & 15 deletions source/tests/issue_13_afterEach_not_running.brs
Original file line number Diff line number Diff line change
@@ -1,28 +1,48 @@
'@TestSuite [RBSA] Rooibos before after tests
'@TestSuite [DGNT] Duplicate Group Name Tests

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'@It tests before each and after each are running
'@It group1
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'@BeforeEach
function RBSA__BeforeEach() as void
? "!!! Before"
'@Test simple
function DGNT_group1_test()
m.AssertTrue(true)
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'@It group2
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'@Test simple
function DGNT_group2_test()
m.AssertTrue(true)
end function


'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'@It group2
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'@AfterEach
function RBSA__AfterEach() as void
? "!!! After"
'@Test simple
function DGNT_group2_dupe_test()
m.AssertTrue(true)
end function

'@Test before after
function RBSA__before_after() as void

assertResult = m.Fail("reason")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'@It group3
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

isFail = m.currentResult.isFail
m.currentResult.Reset()
'@Test simple
function DGNT_group3_test()
m.AssertTrue(true)
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'@It group1
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

m.AssertFalse(assertResult)
m.AssertTrue(isFail)
'@Test simple
function DGNT_group1_dupe_test()
m.AssertTrue(true)
end function
28 changes: 28 additions & 0 deletions source/tests/issue_5_duplicateGroupNames.brs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'@TestSuite [RBSA] Rooibos before after tests

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'@It tests before each and after each are running
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'@BeforeEach
function RBSA__BeforeEach() as void
? "!!! Before"
end function


'@AfterEach
function RBSA__AfterEach() as void
? "!!! After"
end function

'@Test before after
function RBSA__before_after() as void

assertResult = m.Fail("reason")

isFail = m.currentResult.isFail
m.currentResult.Reset()

m.AssertFalse(assertResult)
m.AssertTrue(isFail)
end function
17 changes: 16 additions & 1 deletion src/Rooibos_TestSuite.brs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ function UnitTestSuite(filePath as string, maxLinesWithoutSuiteDirective = 100,
this.ProcessSuite = RBS_TS_ProcessSuite
this.ResetCurrentTestCase = RBS_TS_ResetCurrentTestCase
this.ProcessLegacySuite = RBS_TS_ProcessLegacySuite
this.ProcessSuite(maxLinesWithoutSuiteDirective, supportLegacyTests )
this.currentGroup = invalid
this.groupNames = {}

this.ProcessSuite(maxLinesWithoutSuiteDirective, supportLegacyTests )
return this
end function

Expand Down Expand Up @@ -118,6 +120,19 @@ function RBS_TS_ProcessSuite(maxLinesWithoutSuiteDirective, supportLegacyTests )
name = "UNNAMED TAG_TEST GROUP - name this group for better readability - e.g. 'Tests the Load method... '"
end if

if (m.groupNames[name] = invalid)
m.groupNames[name] = 0
end if

nameCount = m.groupNames[name]
nameCount++
m.groupNames[name] = nameCount
if (nameCount > 1)
? "WARNING A Group already exists with the name '"; name ; " changing name to avoid collisions. New Name:"
name = "WARNING!! DUPLICATE_" + stri(nameCount - 1).trim() + ": " + name
? name
end if

m.currentGroup = UnitTestItGroup(name, isNextTokenSolo, isNextTokenIgnore)

'inherit all suite functions that were set up to now
Expand Down

0 comments on commit 2c130c6

Please sign in to comment.