Skip to content

Commit

Permalink
feat: lcov support
Browse files Browse the repository at this point in the history
  • Loading branch information
georgejecook committed May 5, 2020
1 parent 44690f8 commit 0cfb918
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 24 deletions.
55 changes: 55 additions & 0 deletions frameworkTests/source/tests/ExpectTests.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'@TestSuite ET ExpectTests

namespace ET

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'@It tests bug with expectOnce not matching values
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'@Test reported case
'@Params[[52], true]
'@Params[invalid, false]
'@Params[[invalid], true]
'@Params[["42"], true]
'@Params[[42], false]
function expectOnce_valuesBug_reported(expectedValue, expectMockFail) as void
obj = {
foo: function(arg0) : return arg0 : end function
}

m.ExpectOnce(obj, "foo", expectedValue)
obj.foo(42)
m.isAutoAssertingMocks = false
m.AssertMocks()

isFail = m.currentResult.isFail
m.currentResult.Reset()
m.CleanMocks()
m.AssertEqual(isFail, expectMockFail)
end function


'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'@It tests mock count limit
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

'@Test mock count limit at least 25
function expect_mockCountLimitToBeAtLeast25() as void

interface = {}

mockCountLimit = 25
for i = 1 to mockCountLimit step + 1
keyName = StrI(i).trim()
interface[keyName] = function(arg0) : return arg0 : end function

expectedArg = "a"
expectedReturnValue = "b"
m.ExpectOnce(interface, keyName, [expectedArg], [expectedReturnValue])

interface[keyName](expectedArg)
end for

end function

end namespace
51 changes: 51 additions & 0 deletions src/Coverage.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace RBS.Coverage

function createLCovOutput()
? "Generating lcov.info file..."

cc = m.global._rbs_ccn
expectedMap = cc.expectedMap
filePathMap = cc.filePathMap
resolvedMap = cc.resolvedMap

buffer = ""

for each module in filePathMap.items()
moduleNumber = module.key
filePath = module.value
packageName = "."

relativePath = filePath.replace("pkg:", packageName)
sanitizedPath = relativePath.replace("\\", "/")

buffer += "TN:" + chr(10)
buffer += "SF:" + sanitizedPath + chr(10)

for each expected in expectedMap[moduleNumber]
lineNumber = expected[0]
SHIFT = 1

if (resolvedMap[moduleNumber] <> invalid) and resolvedMap[moduleNumber].doesExist(str(lineNumber)) then
buffer += "DA:" + str(lineNumber + SHIFT) + ",1" + chr(10)
else
buffer += "DA:" + str(lineNumber + SHIFT) + ",0" + chr(10)
end if
end for

buffer += "end_of_record" + chr(10)
end for
return buffer
end function

function printLCovInfo()
?
? "+++++++++++++++++++++++++++++++++++++++++++"
? "LCOV.INFO FILE"
? "+++++++++++++++++++++++++++++++++++++++++++"
?
? "+-=-coverage:start"
? RBS.Coverage.createLCovOutput()
? "+-=-coverage:end"
end sub

end namespace
3 changes: 3 additions & 0 deletions src/TestCase.bs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ public function GetAssertLine(testCase, index)
return testCase.lineNumber
end if
end function

end class
end namespace
53 changes: 32 additions & 21 deletions src/TestLogger.bs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ class Logger

public function new(config)
m.config = config

m.verbosityLevel = {
basic : 0
normal : 1
basic : 0
normal : 1
verbose : 2
}

m.verbosity = m.config.logLevel
m.verbosity = m.config.logLevel
end function

'----------------------------------------------------------------
Expand All @@ -21,7 +21,7 @@ end function
public sub PrintStatistic(statObj as object)
m.PrintStart()
previousfile = invalid

for each testSuite in statObj.Suites
if (not statObj.testRunHasFailures or ((not m.config.showOnlyFailures) or testSuite.fail > 0 or testSuite.crash > 0))
if (testSuite.metaTestSuite.filePath <> previousfile)
Expand All @@ -31,7 +31,7 @@ public sub PrintStatistic(statObj as object)
m.PrintSuiteStatistic(testSuite, statObj.testRunHasFailures)
end if
end for

? ""
m.PrintEnd()
ignoredInfo = RBSFM_getIgnoredTestInfo()
Expand All @@ -45,21 +45,21 @@ public sub PrintStatistic(statObj as object)
print ignoredItemName
end for
end if

if (statObj.ignored > 0)
? "IGNORED TESTS:"
for each ignoredItemName in statObj.IgnoredTestNames
print ignoredItemName
end for
end if

if (statObj.Total = statObj.Correct)
overrallResult = "Success"
else
overrallResult = "Fail"
end if
? "RESULT: "; overrallResult

end sub

'----------------------------------------------------------------
Expand All @@ -69,31 +69,31 @@ end sub
'----------------------------------------------------------------
public sub PrintSuiteStatistic(statSuiteObj as object, hasFailures)
m.PrintSuiteStart(statSuiteObj.Name)

for each testCase in statSuiteObj.Tests
if (not hasFailures or ((not m.config.showOnlyFailures) or testCase.Result <> "Success"))
m.PrintTestStatistic(testCase)
end if
end for

? " |"
end sub

public sub PrintTestStatistic(testCase as object)
metaTestCase = testCase.metaTestCase

if (LCase(testCase.Result) <> "success")
testChar = "-"
assertIndex = metaTestCase.testResult.failedAssertIndex
locationLine = StrI(RBS_TC_GetAssertLine(metaTestCase,assertIndex)).trim()
locationLine = StrI(RBS_TC_GetAssertLine(metaTestCase, assertIndex)).trim()
else
testChar = "|"
locationLine = StrI(metaTestCase.lineNumber).trim()
end if
locationText = "pkg:/" + testCase.filePath.trim() + "(" + locationLine + ")"

if m.config.printTestTimes = true
timeText = " (" + stri(metaTestCase.time).trim() +"ms)"
timeText = " (" + stri(metaTestCase.time).trim() + "ms)"
else
timeText = ""
end if
Expand All @@ -102,17 +102,28 @@ public sub PrintTestStatistic(testCase as object)
if (metaTestcase.isParamTest <> true)
messageLine = RBS_LOGGER_FillText(" " + testChar + " |--" + metaTestCase.Name + " : ", ".", 80)
? messageLine ; testCase.Result ; timeText
else if ( metaTestcase.paramTestIndex = 0)
else if (metaTestcase.paramTestIndex = 0)
name = metaTestCase.Name
if (len(name) > 1 and right(name, 1) = "0")
name = left(name, len(name) - 1)
end if
? " " + testChar + " |--" + name+ " : "
? " " + testChar + " |--" + name + " : "
end if

if (metaTestcase.isParamTest = true)
insetText = " "
messageLine = m.fillText(" " + testChar + insetText + " |--" + formatJson(metaTestCase.rawParams) + " : ", ".", 80)

if type(metaTestCase.rawParams) = "roAssociativeArray"
rawParams = {}
for each key in metaTestCase.rawParams
if type(metaTestCase.rawParams[key]) <> "Function" and type(metaTestCase.rawParams[key]) <> "roFunction"
rawParams[key] = metaTestCase.rawParams[key]
end if
end for
else
rawParams = metaTestCase.rawParams
end if
messageLine = m.fillText(" " + testChar + insetText + " |--" + formatJson(rawParams) + " : ", ".", 80)
? messageLine ; testCase.Result ; timeText
end if

Expand All @@ -129,7 +140,7 @@ public function FillText(text as string, fillChar = " ", numChars = 40) as strin
if (len(text) >= numChars)
text = left(text, numChars - 5) + "..." + fillChar + fillChar
else
numToFill= numChars - len(text) -1
numToFill = numChars - len(text) - 1
for i = 0 to numToFill
text += fillChar
end for
Expand Down
14 changes: 11 additions & 3 deletions src/TestRunner.bs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public sub run()

goto skipSuite
end if
? ""
? RBS_LOGGER.FillText("> SUITE: " + metaTestSuite.name, ">", 80)

if (metaTestSuite.isNodeTest = true and metaTestSuite.nodeTestFileName <> "")
? " +++++RUNNING NODE TEST"
Expand Down Expand Up @@ -122,8 +124,12 @@ public sub run()
end for
m.logger.PrintStatistic(totalStatObj)

if RBS_CMN.IsFunction(Rooibos_ReportCodeCoverage)
Rooibos.ReportCodeCoverage()
if RBS_CMN.IsFunction(RBS.ReportCodeCoverage)
RBS.ReportCodeCoverage()

if m.config.printLcov = true
RBS.Coverage.printLCovInfo()
end if
end if
Rooibos.SendHomeKeypress()
end sub
Expand Down Expand Up @@ -194,6 +200,8 @@ public sub RunItGroups(metaTestSuite, totalStatObj, testUtilsDecoratorMethodName
end if
goto skipItGroup
end if
? ""
? RBS_LOGGER.FillText("> GROUP: " + itGroup.name, ">", 80)

if RBS_CMN.IsFunction(testSuite.SetUp)
testSuite.SetUp()
Expand Down Expand Up @@ -223,7 +231,7 @@ public sub RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config,
goto skipTestCase
end if
? ""
? RBS_LOGGER.FillText("> START: " + testSuite.name + "." + itGroup.name + "." + testCase.Name + " ", ">", 80)
? RBS_LOGGER.FillText("> TEST: " + testCase.Name + " ", ">", 80)

if RBS_CMN.IsFunction(testSuite.beforeEach)
testSuite.beforeEach()
Expand Down

0 comments on commit 0cfb918

Please sign in to comment.