From 8cb1662afafd677aa75b999a94ce27ab45b67cca Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Wed, 19 Feb 2020 13:28:44 -0800 Subject: [PATCH] Ignore virtual files --- .gitignore | 1 + .vscode/launch.json | 19 +++++++ src/features/diagnosticsProvider.ts | 6 ++ tasks/testTasks.ts | 7 ++- .../advisor.integration.test.ts | 5 ++ .../codeActionRename.integration.test.ts | 6 ++ ...completionItemProvider.integration.test.ts | 7 ++- .../definitionProvider.test.ts | 7 ++- .../diagnostics.integration.test.ts | 55 ++++++++++++++++++- ...documentSymbolProvider.integration.test.ts | 6 ++ .../hoverProvider.integration.test.ts | 6 ++ .../implementationProvider.test.ts | 7 ++- .../languageMiddleware.integration.test.ts | 11 +++- .../launchConfiguration.integration.test.ts | 7 +++ test/integrationTests/poll.ts | 20 +++++++ .../reAnalyze.integration.test.ts | 12 +++- .../referenceProvider.test.ts | 7 ++- .../signatureHelp.integration.test.ts | 5 ++ .../BasicRazorApp2_1/Pages/ErrorHaver.razor | 3 + ...orkspaceSymbolProvider.integration.test.ts | 7 +++ 20 files changed, 192 insertions(+), 12 deletions(-) create mode 100644 test/integrationTests/testAssets/BasicRazorApp2_1/Pages/ErrorHaver.razor diff --git a/.gitignore b/.gitignore index 8616ba1fe..b6f704aaa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ bin +obj node_modules out .omnisharp/ diff --git a/.vscode/launch.json b/.vscode/launch.json index c10120f33..a72708a2a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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", diff --git a/src/features/diagnosticsProvider.ts b/src/features/diagnosticsProvider.ts index b99207c61..2d3e2395d 100644 --- a/src/features/diagnosticsProvider.ts +++ b/src/features/diagnosticsProvider.ts @@ -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); diff --git a/tasks/testTasks.ts b/tasks/testTasks.ts index fd077bb1d..e9b85cefd 100644 --- a/tasks/testTasks.ts +++ b/tasks/testTasks.ts @@ -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( diff --git a/test/integrationTests/advisor.integration.test.ts b/test/integrationTests/advisor.integration.test.ts index 570fb403f..892cc14e2 100644 --- a/test/integrationTests/advisor.integration.test.ts +++ b/test/integrationTests/advisor.integration.test.ts @@ -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(); diff --git a/test/integrationTests/codeActionRename.integration.test.ts b/test/integrationTests/codeActionRename.integration.test.ts index d90789c8d..633dc3cb1 100644 --- a/test/integrationTests/codeActionRename.integration.test.ts +++ b/test/integrationTests/codeActionRename.integration.test.ts @@ -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(); diff --git a/test/integrationTests/completionItemProvider.integration.test.ts b/test/integrationTests/completionItemProvider.integration.test.ts index 56321acb1..5e0b94245 100644 --- a/test/integrationTests/completionItemProvider.integration.test.ts +++ b/test/integrationTests/completionItemProvider.integration.test.ts @@ -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(); diff --git a/test/integrationTests/definitionProvider.test.ts b/test/integrationTests/definitionProvider.test.ts index 138556702..815afd7a0 100644 --- a/test/integrationTests/definitionProvider.test.ts +++ b/test/integrationTests/definitionProvider.test.ts @@ -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(); diff --git a/test/integrationTests/diagnostics.integration.test.ts b/test/integrationTests/diagnostics.integration.test.ts index 584244480..7d3de91fd 100644 --- a/test/integrationTests/diagnostics.integration.test.ts +++ b/test/integrationTests/diagnostics.integration.test.ts @@ -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')); @@ -23,6 +23,8 @@ 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(); @@ -36,11 +38,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); @@ -78,6 +125,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(); diff --git a/test/integrationTests/documentSymbolProvider.integration.test.ts b/test/integrationTests/documentSymbolProvider.integration.test.ts index c82d5bb08..bebcba312 100644 --- a/test/integrationTests/documentSymbolProvider.integration.test.ts +++ b/test/integrationTests/documentSymbolProvider.integration.test.ts @@ -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(); diff --git a/test/integrationTests/hoverProvider.integration.test.ts b/test/integrationTests/hoverProvider.integration.test.ts index d88ae6bb4..bcba184a1 100644 --- a/test/integrationTests/hoverProvider.integration.test.ts +++ b/test/integrationTests/hoverProvider.integration.test.ts @@ -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(); }); diff --git a/test/integrationTests/implementationProvider.test.ts b/test/integrationTests/implementationProvider.test.ts index 720f50695..c874c08e7 100644 --- a/test/integrationTests/implementationProvider.test.ts +++ b/test/integrationTests/implementationProvider.test.ts @@ -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(); diff --git a/test/integrationTests/languageMiddleware.integration.test.ts b/test/integrationTests/languageMiddleware.integration.test.ts index 39c2834fd..804824c32 100644 --- a/test/integrationTests/languageMiddleware.integration.test.ts +++ b/test/integrationTests/languageMiddleware.integration.test.ts @@ -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(); @@ -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); @@ -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 { const newEdit = new vscode.WorkspaceEdit(); for (const entry of workspaceEdit.entries()) { diff --git a/test/integrationTests/launchConfiguration.integration.test.ts b/test/integrationTests/launchConfiguration.integration.test.ts index c3e373212..1ed97da1b 100644 --- a/test/integrationTests/launchConfiguration.integration.test.ts +++ b/test/integrationTests/launchConfiguration.integration.test.ts @@ -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'; @@ -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(); diff --git a/test/integrationTests/poll.ts b/test/integrationTests/poll.ts index b0d428d87..6bc021b03 100644 --- a/test/integrationTests/poll.ts +++ b/test/integrationTests/poll.ts @@ -47,6 +47,26 @@ function defaultPollExpression(value: T): boolean { return value !== undefined && ((Array.isArray(value) && value.length > 0) || !Array.isArray(value)); } +export async function pollDoesNotHappen( + getValue: () => T, + duration: number, + step: number, + expression: (input: T) => boolean = defaultPollExpression): Promise { + 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( getValue: () => T, duration: number, diff --git a/test/integrationTests/reAnalyze.integration.test.ts b/test/integrationTests/reAnalyze.integration.test.ts index be694ce16..86f832d15 100644 --- a/test/integrationTests/reAnalyze.integration.test.ts +++ b/test/integrationTests/reAnalyze.integration.test.ts @@ -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'; @@ -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(); diff --git a/test/integrationTests/referenceProvider.test.ts b/test/integrationTests/referenceProvider.test.ts index cca4d7202..d847bee0f 100644 --- a/test/integrationTests/referenceProvider.test.ts +++ b/test/integrationTests/referenceProvider.test.ts @@ -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(); diff --git a/test/integrationTests/signatureHelp.integration.test.ts b/test/integrationTests/signatureHelp.integration.test.ts index 1c66a7d5b..a6c72ac67 100644 --- a/test/integrationTests/signatureHelp.integration.test.ts +++ b/test/integrationTests/signatureHelp.integration.test.ts @@ -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(); diff --git a/test/integrationTests/testAssets/BasicRazorApp2_1/Pages/ErrorHaver.razor b/test/integrationTests/testAssets/BasicRazorApp2_1/Pages/ErrorHaver.razor new file mode 100644 index 000000000..4f4744b77 --- /dev/null +++ b/test/integrationTests/testAssets/BasicRazorApp2_1/Pages/ErrorHaver.razor @@ -0,0 +1,3 @@ +@page + +@DoesNotExist diff --git a/test/integrationTests/workspaceSymbolProvider.integration.test.ts b/test/integrationTests/workspaceSymbolProvider.integration.test.ts index f57b3cf5d..c80f08251 100644 --- a/test/integrationTests/workspaceSymbolProvider.integration.test.ts +++ b/test/integrationTests/workspaceSymbolProvider.integration.test.ts @@ -4,6 +4,8 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; +import * as path from 'path'; + import { expect } from 'chai'; import { activateCSharpExtension } from './integrationHelpers'; import testAssetWorkspace from './testAssets/testAssetWorkspace'; @@ -14,6 +16,11 @@ chai.use(require('chai-fs')); suite(`WorkspaceSymbolProvider: ${testAssetWorkspace.description}`, function () { 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(); let projectDirectory = vscode.Uri.file(testAssetWorkspace.projects[0].projectDirectoryPath);