Skip to content

Commit 510b7cd

Browse files
Add test that reads options and verifies default values
1 parent 7eac784 commit 510b7cd

File tree

3 files changed

+88
-8
lines changed

3 files changed

+88
-8
lines changed

src/omnisharp/options.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export class Options {
3838
const waitForDebugger = omnisharpConfig.get<boolean>('waitForDebugger', false);
3939

4040
// support the legacy "verbose" level as "debug"
41-
let loggingLevel = omnisharpConfig.get<string>('loggingLevel');
42-
if (loggingLevel.toLowerCase() === 'verbose') {
41+
let loggingLevel = omnisharpConfig.get<string>('loggingLevel', 'information');
42+
if (loggingLevel && loggingLevel.toLowerCase() === 'verbose') {
4343
loggingLevel = 'debug';
4444
}
4545

@@ -56,7 +56,7 @@ export class Options {
5656

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

59-
const disableMSBuildDiagnosticWarning = omnisharpConfig.get<boolean>('disableMSBuildDiagnosticWarning');
59+
const disableMSBuildDiagnosticWarning = omnisharpConfig.get<boolean>('disableMSBuildDiagnosticWarning', false);
6060

6161
return new Options(
6262
path,
@@ -97,7 +97,7 @@ export class Options {
9797

9898
if (omnisharpConfig.has('useGlobalMono')) {
9999
// If 'omnisharp.useGlobalMono' setting was found, just use it.
100-
return omnisharpConfig.get<string>('useGlobalMono');
100+
return omnisharpConfig.get<string>('useGlobalMono', "auto");
101101
}
102102
else if (omnisharpConfig.has('useMono')) {
103103
// BACKCOMPAT: If 'omnisharp.useMono' setting was found, true maps to "always" and false maps to "auto"

test/unitTests/options.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { should, expect } from 'chai';
7+
import { Options } from '../../src/omnisharp/options';
8+
import { getFakeVsCode, getWorkspaceConfiguration } from './testAssets/Fakes';
9+
10+
function getVSCode() {
11+
const vscode = getFakeVsCode();
12+
13+
const omnisharpConfig = getWorkspaceConfiguration();
14+
const csharpConfig = getWorkspaceConfiguration();
15+
16+
vscode.workspace.getConfiguration = (section?, resource?) =>
17+
{
18+
if (section === 'omnisharp')
19+
{
20+
return omnisharpConfig;
21+
}
22+
23+
if (section === 'csharp')
24+
{
25+
return csharpConfig;
26+
}
27+
28+
return undefined;
29+
};
30+
31+
return vscode;
32+
}
33+
34+
suite("Options tests", () => {
35+
suiteSetup(() => should());
36+
37+
test('Construct options and verify defaults', () =>
38+
{
39+
const vscode = getVSCode();
40+
const options = Options.Read(vscode);
41+
42+
expect(options.path).to.be.null;
43+
options.useGlobalMono.should.equal("auto");
44+
options.waitForDebugger.should.equal(false);
45+
options.loggingLevel.should.equal("information");
46+
options.autoStart.should.equal(true);
47+
options.projectLoadTimeout.should.equal(60);
48+
options.maxProjectResults.should.equal(250);
49+
options.useEditorFormattingSettings.should.equal(true);
50+
options.useFormatting.should.equal(true);
51+
options.showReferencesCodeLens.should.equal(true);
52+
options.showTestsCodeLens.should.equal(true);
53+
options.disableCodeActions.should.equal(false);
54+
options.disableCodeActions.should.equal(false);
55+
});
56+
});

test/unitTests/testAssets/Fakes.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export const getNullTelemetryReporter = (): ITelemetryReporter => {
3232
};
3333

3434
export const getNullWorkspaceConfiguration = (): vscode.WorkspaceConfiguration => {
35-
let workspace: vscode.WorkspaceConfiguration = {
36-
get: <T>(section: string): T| undefined => {
35+
let configuration: vscode.WorkspaceConfiguration = {
36+
get: <T>(section: string): T | undefined => {
3737
return undefined;
3838
},
3939
has: (section: string) => { return undefined; },
@@ -42,9 +42,33 @@ export const getNullWorkspaceConfiguration = (): vscode.WorkspaceConfiguration =
4242
key: undefined
4343
};
4444
},
45-
update: async () => { return Promise.resolve(); },
45+
update: async () => { return Promise.resolve(); }
4646
};
47-
return workspace;
47+
48+
return configuration;
49+
};
50+
51+
export const getWorkspaceConfiguration = (): vscode.WorkspaceConfiguration => {
52+
let values: { [key: string]: any } = {};
53+
54+
let configuration: vscode.WorkspaceConfiguration = {
55+
get<T>(section: string, defaultValue?: T): T | undefined {
56+
let result = <T>values[section];
57+
return result === undefined && defaultValue !== undefined
58+
? defaultValue
59+
: result;
60+
},
61+
has: (section: string) => {
62+
return values[section] !== undefined;
63+
},
64+
inspect: () => { throw new Error("Not Implemented"); },
65+
update: async (section: string, value: any, configurationTarget?: vscode.ConfigurationTarget | boolean) => {
66+
values[section] = value;
67+
return Promise.resolve();
68+
}
69+
};
70+
71+
return configuration;
4872
};
4973

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

0 commit comments

Comments
 (0)