Skip to content

Commit

Permalink
Update tests to account for adjusted command enablement
Browse files Browse the repository at this point in the history
  • Loading branch information
dibarbet committed Oct 29, 2024
1 parent 05d9416 commit a6e8298
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 34 deletions.
9 changes: 6 additions & 3 deletions src/lsptoolshost/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { createLaunchTargetForSolution } from '../shared/launchTarget';
import reportIssue from '../shared/reportIssue';
import { getDotnetInfo } from '../shared/utils/getDotnetInfo';
import { IHostExecutableResolver } from '../shared/constants/IHostExecutableResolver';
import { getCSharpDevKit } from '../utils/getCSharpDevKit';

export function registerCommands(
context: vscode.ExtensionContext,
Expand Down Expand Up @@ -38,9 +39,11 @@ export function registerCommands(
context.subscriptions.push(
vscode.commands.registerCommand('dotnet.restartServer', async () => restartServer(languageServer))
);
context.subscriptions.push(
vscode.commands.registerCommand('dotnet.openSolution', async () => openSolution(languageServer))
);
if (!getCSharpDevKit()) {
context.subscriptions.push(
vscode.commands.registerCommand('dotnet.openSolution', async () => openSolution(languageServer))
);
}
context.subscriptions.push(
vscode.commands.registerCommand('csharp.reportIssue', async () =>
reportIssue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { expect, test, beforeAll, afterAll, describe } from '@jest/globals';
import { expect, beforeAll, afterAll, describe } from '@jest/globals';
import * as vscode from 'vscode';
import { activateCSharpExtension } from './integrationHelpers';
import { activateCSharpExtension, testIfCSharp, testIfDevKit } from './integrationHelpers';
import testAssetWorkspace from './testAssets/testAssetWorkspace';
import { CommonCommands, OmniSharpCommands, RoslynCommands } from './expectedCommands';
import {
RoslynDevKitCommands,
RoslynStandaloneCommands,
UnexpectedRoslynDevKitCommands,
UnexpectedRoslynStandaloneCommands,
} from './expectedCommands';

describe(`Command Enablement Tests`, () => {
beforeAll(async () => {
Expand All @@ -18,19 +23,30 @@ describe(`Command Enablement Tests`, () => {
await testAssetWorkspace.cleanupWorkspace();
});

test('Roslyn commands are available', async () => {
testIfCSharp('Roslyn standalone commands are available', async () => {
const commands = await vscode.commands.getCommands(true);

// Ensure the standalone Roslyn commands are available.
RoslynCommands.forEach((command) => {
RoslynStandaloneCommands.forEach((command) => {
expect(commands).toContain(command);
});
CommonCommands.forEach((command) => {

// Ensure other commands are not available.
UnexpectedRoslynStandaloneCommands.forEach((command) => {
expect(commands).not.toContain(command);
});
});

testIfDevKit('Roslyn + C# Dev Kit commands are available', async () => {
const commands = await vscode.commands.getCommands(true);

// Ensure the Roslyn + C# Dev Kit commands are available
RoslynDevKitCommands.forEach((command) => {
expect(commands).toContain(command);
});

// Ensure O# commands are not available.
OmniSharpCommands.forEach((command) => {
// Ensure other commands are not available.
UnexpectedRoslynDevKitCommands.forEach((command) => {
expect(commands).not.toContain(command);
});
});
Expand Down
63 changes: 50 additions & 13 deletions test/lsptoolshost/integrationTests/expectedCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,26 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

export const OmniSharpCommands = [
// Commands used by all activation contexts of the extension.
const CommonCommands = [
'dotnet.generateAssets',
'csharp.listProcess',
'csharp.listRemoteProcess',
'csharp.listRemoteDockerProcess',
'csharp.attachToProcess',
'csharp.reportIssue',
];

// Commands used by both O# and Roslyn standalone activation contexts.
const CommonStandaloneCommands = [
'dotnet.restore.project',
'dotnet.restore.all',
'dotnet.test.runTestsInContext',
'dotnet.test.debugTestsInContext',
];

// Commands used only in an O# activation context.
const OmniSharpOnlyCommands = [
'o.restart',
'o.pickProjectAndStart',
'o.fixAll.solution',
Expand All @@ -13,17 +32,35 @@ export const OmniSharpCommands = [
'o.reanalyze.currentProject',
];

export const RoslynCommands = ['dotnet.openSolution', 'dotnet.restartServer'];
// All commands used in the O# activation context.
export const OmniSharpCommands = [...OmniSharpOnlyCommands, ...CommonCommands, ...CommonStandaloneCommands];

export const CommonCommands = [
'dotnet.generateAssets',
'dotnet.restore.project',
'dotnet.restore.all',
'dotnet.test.runTestsInContext',
'dotnet.test.debugTestsInContext',
'csharp.listProcess',
'csharp.listRemoteProcess',
'csharp.listRemoteDockerProcess',
'csharp.attachToProcess',
'csharp.reportIssue',
// Commands used only in a Roslyn activation context.
const RoslynCommonCommands = ['dotnet.restartServer'];

// Commands used only in a Roslyn standalone activation context.
const RoslynStandaloneOnlyCommands = ['dotnet.openSolution'];

// All commands used in a Roslyn standalone activation context.
export const RoslynStandaloneCommands = [
...CommonCommands,
...CommonStandaloneCommands,
...RoslynCommonCommands,
...RoslynStandaloneOnlyCommands,
];

// All commands used in a Roslyn + C# Dev Kit activation context.
export const RoslynDevKitCommands = [...CommonCommands, ...RoslynCommonCommands];

// All commands that should not be available in an O# activation context.
export const UnexpectedOmniSharpCommands = [...RoslynStandaloneOnlyCommands, ...RoslynCommonCommands];

// All commands that should not be available in a Roslyn standalone activation context.
export const UnexpectedRoslynStandaloneCommands = [...OmniSharpOnlyCommands];

// All commands that should not be available in a Roslyn + C# Dev Kit activation context.
export const UnexpectedRoslynDevKitCommands = [
...CommonStandaloneCommands,
...OmniSharpOnlyCommands,
...RoslynStandaloneOnlyCommands,
];
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import { expect, test, beforeAll, afterAll, describe } from '@jest/globals';
import * as vscode from 'vscode';
import { activateCSharpExtension } from './integrationHelpers';
import testAssetWorkspace from './testAssets/activeTestAssetWorkspace';
import {
CommonCommands,
OmniSharpCommands,
RoslynCommands,
} from '../../lsptoolshost/integrationTests/expectedCommands';
import { OmniSharpCommands, UnexpectedOmniSharpCommands } from '../../lsptoolshost/integrationTests/expectedCommands';

describe(`Command Enablement: ${testAssetWorkspace.description}`, function () {
beforeAll(async function () {
Expand All @@ -31,12 +27,9 @@ describe(`Command Enablement: ${testAssetWorkspace.description}`, function () {
OmniSharpCommands.forEach((command) => {
expect(commands).toContain(command);
});
CommonCommands.forEach((command) => {
expect(commands).toContain(command);
});

// Ensure Roslyn standalone commands are not available.
RoslynCommands.forEach((command) => {
// Ensure other commands are not available.
UnexpectedOmniSharpCommands.forEach((command) => {
expect(commands).not.toContain(command);
});
});
Expand Down

0 comments on commit a6e8298

Please # to comment.