Skip to content

Commit

Permalink
Fixed more on device tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdp committed Jan 16, 2024
1 parent 4c3d753 commit b4024ee
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
48 changes: 40 additions & 8 deletions bsc-plugin/src/lib/rooibos/TestGroup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AstEditor, CallExpression, DottedGetExpression, NamespaceContainer } from 'brighterscript';
import { ArrayLiteralExpression, createInvalidLiteral, createStringLiteral, createToken, isDottedGetExpression, TokenKind, isFunctionExpression, Parser } from 'brighterscript';
import type { AstEditor, CallExpression, DottedGetExpression, Expression, NamespaceContainer, Scope } from 'brighterscript';
import { ArrayLiteralExpression, createInvalidLiteral, createStringLiteral, createToken, isDottedGetExpression, TokenKind, isFunctionExpression, Parser, ParseMode } from 'brighterscript';
import * as brighterscript from 'brighterscript';
import { BrsTranspileState } from 'brighterscript/dist/parser/BrsTranspileState';
import { diagnosticErrorProcessingFile } from '../utils/Diagnostics';
Expand Down Expand Up @@ -39,7 +39,6 @@ export class TestGroup extends TestBlock {
} else {
this.hasAsyncTests = testCase.isAsync;
}

}

public getTestCases(): TestCase[] {
Expand All @@ -51,6 +50,7 @@ export class TestGroup extends TestBlock {
//if assertion
//wrap with if is not fail
//add line number as last param
let scope = this.file.program.getFirstScopeForFile(this.file);
const transpileState = new BrsTranspileState(this.file);
try {
let func = this.testSuite.classStatement.methods.find((m) => m.name.text.toLowerCase() === testCase.funcName.toLowerCase());
Expand All @@ -63,16 +63,16 @@ export class TestGroup extends TestBlock {
let assertRegex = /(?:fail|assert(?:[a-z0-9]*)|expect(?:[a-z0-9]*)|stubCall)/i;
if (dge && assertRegex.test(dge.name.text)) {
if (dge.name.text === 'stubCall') {
this.modifyModernRooibosExpectCallExpression(callExpression, editor, namespaceLookup);
this.modifyModernRooibosExpectCallExpression(callExpression, editor, namespaceLookup, scope);
return expressionStatement;

} else {

if (dge.name.text === 'expectCalled' || dge.name.text === 'expectNotCalled') {
this.modifyModernRooibosExpectCallExpression(callExpression, editor, namespaceLookup);
this.modifyModernRooibosExpectCallExpression(callExpression, editor, namespaceLookup, scope);
}
if (dge.name.text === 'expectCalled' || dge.name.text === 'expectNotCalled') {
this.modifyModernRooibosExpectCallExpression(callExpression, editor, namespaceLookup);
this.modifyModernRooibosExpectCallExpression(callExpression, editor, namespaceLookup, scope);
}

if (!noEarlyExit) {
Expand All @@ -95,7 +95,7 @@ export class TestGroup extends TestBlock {
}
}

private modifyModernRooibosExpectCallExpression(callExpression: CallExpression, editor: AstEditor, namespaceLookup: Map<string, NamespaceContainer>) {
private modifyModernRooibosExpectCallExpression(callExpression: CallExpression, editor: AstEditor, namespaceLookup: Map<string, NamespaceContainer>, scope: Scope) {
let isNotCalled = false;
let isStubCall = false;

Expand All @@ -107,7 +107,7 @@ export class TestGroup extends TestBlock {
isNotCalled = nameText === 'expectNotCalled';
isStubCall = nameText === 'stubCall';

if (isStubCall && !brighterscript.isCallExpression(arg0)) {
if (isStubCall && this.shouldNotModifyStubCall(arg0, namespaceLookup, scope)) {
return;
}
editor.setProperty(callExpression.callee.name, 'text', `_${nameText}`);
Expand Down Expand Up @@ -198,6 +198,38 @@ export class TestGroup extends TestBlock {
}
}

private shouldNotModifyStubCall(arg0: Expression, namespaceLookup: Map<string, NamespaceContainer>, scope: Scope) {
if (brighterscript.isDottedGetExpression(arg0)) {
let nameParts = getAllDottedGetParts(arg0);
let name = nameParts.pop();
let functionName: string;

if (name) {
//is a namespace?
if (nameParts[0] && namespaceLookup.has(nameParts[0].toLowerCase())) {
//then this must be a namespace method
let fullPathName = nameParts.join('.').toLowerCase();
let ns = namespaceLookup.get(fullPathName);
if (!ns) {
//TODO this is an error condition!
}
nameParts.push(name);
functionName = nameParts.join('.').toLowerCase();
}
}

if (functionName && scope.getCallableByName(functionName)) {
return true;
}
} else if (brighterscript.isVariableExpression(arg0)) {
const functionName = arg0.getName(ParseMode.BrightScript).toLowerCase();
if (scope.getCallableByName(functionName)) {
return true;
}
}
return false;
}

public asText(): string {
let testCaseText = [...this.testCases.values()].filter((tc) => tc.isIncluded).map((tc) => tc.asText());

Expand Down
6 changes: 3 additions & 3 deletions bsc-plugin/src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ describe('RooibosPlugin', () => {
expect(statements[0]).to.be.instanceof(PrintStatement);
});

describe.skip('expectCalled transpilation', () => {
describe('expectCalled transpilation', () => {
it('correctly transpiles call funcs', async () => {
program.setFile('source/test.spec.bs', `
@suite
Expand Down Expand Up @@ -1125,7 +1125,7 @@ describe('RooibosPlugin', () => {
});
});

describe.skip('stubCall transpilation', () => {
describe('stubCall transpilation', () => {
it('correctly transpiles call funcs', async () => {
program.setFile('source/test.spec.bs', `
@suite
Expand Down Expand Up @@ -1267,7 +1267,7 @@ describe('RooibosPlugin', () => {
});
});

describe.skip('expectNotCalled transpilation', () => {
describe('expectNotCalled transpilation', () => {
it('correctly transpiles call funcs', async () => {
program.setFile('source/test.spec.bs', `
@suite
Expand Down

0 comments on commit b4024ee

Please sign in to comment.