Skip to content

Commit

Permalink
Add test that reads options and verifies default values
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinCampbell committed May 1, 2018
1 parent 7eac784 commit 8bb7c30
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/omnisharp/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class Options {
const waitForDebugger = omnisharpConfig.get<boolean>('waitForDebugger', false);

// support the legacy "verbose" level as "debug"
let loggingLevel = omnisharpConfig.get<string>('loggingLevel');
if (loggingLevel.toLowerCase() === 'verbose') {
let loggingLevel = omnisharpConfig.get<string>('loggingLevel', 'information');
if (loggingLevel && loggingLevel.toLowerCase() === 'verbose') {
loggingLevel = 'debug';
}

Expand All @@ -56,7 +56,7 @@ export class Options {

const disableCodeActions = csharpConfig.get<boolean>('disableCodeActions', false);

const disableMSBuildDiagnosticWarning = omnisharpConfig.get<boolean>('disableMSBuildDiagnosticWarning');
const disableMSBuildDiagnosticWarning = omnisharpConfig.get<boolean>('disableMSBuildDiagnosticWarning', false);

return new Options(
path,
Expand Down Expand Up @@ -97,7 +97,7 @@ export class Options {

if (omnisharpConfig.has('useGlobalMono')) {
// If 'omnisharp.useGlobalMono' setting was found, just use it.
return omnisharpConfig.get<string>('useGlobalMono');
return omnisharpConfig.get<string>('useGlobalMono', "auto");
}
else if (omnisharpConfig.has('useMono')) {
// BACKCOMPAT: If 'omnisharp.useMono' setting was found, true maps to "always" and false maps to "auto"
Expand Down
56 changes: 56 additions & 0 deletions test/unitTests/options.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { should, expect } from 'chai';
import { Options } from '../../src/omnisharp/options';
import { getFakeVsCode, getWorkspaceConfiguration } from './testAssets/Fakes';

function getVSCode() {
const vscode = getFakeVsCode();

const omnisharpConfig = getWorkspaceConfiguration();
const csharpConfig = getWorkspaceConfiguration();

vscode.workspace.getConfiguration = (section?, resource?) =>
{
if (section === 'omnisharp')
{
return omnisharpConfig;
}

if (section === 'csharp')
{
return csharpConfig;
}

return undefined;
};

return vscode;
}

suite("CsharpChannelObserver", () => {
suiteSetup(() => should());

test('Construct options and verify defaults', () =>
{
const vscode = getVSCode();
const options = Options.Read(vscode);

expect(options.path).to.be.null;
options.useGlobalMono.should.equal("auto");
options.waitForDebugger.should.equal(false);
options.loggingLevel.should.equal("information");
options.autoStart.should.equal(true);
options.projectLoadTimeout.should.equal(60);
options.maxProjectResults.should.equal(250);
options.useEditorFormattingSettings.should.equal(true);
options.useFormatting.should.equal(true);
options.showReferencesCodeLens.should.equal(true);
options.showTestsCodeLens.should.equal(true);
options.disableCodeActions.should.equal(false);
options.disableCodeActions.should.equal(false);
});
});
32 changes: 28 additions & 4 deletions test/unitTests/testAssets/Fakes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export const getNullTelemetryReporter = (): ITelemetryReporter => {
};

export const getNullWorkspaceConfiguration = (): vscode.WorkspaceConfiguration => {
let workspace: vscode.WorkspaceConfiguration = {
get: <T>(section: string): T| undefined => {
let configuration: vscode.WorkspaceConfiguration = {
get: <T>(section: string): T | undefined => {
return undefined;
},
has: (section: string) => { return undefined; },
Expand All @@ -42,9 +42,33 @@ export const getNullWorkspaceConfiguration = (): vscode.WorkspaceConfiguration =
key: undefined
};
},
update: async () => { return Promise.resolve(); },
update: async () => { return Promise.resolve(); }
};
return workspace;

return configuration;
};

export const getWorkspaceConfiguration = (): vscode.WorkspaceConfiguration => {
let values: { [key: string]: any } = {};

let configuration: vscode.WorkspaceConfiguration = {
get<T>(section: string, defaultValue?: T): T | undefined {
let result = <T>values[section];
return result === undefined && defaultValue !== undefined
? defaultValue
: result;
},
has: (section: string) => {
return values[section] !== undefined;
},
inspect: () => { throw new Error("Not Implemented"); },
update: async (section: string, value: any, configurationTarget?: vscode.ConfigurationTarget | boolean) => {
values[section] = value;
return Promise.resolve();
}
};

return configuration;
};

export function getOmnisharpMSBuildProjectDiagnosticsEvent(fileName: string, warnings: MSBuildDiagnosticsMessage[], errors: MSBuildDiagnosticsMessage[]): OmnisharpServerMsBuildProjectDiagnostics {
Expand Down

0 comments on commit 8bb7c30

Please sign in to comment.