Skip to content

Commit

Permalink
fix(test): Tests fixed on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
prb28 committed Sep 16, 2018
1 parent c8b874d commit 0b5f020
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 100 deletions.
8 changes: 4 additions & 4 deletions src/execHelper.ts
@@ -1,7 +1,7 @@
import * as cp from 'child_process';
import * as vscode from 'vscode';
import * as path from 'path';
import { ExtensionState } from './extensionState';
import { ExtensionState } from './extension';

export class ICheckResult {
file: string = "";
Expand All @@ -27,7 +27,7 @@ export class ExecutorHelper {
* @param parser Parser for the output
*/
runTool(args: string[], cwd: string | null, severity: string, useStdErr: boolean, cmd: string, env: any, printUnexpectedOutput: boolean, parser: ExecutorParser | null, token?: vscode.CancellationToken): Promise<ICheckResult[]> {
let outputChannel = ExtensionState.getInstance().getStatusManager().outputChannel;
let outputChannel = ExtensionState.getCurrent().getStatusManager().outputChannel;
let p: cp.ChildProcess;
if (token) {
token.onCancellationRequested(() => {
Expand Down Expand Up @@ -160,8 +160,8 @@ export class ExecutorHelper {

diagnosticMap.forEach((diagMap, file) => {
const fileUri = vscode.Uri.parse(file);
let warningDiagnosticCollection = ExtensionState.getInstance().getWarningDiagnosticCollection();
let errorDiagnosticCollection = ExtensionState.getInstance().getErrorDiagnosticCollection();
let warningDiagnosticCollection = ExtensionState.getCurrent().getWarningDiagnosticCollection();
let errorDiagnosticCollection = ExtensionState.getCurrent().getErrorDiagnosticCollection();
if (diagnosticSeverity === undefined || diagnosticSeverity === vscode.DiagnosticSeverity.Error) {
const newErrors = diagMap.get(vscode.DiagnosticSeverity.Error);
let existingWarnings = warningDiagnosticCollection.get(fileUri);
Expand Down
69 changes: 67 additions & 2 deletions src/extension.ts
@@ -1,7 +1,6 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import { ExtensionState } from './extensionState';
import { M68kFormatter } from './formatter';
import { M68kHoverProvider } from './hover';
import { M86kColorProvider } from './color';
Expand All @@ -10,6 +9,10 @@ import { VASMController } from './vasm';
import { FsUAEDebugSession } from './fsUAEDebug';
import * as Net from 'net';
import { RunFsUAENoDebugSession } from './runFsUAENoDebug';
import { Calc } from './calc';
import { VASMCompiler } from './vasm';
import { StatusManager } from "./status";
import { Disassembler } from './disassemble';

import { M68kDefinitionProvider } from './definitionProvider';

Expand All @@ -23,10 +26,65 @@ export const AMIGA_ASM_MODE: vscode.DocumentFilter = { language: 'm68k', scheme:
*/
const EMBED_DEBUG_ADAPTER = true;

export class ExtensionState {
private compiler: VASMCompiler | undefined;
private errorDiagnosticCollection: vscode.DiagnosticCollection | undefined;
private warningDiagnosticCollection: vscode.DiagnosticCollection | undefined;
private statusManager: StatusManager | undefined;
private calc: Calc | undefined;
private disassembler: Disassembler | undefined;
public getErrorDiagnosticCollection(): vscode.DiagnosticCollection {
if (this.errorDiagnosticCollection === undefined) {
this.errorDiagnosticCollection = vscode.languages.createDiagnosticCollection('m68k-error');
}
return this.errorDiagnosticCollection;
}
public getWarningDiagnosticCollection(): vscode.DiagnosticCollection {
if (this.warningDiagnosticCollection === undefined) {
this.warningDiagnosticCollection = vscode.languages.createDiagnosticCollection('m68k-warning');
}
return this.warningDiagnosticCollection;
}
public getStatusManager(): StatusManager {
if (this.statusManager === undefined) {
this.statusManager = new StatusManager();
}
return this.statusManager;
}
public getCalc(): Calc {
if (this.calc === undefined) {
this.calc = new Calc();
}
return this.calc;
}
public getCompiler(): VASMCompiler {
if (this.compiler === undefined) {
this.compiler = new VASMCompiler();
}
return this.compiler;
}
public getDisassembler(): Disassembler {
if (this.disassembler === undefined) {
this.disassembler = new Disassembler();
}
return this.disassembler;
}
public static getCurrent(): ExtensionState {
// activate the extension
let ext = vscode.extensions.getExtension('prb28.amiga-assembly');
if (ext) {
return ext.exports.getState();
}
return new ExtensionState();
}
}

const state = new ExtensionState();

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
let state = ExtensionState.getInstance();
context.globalState.update('state', state);
// Preparing the status manager
let statusManager = state.getStatusManager();
statusManager.showStatus("Build", 'amiga-assembly.build-vasm-workspace', "Build Workspace");
Expand Down Expand Up @@ -143,6 +201,13 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('fs-uae-run', runProvider));
context.subscriptions.push(runProvider);
statusManager.outputChannel.appendLine("------> done");

let api = {
getState(): ExtensionState {
return state;
}
};
return api;
}

export function deactivate() {
Expand Down
58 changes: 0 additions & 58 deletions src/extensionState.ts

This file was deleted.

10 changes: 6 additions & 4 deletions src/test/execHelper.test.ts
Expand Up @@ -3,15 +3,15 @@ import * as vscode from 'vscode';
import * as cp from 'child_process';
import { reset, capture, spy, verify, anyString, instance, when, anything, mock, resetCalls } from 'ts-mockito/lib/ts-mockito';
import { ExecutorHelper, ExecutorParser, ICheckResult } from '../execHelper';
import { ExtensionState } from '../extensionState';
import { ExtensionState } from '../extension';
import { DummyTextDocument } from './dummy';

describe("Executor Tests", function () {
let spiedOutputChannel: vscode.OutputChannel;
before(() => {
// Opening file to activate the extension
const newFile = vscode.Uri.parse("untitled://./exe.s");
return vscode.window.showTextDocument(newFile).then(() => { spiedOutputChannel = spy(ExtensionState.getInstance().getStatusManager().outputChannel); });
return vscode.window.showTextDocument(newFile).then(() => { spiedOutputChannel = spy(ExtensionState.getCurrent().getStatusManager().outputChannel); });
});
it("Should execute a command and parse stdout", async () => {
resetCalls(spiedOutputChannel);
Expand Down Expand Up @@ -63,15 +63,17 @@ describe("Executor Tests", function () {
});
describe("Diagnostics handle", () => {
let ex: ExecutorHelper;
let errorDiagnosticCollection = ExtensionState.getInstance().getErrorDiagnosticCollection();
let warningDiagnosticCollection = ExtensionState.getInstance().getWarningDiagnosticCollection();
let errorDiagnosticCollection: vscode.DiagnosticCollection;
let warningDiagnosticCollection: vscode.DiagnosticCollection;
let spiedErrorDiagnosticCollection: vscode.DiagnosticCollection;
let spiedWarningDiagnosticCollection: vscode.DiagnosticCollection;
let error: ICheckResult;
let warning: ICheckResult;
let errors: Array<ICheckResult>;
let document: DummyTextDocument;
beforeEach(() => {
errorDiagnosticCollection = ExtensionState.getCurrent().getErrorDiagnosticCollection();
warningDiagnosticCollection = ExtensionState.getCurrent().getWarningDiagnosticCollection();
errorDiagnosticCollection.clear();
warningDiagnosticCollection.clear();
ex = new ExecutorHelper();
Expand Down
10 changes: 5 additions & 5 deletions src/test/extension.test.ts
Expand Up @@ -9,7 +9,7 @@ import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs';
import { spy, verify, when, anything, resetCalls, mock, instance } from 'ts-mockito/lib/ts-mockito';
import { ExtensionState } from '../extensionState';
import { ExtensionState } from '../extension';
import { Capstone } from '../capstone';

// Defines a Mocha test suite to group tests of similar kind together
Expand Down Expand Up @@ -65,7 +65,7 @@ describe("Global Extension Tests", function () {
});
describe("Build commands", function () {
it("Should build the workspace on command", async () => {
let state = ExtensionState.getInstance();
let state = ExtensionState.getCurrent();
let spiedCompiler = spy(state.getCompiler());
let spiedStatus = spy(state.getStatusManager());
when(spiedCompiler.buildWorkspace()).thenCall(() => { return Promise.resolve(); });
Expand All @@ -84,7 +84,7 @@ describe("Global Extension Tests", function () {
verify(spiedStatus.onError("nope")).once();
});
it("Should build the current document on command", async () => {
let state = ExtensionState.getInstance();
let state = ExtensionState.getCurrent();
let spiedCompiler = spy(state.getCompiler());
let spiedStatus = spy(state.getStatusManager());
when(spiedCompiler.buildCurrentEditorFile()).thenCall(() => { return Promise.resolve(); });
Expand All @@ -102,7 +102,7 @@ describe("Global Extension Tests", function () {
verify(spiedStatus.onError("nope")).once();
});
it("Should clean the current workspace on command", async () => {
let state = ExtensionState.getInstance();
let state = ExtensionState.getCurrent();
let spiedCompiler = spy(state.getCompiler());
let spiedStatus = spy(state.getStatusManager());
when(spiedCompiler.cleanWorkspace()).thenCall(() => { return Promise.resolve(); });
Expand All @@ -122,7 +122,7 @@ describe("Global Extension Tests", function () {
});
describe("Disassemble command", function () {
it("Should disassemble a file", async () => {
let state = ExtensionState.getInstance();
let state = ExtensionState.getCurrent();
let spiedDisassembler = spy(state.getDisassembler());
let mockedCapstone = mock(Capstone);
let capstone = instance(mockedCapstone);
Expand Down
30 changes: 17 additions & 13 deletions src/test/extension_calc.test.ts
Expand Up @@ -7,11 +7,12 @@
import { expect } from 'chai';
import * as vscode from 'vscode';
import { spy, verify, anyString, capture, when, anything } from 'ts-mockito/lib/ts-mockito';
import { ExtensionState } from '../extensionState';
import { ExtensionState } from '../extension';

// Defines a Mocha test suite to group tests of similar kind together
describe("Global Extension Tests", function () {
describe("Calc commands", function () {
context("Calc commands", function () {
let state: ExtensionState | undefined;
before(async () => {
const newFile = vscode.Uri.parse("untitled://./myfile.s");
await vscode.workspace.openTextDocument(newFile).then(async document => {
Expand Down Expand Up @@ -39,22 +40,25 @@ describe("Global Extension Tests", function () {
} else {
expect.fail("Editor not available");
}
state = ExtensionState.getCurrent();
});
it("Should evaluate the selection in the status bar", () => {
it("Should evaluate the selection in the status bar", async () => {
this.timeout(60000);
let calc = ExtensionState.getInstance().getCalc();
// Get the satus value
// tslint:disable-next-line:no-unused-expression
expect(calc).to.not.be.undefined;
let sb = calc.getStatusBar();
// tslint:disable-next-line:no-unused-expression
expect(sb).to.not.be.undefined;
if (sb) {
expect(sb.text).to.be.equal("3+2=#5/$5/%101");
if (state) {
let calc = state.getCalc();
// Get the satus value
// tslint:disable-next-line:no-unused-expression
expect(calc).to.not.be.undefined;
let sb = calc.getStatusBar();
// tslint:disable-next-line:no-unused-expression
expect(sb).to.not.be.undefined;
if (sb) {
expect(sb.text).to.be.equal("3+2=#5/$5/%101");
}
}
});
it("Should hide the status bar if it it not evaluable", async () => {
let calc = ExtensionState.getInstance().getCalc();
let calc = ExtensionState.getCurrent().getCalc();
let sb = calc.getStatusBar();
// tslint:disable-next-line:no-unused-expression
expect(sb).to.not.be.undefined;
Expand Down
8 changes: 4 additions & 4 deletions src/test/status.test.ts
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { ExtensionState } from '../extensionState';
import { ExtensionState } from '../extension';
import { spy, verify, anyString, when } from 'ts-mockito/lib/ts-mockito';
import * as vscode from 'vscode';

Expand All @@ -11,7 +11,7 @@ describe("Status Tests", function () {
return vscode.window.showTextDocument(newFile);
});
it("Should status show on command", () => {
let state = ExtensionState.getInstance();
let state = ExtensionState.getCurrent();
let statusManager = state.getStatusManager();
statusManager.diagnosticsStatusBarItem.show();
// status is shown
Expand Down Expand Up @@ -48,7 +48,7 @@ describe("Status Tests", function () {
});
it("Should show react to an error", () => {
let spiedWindow = spy(vscode.window);
let state = ExtensionState.getInstance();
let state = ExtensionState.getCurrent();
let statusManager = state.getStatusManager();
expect(statusManager.statusBarEntry).not.to.be.null;
if (statusManager.statusBarEntry) {
Expand All @@ -60,7 +60,7 @@ describe("Status Tests", function () {
}
});
it("Should show react to a success", () => {
let state = ExtensionState.getInstance();
let state = ExtensionState.getCurrent();
let statusManager = state.getStatusManager();
expect(statusManager.statusBarEntry).not.to.be.null;
if (statusManager.statusBarEntry) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/vasm.test.ts
Expand Up @@ -5,7 +5,7 @@ import { capture, spy, verify, anyString, when, anything, resetCalls, reset } fr
import { VASMCompiler, VASMParser, VASMController } from '../vasm';
import { ExecutorHelper, ICheckResult } from '../execHelper';
import { DummyTextDocument } from './dummy';
import { ExtensionState } from '../extensionState';
import { ExtensionState } from '../extension';
import { VLINKLinker } from '../vlink';

describe("VASM Tests", function () {
Expand Down Expand Up @@ -164,7 +164,7 @@ describe("VASM Tests", function () {
});
it("Should clean the workspace", async function () {
let spiedWorkspace = spy(vscode.workspace);
let state = ExtensionState.getInstance();
let state = ExtensionState.getCurrent();
let spiedOutputChannel = spy(state.getStatusManager().outputChannel);
when(spiedCompiler.unlink(anything())).thenCall(() => { });
let file1 = vscode.Uri.parse("file:///build/file1.o");
Expand All @@ -177,7 +177,7 @@ describe("VASM Tests", function () {
});
});
it("Should get an error when cleaning the workspace", async function () {
let state = ExtensionState.getInstance();
let state = ExtensionState.getCurrent();
let spiedOutputChannel = spy(state.getStatusManager().outputChannel);
spiedCompiler = spy(compiler);
when(spiedCompiler.getWorkspaceRootDir()).thenReturn(vscode.Uri.parse("file:///workdir"));
Expand Down Expand Up @@ -209,7 +209,7 @@ describe("VASM Tests", function () {
it("Should build the current document on save", async () => {
let compiler = new VASMCompiler();
const spiedCompiler = spy(compiler);
let state = ExtensionState.getInstance();
let state = ExtensionState.getCurrent();
const spiedStatus = spy(state.getStatusManager());
let controller = new VASMController(compiler);
let document = new DummyTextDocument();
Expand Down

0 comments on commit 0b5f020

Please sign in to comment.