Skip to content

Commit

Permalink
using logger instead of console.log
Browse files Browse the repository at this point in the history
  • Loading branch information
markwpearce committed Aug 19, 2024
1 parent 585c0ed commit d82dbb9
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 26 deletions.
5 changes: 3 additions & 2 deletions bsc-plugin/src/lib/rooibos/CodeCoverageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { RawCodeStatement } from './RawCodeStatement';
import { BrsTranspileState } from 'brighterscript/dist/parser/BrsTranspileState';
import { RawCodeExpression } from './RawCodeExpression';
import type { FileFactory } from './FileFactory';
import { RooibosLogPrefix } from '../utils/Diagnostics';

export enum CodeCoverageLineType {
noCode = 0,
Expand Down Expand Up @@ -44,7 +45,7 @@ export class CodeCoverageProcessor {
this.fileFactory = fileFactory;
try {
} catch (e) {
console.log('Error:', e.stack);
builder.logger.error(RooibosLogPrefix, 'Error:', e.stack);
}
}

Expand Down Expand Up @@ -76,7 +77,7 @@ export class CodeCoverageProcessor {
this.executableLines = new Map<number, Statement>();
this.processedStatements = new Set<Statement>();
this.astEditor = astEditor;
console.log('Processing file:', this.fileId, file.pkgPath);
file.program.logger.info(RooibosLogPrefix, 'Processing file for code coverage:', this.fileId, file.pkgPath);

file.ast.walk(createVisitor({
ForStatement: (ds, parent, owner, key) => {
Expand Down
5 changes: 3 additions & 2 deletions bsc-plugin/src/lib/rooibos/FileFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from 'path';
import * as fs from 'fs';
import * as fse from 'fs-extra';
import type { TestSuite } from './TestSuite';
import { RooibosLogPrefix } from '../utils/Diagnostics';

export class FileFactory {
private coverageComponentXmlTemplate: string;
Expand Down Expand Up @@ -135,7 +136,7 @@ export class FileFactory {
this.addedFrameworkFiles.push(file);
return file;
} catch (error) {
program.logger.error(`Error adding framework file: ${entry.dest} : ${error.message}`);
program.logger.error(RooibosLogPrefix, `Error adding framework file: ${entry.dest} : ${error.message}`);
}
}

Expand All @@ -146,7 +147,7 @@ export class FileFactory {
contents
);
} catch (error) {
program.logger.error(`Error adding framework file: ${path} : ${error.message}`);
program.logger.error(RooibosLogPrefix, `Error adding framework file: ${path} : ${error.message}`);
}
}
}
4 changes: 2 additions & 2 deletions bsc-plugin/src/lib/rooibos/MockUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { RooibosConfig } from './RooibosConfig';
import type { FileFactory } from './FileFactory';
import undent from 'undent';
import type { RooibosSession } from './RooibosSession';
import { diagnosticErrorProcessingFile } from '../utils/Diagnostics';
import { diagnosticErrorProcessingFile, RooibosLogPrefix } from '../utils/Diagnostics';
import type { TestCase } from './TestCase';
import type { TestSuite } from './TestSuite';
import { functionRequiresReturnValue, getAllDottedGetParts, getFileLookups, getScopeForSuite } from './Utils';
Expand Down Expand Up @@ -167,7 +167,7 @@ export class MockUtil {
walkMode: brighterscript.WalkMode.visitStatementsRecursive
});
} catch (e) {
this.builder.program.logger.error('Error processing global method mocks', e);
this.builder.program.logger.error(RooibosLogPrefix, 'Error processing global method mocks', e);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
diagnosticErrorProcessingFile(testSuite.file, e.message);
}
Expand Down
6 changes: 3 additions & 3 deletions bsc-plugin/src/lib/rooibos/RooibosSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SessionInfo } from './RooibosSessionInfo';
import { TestSuiteBuilder } from './TestSuiteBuilder';
import type { FileFactory } from './FileFactory';
import type { TestSuite } from './TestSuite';
import { diagnosticErrorNoMainFound as diagnosticWarnNoMainFound, diagnosticNoStagingDir } from '../utils/Diagnostics';
import { diagnosticErrorNoMainFound as diagnosticWarnNoMainFound, diagnosticNoStagingDir, RooibosLogPrefix } from '../utils/Diagnostics';
import undent from 'undent';
import * as fsExtra from 'fs-extra';
import type { MockUtil } from './MockUtil';
Expand Down Expand Up @@ -47,7 +47,7 @@ export class RooibosSession {
const resultFiles = this.createNodeFiles(program);

if (this.config.isGlobalMethodMockingEnabled && this.config.isGlobalMethodMockingEfficientMode) {
program.logger.info('Efficient global stubbing is enabled');
program.logger.info(RooibosLogPrefix, 'Efficient global stubbing is enabled');
this.namespaceLookup = this.getNamespaces(program);
for (let testSuite of this.sessionInfo.testSuitesToRun) {
mockUtil.gatherGlobalMethodMocks(testSuite);
Expand Down Expand Up @@ -121,7 +121,7 @@ export class RooibosSession {
if (!mainFunction) {
diagnosticWarnNoMainFound(files[0] as BrsFile);
if (!this._builder.options.stagingDir) {
this._builder.program.logger.error('Rooibos requires that stagingDir bsconfig option is set');
this._builder.program.logger.error(RooibosLogPrefix, 'Rooibos requires that stagingDir bsconfig option is set');
diagnosticNoStagingDir(files[0] as BrsFile);
} else {
const filePath = path.join(this._builder.options.stagingDir, 'source/rooibosMain.brs');
Expand Down
3 changes: 3 additions & 0 deletions bsc-plugin/src/lib/utils/Diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { DiagnosticSeverity, Range, util } from 'brighterscript';

import type { AnnotationType, RooibosAnnotation } from '../rooibos/Annotation';


export const RooibosLogPrefix = '[Rooibos]';

function addDiagnostic(
file: BrsFile,
code: number,
Expand Down
5 changes: 0 additions & 5 deletions bsc-plugin/src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,6 @@ describe('RooibosPlugin', () => {
program.setFile('source/test.spec.bs', testSource);
program.validate();
await builder.build();
console.log(builder.getDiagnostics());
expect(builder.getDiagnostics()).to.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun).to.not.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun[0].name).to.equal('a');
Expand All @@ -1950,7 +1949,6 @@ describe('RooibosPlugin', () => {
program.setFile('source/test.spec.bs', testSource);
program.validate();
await builder.build();
console.log(builder.getDiagnostics());
expect(builder.getDiagnostics()).to.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun).to.not.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun[0].name).to.equal('b');
Expand All @@ -1961,7 +1959,6 @@ describe('RooibosPlugin', () => {
program.setFile('source/test.spec.bs', testSource);
program.validate();
await builder.build();
console.log(builder.getDiagnostics());
expect(builder.getDiagnostics()).to.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun).to.not.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun[0].name).to.equal('b');
Expand All @@ -1973,7 +1970,6 @@ describe('RooibosPlugin', () => {
program.setFile('source/test.spec.bs', testSource);
program.validate();
await builder.build();
console.log(builder.getDiagnostics());
expect(builder.getDiagnostics()).to.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun).to.be.empty;
});
Expand All @@ -1983,7 +1979,6 @@ describe('RooibosPlugin', () => {
program.setFile('source/test.spec.bs', testSource);
program.validate();
await builder.build();
console.log(builder.getDiagnostics());
expect(builder.getDiagnostics()).to.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun).to.not.be.empty;
expect(plugin.session.sessionInfo.testSuitesToRun[0].name).to.equal('a');
Expand Down
8 changes: 3 additions & 5 deletions bsc-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import * as minimatch from 'minimatch';
import * as path from 'path';
import { MockUtil } from './lib/rooibos/MockUtil';
import { getScopeForSuite } from './lib/rooibos/Utils';
import { RooibosLogPrefix } from './lib/utils/Diagnostics';

export class RooibosPlugin implements CompilerPlugin {

Expand Down Expand Up @@ -137,15 +138,14 @@ export class RooibosPlugin implements CompilerPlugin {
if (!(isBrsFile(file) || isXmlFile(file)) || this.shouldSkipFile(file)) {
continue;
}
// console.log('afp', file.pkgPath);
if (util.pathToUri(file.srcPath).includes('/rooibos/bsc-plugin/dist/framework')) {
// eslint-disable-next-line @typescript-eslint/dot-notation
return;
}
if (this.fileFactory.isIgnoredFile(file) || !this.shouldSearchInFileForTests(file)) {
return;
}
console.log('processing ', file.pkgPath);
event.program.logger.log(RooibosLogPrefix, 'Processing test file', file.pkgPath);

if (isBrsFile(file)) {
// Add the node test component so brighter script can validate the test files
Expand Down Expand Up @@ -178,7 +178,7 @@ export class RooibosPlugin implements CompilerPlugin {
const scope = getScopeForSuite(testSuite);
let noEarlyExit = testSuite.annotation.noEarlyExit;
if (noEarlyExit) {
event.program.logger.warn(`TestSuite "${testSuite.name}" is marked as noEarlyExit`);
event.program.logger.warn(RooibosLogPrefix, `TestSuite "${testSuite.name}" is marked as noEarlyExit`);
}

const modifiedTestCases = new Set();
Expand Down Expand Up @@ -211,7 +211,6 @@ export class RooibosPlugin implements CompilerPlugin {
}

afterProgramValidate(event: AfterProgramValidateEvent) {
// console.log('bpv');
this.session.updateSessionStats();
for (let testSuite of [...this.session.sessionInfo.testSuites.values()]) {
testSuite.validate();
Expand All @@ -233,7 +232,6 @@ export class RooibosPlugin implements CompilerPlugin {
}
}
}
// console.log('including ', file.pkgPath);
return true;
}
shouldAddCodeCoverageToFile(file: BscFile) {
Expand Down
11 changes: 4 additions & 7 deletions framework/src/source/TestGroup.bs
Original file line number Diff line number Diff line change
Expand Up @@ -200,27 +200,24 @@ namespace rooibos
m.testSuite.testGroupDone()
end function

private function runSuiteFunction(methodName, defaultMethodName, test = invalid)
private function runSuiteFunction(methodName as string, defaultMethodName as string, testInstance = invalid as Test) as boolean

if methodName = invalid or methodName = ""
methodName = defaultMethodName
end if
if m.testSuite.catchCrashes and not m.testSuite.noCatch and not (test <> invalid and test.noCatch)
if m.testSuite.catchCrashes and not m.testSuite.noCatch and not (testInstance <> invalid and testInstance.noCatch)
try
m.testSuite[methodName]()
return true
catch error
if test <> invalid
'bs:disable-next-line
test.result.crash("function " + methodName + "crashed!", error)
if testInstance <> invalid
testInstance.result.crash("function " + methodName + "crashed!", error)
end if
end try
else
m.testSuite[methodName]()
return true
end if

'bs:disable-next-line
return false
end function

Expand Down

0 comments on commit d82dbb9

Please sign in to comment.