Skip to content

Commit

Permalink
Ignore virtual files
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbrandenburg committed Feb 20, 2020
1 parent 4ca5155 commit c35ca2e
Show file tree
Hide file tree
Showing 20 changed files with 197 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin
obj
node_modules
out
.omnisharp/
Expand Down
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@
],
"preLaunchTask": "buildDev"
},
{
"name": "Launch razorcsproj Workspace Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"${workspaceRoot}/test/integrationTests/testAssets/BasicRazorApp2_1",
"--extensionDevelopmentPath=${workspaceRoot}",
"--extensionTestsPath=${workspaceRoot}/out/test/integrationTests"
],
"env": {
"CODE_WORKSPACE_ROOT": "${workspaceRoot}",
"CODE_TESTS_PATH": "${workspaceRoot}/out/test/integrationTests",
"CODE_TESTS_WORKSPACE": "${workspaceRoot}/test/integrationTests/testAssets/BasicRazorApp2_1",
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
"OSVC_SUITE": "BasicRazorApp2_1"
},
},
{
"name": "Launch slnWithCsproj Workspace Tests",
"type": "extensionHost",
Expand Down
6 changes: 6 additions & 0 deletions src/features/diagnosticsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ class DiagnosticsProvider extends AbstractSupport {
return;
}

// No problems published for virtual files
if(isVirtualCSharpDocument(document))
{
return;
}

// (re)set new diagnostics for this document
let diagnosticsInFile = this._mapQuickFixesAsDiagnosticsInFile(quickFixes);

Expand Down
7 changes: 6 additions & 1 deletion tasks/testTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ gulp.task("test:integration:slnWithCsproj", async () => {
return runIntegrationTest("slnWithCsproj");
});

gulp.task("test:integration:BasicRazorApp2_1", async () => {
return runIntegrationTest("BasicRazorApp2_1");
});

gulp.task(
"test:integration", gulp.series(
"test:integration:singleCsproj",
"test:integration:slnWithCsproj"
"test:integration:slnWithCsproj",
"test:integration:BasicRazorApp2_1"
));

gulp.task("test", gulp.series(
Expand Down
5 changes: 5 additions & 0 deletions test/integrationTests/advisor.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ suite(`Advisor ${testAssetWorkspace.description}`, function () {
let advisor: Advisor;

suiteSetup(async function () {
// These tests don't run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() === 'BasicRazorApp2_1') {
this.skip();
}

let activationResult = await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
6 changes: 6 additions & 0 deletions test/integrationTests/codeActionRename.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ suite(`Code Action Rename ${testAssetWorkspace.description}`, function () {

suiteSetup(async function () {
should();

// These tests don't run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() === 'BasicRazorApp2_1') {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { activateCSharpExtension } from "./integrationHelpers";
suite(`${OmniSharpCompletionItemProvider.name}: Returns the completion items`, () => {
let fileUri: vscode.Uri;

suiteSetup(async () => {
suiteSetup(async function() {
// These tests don't run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() === 'BasicRazorApp2_1') {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
7 changes: 6 additions & 1 deletion test/integrationTests/definitionProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { activateCSharpExtension } from './integrationHelpers';
suite(`${CSharpDefinitionProvider.name}: ${testAssetWorkspace.description}`, () => {
let fileUri: vscode.Uri;

suiteSetup(async () => {
suiteSetup(async function () {
// These tests don't run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() === 'BasicRazorApp2_1') {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
60 changes: 59 additions & 1 deletion test/integrationTests/diagnostics.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as path from 'path';
import { should, expect } from 'chai';
import { activateCSharpExtension } from './integrationHelpers';
import testAssetWorkspace from './testAssets/testAssetWorkspace';
import { poll, assertWithPoll } from './poll';
import { poll, assertWithPoll, pollDoesNotHappen } from './poll';

const chai = require('chai');
chai.use(require('chai-arrays'));
Expand All @@ -23,10 +23,17 @@ function setDiagnosticWorkspaceLimit(to: number | null) {
suite(`DiagnosticProvider: ${testAssetWorkspace.description}`, function () {
let fileUri: vscode.Uri;
let secondaryFileUri: vscode.Uri;
let razorFileUri: vscode.Uri;
let virtualRazorFileUri: vscode.Uri;

suiteSetup(async function () {
should();

// These tests only run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() !== 'BasicRazorApp2_1') {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand All @@ -36,11 +43,56 @@ suite(`DiagnosticProvider: ${testAssetWorkspace.description}`, function () {

fileUri = vscode.Uri.file(path.join(projectDirectory, fileName));
secondaryFileUri = vscode.Uri.file(path.join(projectDirectory, secondaryFileName));
razorFileUri = vscode.Uri.file(path.join(projectDirectory, 'Pages', 'ErrorHaver.razor'));
virtualRazorFileUri = vscode.Uri.file(razorFileUri.fsPath + '__virtual.cs');
});

suite("razor workspace", () => {
suiteSetup(async function () {
should();

// These tests only run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() !== 'BasicRazorApp2_1') {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();
await vscode.commands.executeCommand("vscode.open", razorFileUri);
});

test("Razor shouldn't give diagnostics for virtual files", async () => {
await pollDoesNotHappen(() => vscode.languages.getDiagnostics(), 5 * 1000, 500, function(res) {
const virtual = res.find(r => r[0].fsPath === virtualRazorFileUri.fsPath);

if(!virtual) {
return false;
}

const diagnosticsList = virtual[1];
if(diagnosticsList.some(diag => diag.code == 'CS0103')) {
return true;
}
else{
return false;
}
});
});

suiteTeardown(async () => {
await testAssetWorkspace.cleanupWorkspace();
});
});

suite("small workspace (based on maxProjectFileCountForDiagnosticAnalysis setting)", () => {
suiteSetup(async function () {
should();

// These tests don't run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() === 'BasicRazorApp2_1') {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();
await vscode.commands.executeCommand("vscode.open", fileUri);
Expand Down Expand Up @@ -78,6 +130,12 @@ suite(`DiagnosticProvider: ${testAssetWorkspace.description}`, function () {
suite("large workspace (based on maxProjectFileCountForDiagnosticAnalysis setting)", () => {
suiteSetup(async function () {
should();

// These tests don't run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() === 'BasicRazorApp2_1') {
this.skip();
}

await setDiagnosticWorkspaceLimit(1);
await testAssetWorkspace.restore();
await activateCSharpExtension();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ suite(`DocumentSymbolProvider: ${testAssetWorkspace.description}`, function () {

suiteSetup(async function () {
should();

// These tests don't run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() === 'BasicRazorApp2_1') {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
6 changes: 6 additions & 0 deletions test/integrationTests/hoverProvider.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ chai.use(require('chai-fs'));
suite(`Hover Provider: ${testAssetWorkspace.description}`, function () {
suiteSetup(async function () {
should();

// These tests don't run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() === 'BasicRazorApp2_1') {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();
});
Expand Down
7 changes: 6 additions & 1 deletion test/integrationTests/implementationProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { activateCSharpExtension } from './integrationHelpers';
suite(`${CSharpImplementationProvider.name}: ${testAssetWorkspace.description}`, () => {
let fileUri: vscode.Uri;

suiteSetup(async () => {
suiteSetup(async function() {
// These tests don't run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() === 'BasicRazorApp2_1') {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
11 changes: 8 additions & 3 deletions test/integrationTests/languageMiddleware.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ suite(`${LanguageMiddlewareFeature.name}: ${testAssetWorkspace.description}`, ()
let fileUri: vscode.Uri;
let remappedFileUri: vscode.Uri;

suiteSetup(async () => {
suiteSetup(async function () {
// These tests don't run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() === 'BasicRazorApp2_1') {
this.skip();
}

await activateCSharpExtension();
await registerLanguageMiddleware();
await testAssetWorkspace.restore();
Expand All @@ -41,7 +46,7 @@ suite(`${LanguageMiddlewareFeature.name}: ${testAssetWorkspace.description}`, ()
fileUri,
new vscode.Position(4, 30),
'newName'));

let entries = workspaceEdit!.entries();
expect(entries.length).to.be.equal(1);
expect(entries[0][0].path).to.be.equal(remappedFileUri.path);
Expand Down Expand Up @@ -93,7 +98,7 @@ class TestLanguageMiddleware implements LanguageMiddleware
let fileToRemap = 'remap.cs';
this.fileToRemapUri = vscode.Uri.file(path.join(projectDirectory, fileToRemap));
}

remapWorkspaceEdit?(workspaceEdit: vscode.WorkspaceEdit, token: vscode.CancellationToken): vscode.ProviderResult<vscode.WorkspaceEdit> {
const newEdit = new vscode.WorkspaceEdit();
for (const entry of workspaceEdit.entries()) {
Expand Down
7 changes: 7 additions & 0 deletions test/integrationTests/launchConfiguration.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import * as fs from 'async-file';
import * as vscode from 'vscode';
import * as path from 'path';

import { should, expect } from 'chai';
import { activateCSharpExtension } from './integrationHelpers';
Expand All @@ -18,6 +19,12 @@ chai.use(require('chai-fs'));
suite(`Tasks generation: ${testAssetWorkspace.description}`, function () {
suiteSetup(async function () {
should();

// These tests don't run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() === 'BasicRazorApp2_1') {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
20 changes: 20 additions & 0 deletions test/integrationTests/poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ function defaultPollExpression<T>(value: T): boolean {
return value !== undefined && ((Array.isArray(value) && value.length > 0) || !Array.isArray(value));
}

export async function pollDoesNotHappen<T>(
getValue: () => T,
duration: number,
step: number,
expression: (input: T) => boolean = defaultPollExpression): Promise<void> {
while (duration > 0) {
let value = await getValue();

if (expression(value)) {
throw new Error("Polling succeeded within the alotted duration, but should not have.");
}

await sleep(step);

duration -= step;
}

// Successfully never happened
}

export async function poll<T>(
getValue: () => T,
duration: number,
Expand Down
12 changes: 9 additions & 3 deletions test/integrationTests/reAnalyze.integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
Expand Down Expand Up @@ -40,6 +40,12 @@ suite(`ReAnalyze: ${testAssetWorkspace.description}`, function () {

suiteSetup(async function () {
should();

// These tests don't run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() === 'BasicRazorApp2_1') {
this.skip();
}

eventStream = (await activateCSharpExtension()).eventStream;
await testAssetWorkspace.restore();

Expand Down
7 changes: 6 additions & 1 deletion test/integrationTests/referenceProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { activateCSharpExtension } from './integrationHelpers';
suite(`${OmnisharpReferenceProvider.name}: ${testAssetWorkspace.description}`, () => {
let fileUri: vscode.Uri;

suiteSetup(async () => {
suiteSetup(async function () {
// These tests don't run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() === 'BasicRazorApp2_1') {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
5 changes: 5 additions & 0 deletions test/integrationTests/signatureHelp.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ suite(`SignatureHelp: ${testAssetWorkspace.description}`, function () {
let fileUri: vscode.Uri;

suiteSetup(async function () {
// These tests don't run on the BasicRazorApp2_1 solution
if (vscode.workspace.workspaceFolders[0].uri.fsPath.split(path.sep).pop() === 'BasicRazorApp2_1') {
this.skip();
}

await activateCSharpExtension();
await testAssetWorkspace.restore();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@page

@DoesNotExist
Loading

0 comments on commit c35ca2e

Please sign in to comment.