Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed duplicate cur line injections #267

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 71 additions & 19 deletions bsc-plugin/src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,17 @@ describe('RooibosPlugin', () => {

it('ignores a test', () => {
program.setFile('source/test.spec.bs', `
@suite
class ATest
@describe("groupA")
@suite
class ATest
@describe("groupA")

@ignore
@it("is test1")
@ignore
@it("is test1")
function Test()
end function

end class
`);
end class
`);
program.validate();
expect(program.getDiagnostics()).to.be.empty;
expect(plugin.session.sessionInfo.groupsCount).to.equal(1);
Expand All @@ -210,21 +210,21 @@ describe('RooibosPlugin', () => {
program.setFile('source/test.spec.bs', `
@suite
class ATest
@describe("groupA")
@describe("groupA")

@it("is test1")
function Test_1()
end function
@it("is test1")
function Test_1()
end function

@describe("groupB")
@describe("groupB")

@it("is test1")
function Test_2()
end function
@it("is test1")
function Test_2()
end function

@it("is test2")
function Test_3()
end function
@it("is test2")
function Test_3()
end function

end class
`);
Expand Down Expand Up @@ -1614,6 +1614,58 @@ describe('RooibosPlugin', () => {
});
});

describe('currentAssertLineNumber transpilation', () => {
it('correctly transpiles currentAssertLineNumber with out duplications', async () => {
program.setFile('source/test.spec.bs', `
@suite
class ATest
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("tests AssertArrayContainsOnlyValuesOfType")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

@it("pass")
@params(["one", "two", "three"], "String")
@params([1, 2, 3], "Integer")
@params([true, true, false], "Boolean")
@params([[true, true], [false, false]], "Array")
@params([{ "test": 1 }, { "test": 1 }], "AssociativeArray")
function _(values, typeName)

m.assertArrayContainsOnlyValuesOfType(values, typeName)
isFail = m.currentResult.isFail

m.currentResult.Reset()

m.assertFalse(isFail)

end function
end class
`);
program.validate();
expect(program.getDiagnostics()).to.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun).to.not.be.empty;
await builder.transpile();
expect(
getTestFunctionContents()
).to.eql(undent`
m.currentAssertLineNumber = 15
m.assertArrayContainsOnlyValuesOfType(values, typeName)
if m.currentResult?.isFail = true then
m.done()
return invalid
end if
isFail = m.currentResult.isFail
m.currentResult.Reset()
m.currentAssertLineNumber = 20
m.assertFalse(isFail)
if m.currentResult?.isFail = true then
m.done()
return invalid
end if
`);
});
});

describe('expectNotCalled transpilation', () => {
it('correctly transpiles call funcs', async () => {
program.setFile('source/test.spec.bs', `
Expand Down Expand Up @@ -2210,7 +2262,7 @@ function getContents(filename: string) {
function getTestFunctionContents() {
const contents = getContents('test.spec.brs');

let [, result] = /instance.[\w_]+\s?\= function\(\)\s?([\S\s]*|.*)(?=^\s*end function\s+instance\.)/img.exec(contents);
let [, result] = /instance.[\w_]+\s?\= function\((?:[\w,\s]*)\)\s?([\S\s]*|.*)(?=^\s*end function\s+instance\.)/img.exec(contents);

return undent(result);
}
Expand Down
8 changes: 7 additions & 1 deletion bsc-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,16 @@ export class RooibosPlugin implements CompilerPlugin {
console.warn(`WARNING: testSuite "${testSuite.name}" is marked as noEarlyExit`);
}

const modifiedTestCases = new Set();
testSuite.addDataFunctions(event.editor as any);
for (let group of [...testSuite.testGroups.values()].filter((tg) => tg.isIncluded)) {
for (let testCase of [...group.testCases.values()].filter((tc) => tc.isIncluded)) {
group.modifyAssertions(testCase, noEarlyExit, event.editor as any, this.session.namespaceLookup, scope);
let caseName = group.testSuite.generatedNodeName + group.file.pkgPath + testCase.funcName;
if (!modifiedTestCases.has(caseName)) {
group.modifyAssertions(testCase, noEarlyExit, event.editor as any, this.session.namespaceLookup, scope);
modifiedTestCases.add(caseName);
}

}
}
}
Expand Down