Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Sep 29, 2023
1 parent 84fa106 commit 0afae62
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 46 deletions.
38 changes: 0 additions & 38 deletions src/LogOutputManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,18 @@ import { util } from 'brighterscript';
describe('LogOutputManager ', () => {
let logOutputManagerMock: Sinon.SinonMock;
let logOutputManager: LogOutputManager;
let languagesMock: Sinon.SinonMock;
let outputChannelMock: Sinon.SinonMock;
let logDocumentLinkProviderMock: Sinon.SinonMock;
let collectionMock: Sinon.SinonMock;
let declarationProviderMock: Sinon.SinonMock;

beforeEach(() => {
sinon.restore();
const outputChannel = new vscode.OutputChannel();
const debugCollection = new vscode.DebugCollection();
const logDocumentLinkProvider = new LogDocumentLinkProvider();
const declarationProvider = new DeclarationProvider();
outputChannelMock = sinon.mock(outputChannel);
logDocumentLinkProviderMock = sinon.mock(logDocumentLinkProvider);
collectionMock = sinon.mock(debugCollection);
declarationProviderMock = sinon.mock(declarationProvider);
languagesMock = sinon.mock(vscode.languages);
languagesMock.expects('createDiagnosticCollection').returns(debugCollection);
collectionMock.expects('clear');
logOutputManager = new LogOutputManager(outputChannel, vscode.context, logDocumentLinkProvider, declarationProvider);
logOutputManagerMock = sinon.mock(logOutputManager);
});
Expand All @@ -55,73 +48,49 @@ describe('LogOutputManager ', () => {
});

it('tests onDidStartDebugSession clear flag', () => {
collectionMock.expects('clear').once();
logOutputManager.isClearingConsoleOnChannelStart = true;
logOutputManager.onDidStartDebugSession();
outputChannelMock.verify();
collectionMock.verify();
logOutputManagerMock.verify();
});

it('tests onDidStartDebugSession no clear flag', () => {
collectionMock.expects('clear').never();
logOutputManager.isClearingConsoleOnChannelStart = false;
logOutputManager.onDidStartDebugSession();
outputChannelMock.verify();
collectionMock.verify();
logOutputManagerMock.verify();
});

it('tests onDidReceiveDebugSessionCustomEvent - LaunchStartEvent - clear flag', async () => {
collectionMock.expects('clear').once();
logOutputManager.isClearingOutputOnLaunch = true;
await logOutputManager.onDidReceiveDebugSessionCustomEvent({ event: 'LaunchStartEvent' });
outputChannelMock.verify();
collectionMock.verify();
logOutputManagerMock.verify();
});

it('tests onDidReceiveDebugSessionCustomEvent - LaunchStartEvent - no clear flag', async () => {
collectionMock.expects('clear').never();
logOutputManager.isClearingOutputOnLaunch = false;
await logOutputManager.onDidReceiveDebugSessionCustomEvent(new LaunchStartEvent({} as any));
outputChannelMock.verify();
collectionMock.verify();
logOutputManagerMock.verify();
});

it('tests onDidReceiveDebugSessionCustomEvent - LogOutputEvent', async () => {
outputChannelMock.expects('appendLine').once();
await logOutputManager.onDidReceiveDebugSessionCustomEvent(new LogOutputEvent('test 1'));
outputChannelMock.verify();
collectionMock.verify();
logOutputManagerMock.verify();
});

it('tests onDidReceiveDebugSessionCustomEvent - error - empty', async () => {
await logOutputManager.onDidReceiveDebugSessionCustomEvent({ event: '', body: {} });
outputChannelMock.verify();
collectionMock.verify();
logOutputManagerMock.verify();
});

it('tests onDidReceiveDebugSessionCustomEvent - error - undefined', async () => {
await logOutputManager.onDidReceiveDebugSessionCustomEvent({ event: '' });
outputChannelMock.verify();
collectionMock.verify();
logOutputManagerMock.verify();
});

it('tests onDidReceiveDebugSessionCustomEvent - errors', async () => {
logOutputManagerMock.expects('addDiagnosticForError').once();
let compileErrors: BSDebugDiagnostic[] = [{
path: 'path1',
message: 'message1',
range: util.createRange(1, 2, 3, 4)
}];
await logOutputManager.onDidReceiveDebugSessionCustomEvent(new DiagnosticsEvent(compileErrors));
outputChannelMock.verify();
collectionMock.verify();
logOutputManagerMock.verify();
});

Expand All @@ -130,13 +99,11 @@ describe('LogOutputManager ', () => {
logOutputManager.appendLine('test1', true);
logOutputManager.appendLine('test2', true);
logOutputManager.appendLine('test3', true);
collectionMock.expects('clear').once();
outputChannelMock.expects('clear').once();

logOutputManager.clearOutput();

outputChannelMock.verify();
collectionMock.verify();
});

it('tests output indexes are cleared', () => {
Expand All @@ -151,7 +118,6 @@ describe('LogOutputManager ', () => {
logOutputManager.markOutput();

logOutputManagerMock.verify();
collectionMock.verify();

logOutputManagerMock = sinon.mock(logOutputManager);
logOutputManager.clearOutput();
Expand All @@ -164,7 +130,6 @@ describe('LogOutputManager ', () => {
logOutputManager.markOutput();

logOutputManagerMock.verify();
collectionMock.verify();

});
});
Expand All @@ -175,7 +140,6 @@ describe('LogOutputManager ', () => {
.withExactArgs('test1').once();
logOutputManager.appendLine('test1', true);
outputChannelMock.verify();
collectionMock.verify();
});

it('splits multiple lines', () => {
Expand All @@ -187,7 +151,6 @@ describe('LogOutputManager ', () => {
logOutputManager.appendLine('test1\ntest2', true);

outputChannelMock.verify();
collectionMock.verify();
});
});

Expand All @@ -204,7 +167,6 @@ describe('LogOutputManager ', () => {
logOutputManager.markOutput();

logOutputManagerMock.verify();
collectionMock.verify();
});
});

Expand Down
10 changes: 2 additions & 8 deletions src/managers/DiagnosticManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,21 @@ export class DiagnosticManager {
}

public async addDiagnosticForError(path: string, diagnostics: BSDebugDiagnostic[]) {
//TODO get the actual folder
let documentUri: vscode.Uri;
let uri = vscode.Uri.file(path);
let doc = await vscode.workspace.openTextDocument(uri); // calls back
let doc = await vscode.workspace.openTextDocument(uri);
if (doc !== undefined) {
documentUri = doc.uri;
}
// console.log("got " + documentUri);

//debug crap - for some reason - using this URI works - using the one from the path does not :()
// const document = vscode.window.activeTextEditor.document;
// const currentDocumentUri = document.uri;
// console.log("currentDocumentUri " + currentDocumentUri);
if (documentUri !== undefined) {
let result: vscode.Diagnostic[] = [];
for (const diagnostic of diagnostics) {
result.push({
code: diagnostic.code,
message: `From debugger: ${diagnostic.message}`,
source: diagnostic.source,
severity: diagnostic.severity,
severity: diagnostic.severity as vscode.DiagnosticSeverity,
tags: diagnostic.tags,
range: new vscode.Range(
new vscode.Position(diagnostic.range.start.line, diagnostic.range.start.character),
Expand Down

0 comments on commit 0afae62

Please sign in to comment.