Skip to content

Commit

Permalink
reinstates erroneously disabled try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
georgejecook committed Oct 25, 2023
1 parent 8a7469a commit 276a73f
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions bsc-plugin/src/lib/rooibos/TestGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,43 +56,43 @@ export class TestGroup extends TestBlock {
//wrap with if is not fail
//add line number as last param
const transpileState = new BrsTranspileState(this.file);
// try {
let func = this.testSuite.classStatement.methods.find((m) => m.name.text.toLowerCase() === testCase.funcName.toLowerCase());
func.walk(brighterscript.createVisitor({
ExpressionStatement: (expressionStatement, parent, owner) => {
let callExpression = expressionStatement.expression as CallExpression;
if (brighterscript.isCallExpression(callExpression) && brighterscript.isDottedGetExpression(callExpression.callee)) {
let dge = callExpression.callee;
let isSub = isFunctionExpression(callExpression.parent.parent.parent) && callExpression.parent.parent.parent.functionType.kind === TokenKind.Sub;
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);
return expressionStatement;

} else {

if (dge.name.text === 'expectCalled' || dge.name.text === 'expectNotCalled') {
try {
let func = this.testSuite.classStatement.methods.find((m) => m.name.text.toLowerCase() === testCase.funcName.toLowerCase());
func.walk(brighterscript.createVisitor({
ExpressionStatement: (expressionStatement, parent, owner) => {
let callExpression = expressionStatement.expression as CallExpression;
if (brighterscript.isCallExpression(callExpression) && brighterscript.isDottedGetExpression(callExpression.callee)) {
let dge = callExpression.callee;
let isSub = isFunctionExpression(callExpression.parent.parent.parent) && callExpression.parent.parent.parent.functionType.kind === TokenKind.Sub;
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);
}
//TODO change this to editor.setProperty(parentObj, parentKey, new SourceNode()) once bsc supports it
overrideAstTranspile(editor, expressionStatement, '\n' + undent`
return expressionStatement;

} else {

if (dge.name.text === 'expectCalled' || dge.name.text === 'expectNotCalled') {
this.modifyModernRooibosExpectCallExpression(callExpression, editor, namespaceLookup);
}
//TODO change this to editor.setProperty(parentObj, parentKey, new SourceNode()) once bsc supports it
overrideAstTranspile(editor, expressionStatement, '\n' + undent`
m.currentAssertLineNumber = ${callExpression.range.start.line}
${callExpression.transpile(transpileState).join('')}
${noEarlyExit ? '' : `if m.currentResult?.isFail = true then m.done() : return ${isSub ? '' : 'invalid'}`}
` + '\n');
}
}
}
}
}
}), {
walkMode: brighterscript.WalkMode.visitStatementsRecursive
});
// } catch (e) {
// // console.log(e);
// // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
// diagnosticErrorProcessingFile(this.testSuite.file, e.message);
// }
}), {
walkMode: brighterscript.WalkMode.visitStatementsRecursive
});
} catch (e) {
// console.log(e);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
diagnosticErrorProcessingFile(this.testSuite.file, e.message);
}
}

private modifyModernRooibosExpectCallExpression(callExpression: CallExpression, editor: AstEditor, namespaceLookup: Map<string, NamespaceContainer>) {
Expand Down

0 comments on commit 276a73f

Please sign in to comment.