Skip to content

Commit

Permalink
Fixed most failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdp committed Jan 14, 2025
1 parent b77ad70 commit aca45ca
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 41 deletions.
6 changes: 3 additions & 3 deletions bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ describe('RooibosPlugin', () => {
it('adds code coverage to a brs file', async () => {
program.setFile('source/code.brs', `
function new(a1, a2)
c = 0
text = ""
c = 0
text = ""
for i = 0 to 10
text = text + "hello"
c++
Expand Down Expand Up @@ -333,7 +333,7 @@ describe('RooibosPlugin', () => {
expect(a).to.equal(b);
});

it('correctly transpiles some statements', async () => {
it.only('correctly transpiles some statements', async () => {

Check failure on line 336 in bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.spec.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

it.only not permitted
const source = `sub foo()
x = function(y)
if (true) then
Expand Down
8 changes: 7 additions & 1 deletion bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class CodeCoverageProcessor {
private coverageMap: Map<number, number>;
private fileFactory: FileFactory;
private processedStatements: Set<Statement>;
private addedStatements: Set<Statement>;
private astEditor: Editor;

public generateMetadata(isUsingCoverage: boolean, program: Program) {
Expand All @@ -74,6 +75,7 @@ export class CodeCoverageProcessor {
this.coverageMap = new Map<number, number>();
this.executableLines = new Map<number, Statement>();
this.processedStatements = new Set<Statement>();
this.addedStatements = new Set<Statement>();
this.astEditor = astEditor;

file.ast.walk(createVisitor({
Expand Down Expand Up @@ -167,21 +169,25 @@ export class CodeCoverageProcessor {
}

private convertStatementToCoverageStatement(statement: Statement, coverageType: CodeCoverageLineType, owner: any, key: any) {
if (this.processedStatements.has(statement)) {
if (this.processedStatements.has(statement) || this.addedStatements.has(statement)) {
return;
}

const lineNumber = statement.range.start.line;
this.coverageMap.set(lineNumber, coverageType);
const parsed = Parser.parse(this.getFuncCallText(lineNumber, coverageType)).ast.statements[0] as ExpressionStatement;
this.astEditor.arraySplice(owner, key, 0, parsed);
this.addedStatements.add(parsed);
// store the statement in a set to avoid handling again after inserting statement above
this.processedStatements.add(statement);
}

public addBrsAPIText(file: BrsFile, astEditor: Editor) {
const astCodeToInject = Parser.parse(this.coverageBrsTemplate.replace(/\#ID\#/g, this.fileId.toString().trim())).ast.statements;
astEditor.arrayPush(file.ast.statements, ...astCodeToInject);
for (let statement of astCodeToInject) {
this.addedStatements.add(statement);
}
}

private addStatement(statement: Statement, lineNumber?: number) {
Expand Down
64 changes: 32 additions & 32 deletions framework/src/source/MochaTestReporter.bs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ namespace rooibos
' end function

override sub onSuiteBegin(event as rooibos.TestReporterOnSuiteBeginEvent)
print m.colorLines(rooibos.reporter.mocha.colors.suite, event.suite.name)
print m.colorLines(rooibos.reporters.mocha.colors.suite, event.suite.name)
end sub

override sub onTestGroupBegin(event as rooibos.TestReporterOnTestGroupBeginEvent)
print tab(2) m.colorLines(rooibos.reporter.mocha.colors.suite, event.group.name)
print tab(2) m.colorLines(rooibos.reporters.mocha.colors.suite, event.group.name)
end sub

' override function onTestBegin(event as rooibos.TestReporterOnTestBeginEvent)
Expand All @@ -28,19 +28,19 @@ namespace rooibos
test = event.test
status = test.result.getStatusText()

lineColor = rooibos.reporter.mocha.colors.light
lineColor = rooibos.reporters.mocha.colors.light
symbolColor = ""
symbol = "?"
if status = "PASS"
symbol = "✔"
symbolColor = rooibos.reporter.mocha.colors.checkmark
symbolColor = rooibos.reporters.mocha.colors.checkmark
else if status = "FAIL" or status = "CRASH"
symbol = "✖️"
symbolColor = rooibos.reporter.mocha.colors.brightFail
symbolColor = rooibos.reporters.mocha.colors.brightFail
else if status = "SKIP"
symbol = "-"
symbolColor = rooibos.reporter.mocha.colors.pending
lineColor = rooibos.reporter.mocha.colors.pending
symbolColor = rooibos.reporters.mocha.colors.pending
lineColor = rooibos.reporters.mocha.colors.pending
end if

params = ""
Expand Down Expand Up @@ -93,18 +93,18 @@ namespace rooibos
statusString = chr(10)

indent = string(1, chr(9))
statusString += `${indent}${m.colorLines(rooibos.reporter.mocha.colors.brightPass, `${stats.passedCount} passed`)} ${m.colorLines(rooibos.reporter.mocha.colors.light, ` (${stats.time}ms)`)}`
statusString += `${indent}${m.colorLines(rooibos.reporters.mocha.colors.brightPass, `${stats.passedCount} passed`)} ${m.colorLines(rooibos.reporters.mocha.colors.light, ` (${stats.time}ms)`)}`

if stats.crashedCount > 0
statusString += chr(10) + m.colorLines(rooibos.reporter.mocha.colors.fail, `${indent}${stats.crashedCount} crashed`)
statusString += chr(10) + m.colorLines(rooibos.reporters.mocha.colors.fail, `${indent}${stats.crashedCount} crashed`)
end if

if stats.failedCount > 0
statusString += chr(10) + m.colorLines(rooibos.reporter.mocha.colors.fail, `${indent}${stats.failedCount} failing`)
statusString += chr(10) + m.colorLines(rooibos.reporters.mocha.colors.fail, `${indent}${stats.failedCount} failing`)
end if

if stats.ignoredCount > 0
statusString += chr(10) + m.colorLines(rooibos.reporter.mocha.colors.pending, `${indent}${stats.ignoredCount} skipped`)
statusString += chr(10) + m.colorLines(rooibos.reporters.mocha.colors.pending, `${indent}${stats.ignoredCount} skipped`)
end if

statusString += chr(10)
Expand Down Expand Up @@ -217,10 +217,10 @@ namespace rooibos
cleanUp = function(line, m)
indent = " "
if line.left(1) = "+"
return indent + m.colorLines(rooibos.reporter.mocha.colors.diffAdded, line)
return indent + m.colorLines(rooibos.reporters.mocha.colors.diffAdded, line)
end if
if line.left(1) = "-"
return indent + m.colorLines(rooibos.reporter.mocha.colors.diffRemoved, line)
return indent + m.colorLines(rooibos.reporters.mocha.colors.diffRemoved, line)
end if
if CreateObject("roRegex", "@@", "").isMatch(line)
return "--"
Expand All @@ -234,7 +234,7 @@ namespace rooibos
msg = m.createPatch("string", actual, expected)
lines = msg.split(chr(10)).slice(5)

final = chr(10) + " " + m.colorLines(rooibos.reporter.mocha.colors.diffAdded, "+ expected") + " " + m.colorLines(rooibos.reporter.mocha.colors.diffRemoved, "- actual")
final = chr(10) + " " + m.colorLines(rooibos.reporters.mocha.colors.diffAdded, "+ expected") + " " + m.colorLines(rooibos.reporters.mocha.colors.diffRemoved, "- actual")
final += chr(10) + chr(10)

cleanLines = []
Expand Down Expand Up @@ -323,7 +323,7 @@ namespace rooibos

' Diff two sets of strings, comparing them line by line
function diffLines(oldStr, newStr, callback)
lineDiff = rooibos.reporter.mocha.new_lineDiff()
lineDiff = rooibos.reporters.mocha.new_lineDiff()

return lineDiff.diff(oldStr, newStr, {
ignoreCase: false,
Expand Down Expand Up @@ -402,7 +402,7 @@ namespace rooibos
curRange.append(m.contextLines(lines))
else
' end the range and output
contextSize = rooibos.reporter.mocha.min(lines.count(), options.context)
contextSize = rooibos.reporters.mocha.min(lines.count(), options.context)
curRange.append(m.contextLines(lines.slice(0, contextSize)))

hunk = {
Expand Down Expand Up @@ -431,7 +431,7 @@ namespace rooibos
if hunk.lines[i].endsWith(chr(10))
hunk.lines[i] = hunk.lines[i].mid(0, len(hunk.lines[i]) - 1)
else
hunk.lines = rooibos.reporter.mocha.arraySplice(hunk.lines, i + 1, 0, ["\ No newline at end of file"])
hunk.lines = rooibos.reporters.mocha.arraySplice(hunk.lines, i + 1, 0, ["\ No newline at end of file"])
i++ ' Skip the line we just added, then continue iterating
end if
end for
Expand All @@ -449,7 +449,7 @@ namespace rooibos
' Split `text` into an array of lines, including the trailing newline character (where present)
function splitLines(text)
hasTrailingNl = text.endsWith(chr(10))
result = rooibos.reporter.mocha.arrayMap(text.split(chr(10)), function(line, _ = invalid)
result = rooibos.reporters.mocha.arrayMap(text.split(chr(10)), function(line, _ = invalid)
return line + chr(10)
end function)
if hasTrailingNl
Expand All @@ -462,15 +462,15 @@ namespace rooibos
end function

function contextLines(lines)
return rooibos.reporter.mocha.arrayMap(lines, function(entry, _ = invalid)
return rooibos.reporters.mocha.arrayMap(lines, function(entry, _ = invalid)
return " " + entry
end function)
end function

' Return a unified patch file contents from a structured patch
function formatPatch(diff, _ = invalid)
if type(diff) = "roArray"
return rooibos.reporter.mocha.arrayMap(diff, m.formatPatch).join(chr(10))
return rooibos.reporters.mocha.arrayMap(diff, m.formatPatch).join(chr(10))
end if

ret = []
Expand Down Expand Up @@ -512,7 +512,7 @@ namespace rooibos

end class

namespace reporter
namespace reporters
namespace mocha
enum colors
pass = "90"
Expand Down Expand Up @@ -607,13 +607,13 @@ namespace rooibos
editLength = 1
maxEditLength = newLen + oldLen
if options.maxEditLength <> invalid
maxEditLength = rooibos.reporter.mocha.min(maxEditLength, options.maxEditLength)
maxEditLength = rooibos.reporters.mocha.min(maxEditLength, options.maxEditLength)
end if

maxExecutionTime = Infinity
abortAfterTimestamp = CreateObject("roDateTime").asSeconds() + maxExecutionTime

bestPath = rooibos.reporter.mocha.new_objectArray()
bestPath = rooibos.reporters.mocha.new_objectArray()

' bestPath = [{ oldPos: -1, lastComponent: invalid }]
bestPath.set(0, { oldPos: -1, lastComponent: invalid })
Expand All @@ -624,7 +624,7 @@ namespace rooibos
if bestPath.get(0).oldPos + 1 >= oldLen and newPos + 1 >= newLen
' Identity per the equality and tokenizer
' return m.done(buildValues(m, bestPath[0].lastComponent, newString, oldString, m.useLongestToken))
return m.done(rooibos.reporter.mocha.buildValues(m, bestPath.get(0).lastComponent, newString, oldString, m.useLongestToken), options)
return m.done(rooibos.reporters.mocha.buildValues(m, bestPath.get(0).lastComponent, newString, oldString, m.useLongestToken), options)
end if

' Once we hit the right edge of the edit graph on some diagonal k, we can
Expand Down Expand Up @@ -673,10 +673,10 @@ namespace rooibos

' Main worker method. checks all permutations of a given edit length for acceptance.
execEditLength: function(execEditParams)
startingDiagonalPath = rooibos.reporter.mocha.max(execEditParams.minDiagonalToConsider, -execEditParams.editLength)
diagonalPath = rooibos.reporter.mocha.max(execEditParams.minDiagonalToConsider, -execEditParams.editLength)
startingDiagonalPath = rooibos.reporters.mocha.max(execEditParams.minDiagonalToConsider, -execEditParams.editLength)
diagonalPath = rooibos.reporters.mocha.max(execEditParams.minDiagonalToConsider, -execEditParams.editLength)
' while diagonalPath <= min(execEditParams.maxDiagonalToConsider, execEditParams.editLength)
for diagonalPath = rooibos.reporter.mocha.max(execEditParams.minDiagonalToConsider, -execEditParams.editLength) to rooibos.reporter.mocha.min(execEditParams.maxDiagonalToConsider, execEditParams.editLength) step 2
for diagonalPath = rooibos.reporters.mocha.max(execEditParams.minDiagonalToConsider, -execEditParams.editLength) to rooibos.reporters.mocha.min(execEditParams.maxDiagonalToConsider, execEditParams.editLength) step 2
removePath = execEditParams.bestPath.get(diagonalPath - 1)
addPath = execEditParams.bestPath.get(diagonalPath + 1)
if removePath <> invalid
Expand Down Expand Up @@ -711,15 +711,15 @@ namespace rooibos

if basePath.oldPos + 1 >= execEditParams.oldLen and newPos + 1 >= execEditParams.newLen
' If we have hit the end of both strings, then we are done
execEditParams.ret = m.done(rooibos.reporter.mocha.buildValues(m, basePath.lastComponent, execEditParams.newString, execEditParams.oldString, m.useLongestToken), execEditParams.options)
execEditParams.ret = m.done(rooibos.reporters.mocha.buildValues(m, basePath.lastComponent, execEditParams.newString, execEditParams.oldString, m.useLongestToken), execEditParams.options)
return execEditParams
else
execEditParams.bestPath.set(diagonalPath, basePath)
if basePath.oldPos + 1 >= execEditParams.oldLen
execEditParams.maxDiagonalToConsider = rooibos.reporter.mocha.min(execEditParams.maxDiagonalToConsider, diagonalPath - 1)
execEditParams.maxDiagonalToConsider = rooibos.reporters.mocha.min(execEditParams.maxDiagonalToConsider, diagonalPath - 1)
end if
if newPos + 1 >= execEditParams.newLen
execEditParams.minDiagonalToConsider = rooibos.reporter.mocha.max(execEditParams.minDiagonalToConsider, diagonalPath + 1)
execEditParams.minDiagonalToConsider = rooibos.reporters.mocha.max(execEditParams.minDiagonalToConsider, diagonalPath + 1)
end if
end if
end for
Expand Down Expand Up @@ -855,7 +855,7 @@ namespace rooibos
end function

function new_lineDiff()
lineDiff = rooibos.reporter.mocha.new_Diff()
lineDiff = rooibos.reporters.mocha.new_Diff()
lineDiff.tokenize = function(value, options)
if options.stripTrailingCr = true
' remove one \r before \n to match GNU diff's --strip-trailing-cr behavior
Expand Down Expand Up @@ -912,7 +912,7 @@ namespace rooibos
rightPart = rightPart.mid(0, len(rightPart) - 1)
end if
end if
return rooibos.reporter.mocha.new_Diff().equals(leftPart, rightPart, options)
return rooibos.reporters.mocha.new_Diff().equals(leftPart, rightPart, options)
end function

return lineDiff
Expand Down
10 changes: 5 additions & 5 deletions framework/src/source/TestRunner.bs
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,16 @@ namespace rooibos
end function

private function getTestReporters()
reporters = []
testReporters = []
for each factory in m.config.reporters
if rooibos.common.isFunction(factory)
reporters.push(factory(m))
testReporters.push(factory(m))
end if
end for
if reporters.isEmpty()
reporters.push(new rooibos.ConsoleTestReporter(m))
if testReporters.isEmpty()
testReporters.push(new rooibos.ConsoleTestReporter(m))
end if
return reporters
return testReporters
end function

end class
Expand Down

0 comments on commit aca45ca

Please sign in to comment.