From 6b59233475e2112ac61fb4ee569916428b5b5d18 Mon Sep 17 00:00:00 2001 From: jirimosinger <99467904+jirimosinger@users.noreply.github.com> Date: Fri, 29 Apr 2022 14:07:19 +0200 Subject: [PATCH] test: Added missing tests from Rally --- .github/workflows/CI.yml | 2 +- .../src/test/suite/completionList.test.ts | 55 +++ .../src/test/suite/integration.test.ts | 342 ++++++++---------- .../src/test/suite/testHelper.ts | 59 +++ .../workspace/.hlasmplugin/proc_grps.json | 3 + 5 files changed, 272 insertions(+), 189 deletions(-) create mode 100644 clients/vscode-hlasmplugin/src/test/suite/completionList.test.ts create mode 100644 clients/vscode-hlasmplugin/src/test/suite/testHelper.ts diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2ab370ddf..5e38a396e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -339,7 +339,7 @@ jobs: needs: alpine-VSIX strategy: matrix: - theia: ["quay.io/zowe-explorer/theia:1.18.0"] + theia: ["quay.io/zowe-explorer/theia:1.24.0"] # theiaide images not supported anymore, replaced with a quay mirror until there is something official again. See also https://github.com/theia-ide/theia-apps/issues/496 container: image: ${{ matrix.theia }} diff --git a/clients/vscode-hlasmplugin/src/test/suite/completionList.test.ts b/clients/vscode-hlasmplugin/src/test/suite/completionList.test.ts new file mode 100644 index 000000000..824298e44 --- /dev/null +++ b/clients/vscode-hlasmplugin/src/test/suite/completionList.test.ts @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 Broadcom. + * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Broadcom, Inc. - initial API and implementation + */ + +import * as assert from 'assert'; +import * as vscode from 'vscode'; +import * as helper from './testHelper'; + +suite('Completion List Test Suite', () => { + const workspace_file = 'open'; + let editor: vscode.TextEditor; + + suiteSetup(async function () { + this.timeout(10000); + + await helper.showDocument(workspace_file); + editor = helper.get_editor(workspace_file); + }); + + suiteTeardown(async function () { + await vscode.commands.executeCommand('workbench.action.closeActiveEditor'); + }); + + // test completion list for instructions + test('Completion List Instructions test', async () => { + const movePosition = await helper.insertString(editor, new vscode.Position(7, 1), 'L'); + + const completionList: vscode.CompletionList = await vscode.commands.executeCommand('vscode.executeCompletionItemProvider', editor.document.uri, movePosition); + + const result = completionList.items.filter(complItem => complItem.label.toString().startsWith('L')); + assert.ok(result.length === 289, 'Wrong number of suggestion result. Expected 289 got ' + result.length); + }).timeout(3000).slow(1000); + + // test completion list for variable symbols + test('Completion List Variable symbols test', async () => { + // add '&' to simulate start of a variable symbol + const movePosition = await helper.insertString(editor, new vscode.Position(8, 0), '&'); + + const completionList: vscode.CompletionList = await vscode.commands.executeCommand('vscode.executeCompletionItemProvider', editor.document.uri, movePosition); + + assert.ok(completionList.items.length === 2, 'Wrong number of suggestion result. Expected 2 got ' + completionList.items.length); + assert.ok(completionList.items[0].label.toString() === '&VAR', 'Wrong first completion item. Expected &VAR got ' + completionList.items[0].label.toString()); + assert.ok(completionList.items[1].label.toString() === '&VAR2', 'Wrong second completion item. Expected &VAR2 got ' + completionList.items[1].label.toString()); + }).timeout(3000).slow(1000); +}); diff --git a/clients/vscode-hlasmplugin/src/test/suite/integration.test.ts b/clients/vscode-hlasmplugin/src/test/suite/integration.test.ts index d92517c9e..38fbef570 100644 --- a/clients/vscode-hlasmplugin/src/test/suite/integration.test.ts +++ b/clients/vscode-hlasmplugin/src/test/suite/integration.test.ts @@ -15,194 +15,160 @@ import * as assert from 'assert'; import * as vscode from 'vscode'; import * as path from 'path'; +import * as helper from './testHelper'; suite('Integration Test Suite', () => { - const workspacePath = vscode.workspace.workspaceFolders[0].uri.fsPath; - - const workspace_file = 'open'; - const get_editor = () => { - const editor = vscode.window.activeTextEditor; - assert.equal(editor.document.uri.fsPath, path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, workspace_file)); - - return editor; - } - const sleep = (ms: number) => { - return new Promise((resolve) => { setTimeout(resolve, ms) }); - }; - - suiteSetup(async function () { - this.timeout(30000); - // 'open' should be in workspace - const files = await vscode.workspace.findFiles(workspace_file); - - assert.ok(files && files[0]); - const file = files[0]; - - // open the file - const document = await vscode.workspace.openTextDocument(file); - - await vscode.window.showTextDocument(document); - }); - - // open 'open' file, should be recognized as hlasm - test('HLASM file open test', async () => { - const editor = get_editor(); - - // setting a language takes a while but shouldn't take longer than a second - await sleep(1000); - assert.ok(editor.document.languageId === 'hlasm'); - }).timeout(10000).slow(4000); - - // change 'open' file to create diagnostic - test('Diagnostic test', async () => { - const editor = get_editor(); - - // register callback to check for the correctness of the diagnostic - const diagnostic_event = new Promise<[vscode.Uri, vscode.Diagnostic[]][]>((resolve, reject) => { - const listener = vscode.languages.onDidChangeDiagnostics((_) => { - listener.dispose(); - resolve(vscode.languages.getDiagnostics()); - }); - }); - // remove second parameter from LR instruction - await editor.edit(edit => { - edit.delete(new vscode.Range(new vscode.Position(2, 6), new vscode.Position(2, 7))); - }); - - const allDiags = await diagnostic_event; - const openDiags = allDiags.find(pair => pair[0].path.endsWith("open"))[1] - - assert.ok(openDiags.length == 1 && openDiags[0].code == 'M003', 'Wrong diagnostic'); - }).timeout(10000).slow(1000); - - // test completion for instructions - test('Completion Instructions test', async () => { - const editor = get_editor(); - await editor.edit(edit => { - edit.insert(new vscode.Position(7, 1), 'L'); - }); - const movePosition = new vscode.Position(7, 2); - editor.selection = new vscode.Selection(movePosition, movePosition); - - await vscode.commands.executeCommand('editor.action.triggerSuggest'); - await sleep(1000); - - await vscode.commands.executeCommand('acceptSelectedSuggestion'); - await sleep(1000); - - const text = editor.document.getText(); - const acceptedLine = text.split('\n')[7]; - - assert.ok(acceptedLine.includes('L R,D12U(X,B)'), 'Wrong suggestion result' + acceptedLine); - }).timeout(10000).slow(4000); - - // test completion for variable symbols - test('Completion Variable symbol test', async () => { - const editor = get_editor(); - // add '&' to simulate start of a variable symbol - await editor.edit(edit => { - edit.insert(new vscode.Position(8, 0), '&'); - }); - const movePosition = new vscode.Position(8, 1); - editor.selection = new vscode.Selection(movePosition, movePosition); - - await vscode.commands.executeCommand('editor.action.triggerSuggest'); - await sleep(1000); - - await vscode.commands.executeCommand('acceptSelectedSuggestion') - await sleep(1000); - - const text = editor.document.getText(); - const acceptedLine = text.split('\n')[8]; - - assert.ok(acceptedLine.includes('&VAR'), 'Wrong suggestion result' + acceptedLine); - }).timeout(10000).slow(4000); - - // go to definition for ordinary symbol - test('Definition Ordinary symbol test', async () => { - const editor = get_editor(); - const result: vscode.Location[] = await vscode.commands.executeCommand('vscode.executeDefinitionProvider', editor.document.uri, new vscode.Position(1, 7)); - - assert.ok(result.length == 1 - && result[0].uri.fsPath == editor.document.fileName - && result[0].range.start.line == 9 - && result[0].range.start.character == 0, 'Wrong ordinary symbol definition location'); - }).timeout(10000).slow(1000); - - // hover for variable symbol - test('Hover Variable symbol test', async () => { - const editor = get_editor(); - const result: vscode.Hover[] = await vscode.commands.executeCommand('vscode.executeHoverProvider', editor.document.uri, new vscode.Position(6, 8)); - - assert.ok(result.length == 1 - && result[0].contents.length == 1 - && (result[0].contents[0] as vscode.MarkdownString).value == 'SETA variable', 'Wrong variable symbol hover contents'); - }).timeout(10000).slow(1000); - - // go to definition for macros - test('Definition Macro test', async () => { - const editor = get_editor(); - const result: vscode.Location[] = await vscode.commands.executeCommand('vscode.executeDefinitionProvider', editor.document.uri, new vscode.Position(6, 2)); - assert.ok(result.length == 1 - && result[0].uri.fsPath == path.join(workspacePath, 'libs', 'mac.asm') - && result[0].range.start.line == 1 - && result[0].range.start.character == 4, 'Wrong macro definition location'); - }).timeout(10000).slow(1000); - - // debug open code test - test('Debug test', async () => { - const session_started_event = new Promise((resolve) => { - // when the debug session starts - const disposable = vscode.debug.onDidStartDebugSession((session) => { - disposable.dispose(); - resolve(session); - }); - }); - // start debugging - if (!await vscode.debug.startDebugging(vscode.workspace.workspaceFolders[0], 'Macro tracer: current program')) - throw new Error("Failed to start a debugging session"); - - const session = await session_started_event; - - // wait a second to let the debug session complete - await sleep(1000); - // step over once - await vscode.commands.executeCommand('workbench.action.debug.stepOver'); - // wait 1 more second to let step over take place - await sleep(1000); - // then check for VAR2 variable - const scopesResult = await session.customRequest('scopes', { frameId: 0 }); - - const scopes = scopesResult.body ? scopesResult.body.scopes : scopesResult.scopes; - - const reference = scopes.find((scope: { name: string }) => scope.name == 'Locals').variablesReference; - const variablesResult = await session.customRequest('variables', { variablesReference: reference }); - - await vscode.commands.executeCommand('workbench.action.debug.stop'); - - const variables = variablesResult.body ? variablesResult.body.variables : variablesResult.variables; - - assert.ok(variables.length == 1 && variables[0].value == 'SOMETHING' && variables[0].name == '&VAR2', 'Wrong debug variable &VAR2'); - }).timeout(10000).slow(4000); - - // verify that library patterns are working - test('Test library patterns', async () => { - const files = await vscode.workspace.findFiles('pattern_test/test_pattern.hlasm'); - - assert.ok(files && files[0]); - const file = files[0]; - - // open the file - const document = await vscode.workspace.openTextDocument(file); - - await vscode.window.showTextDocument(document); - - await sleep(2000); - - const allDiags = vscode.languages.getDiagnostics(); - const patternDiags = allDiags.find(pair => pair[0].path.endsWith("test_pattern.hlasm")) - - if (patternDiags) - assert.ok(patternDiags[1].length == 0, 'Library patterns are not working'); - }).timeout(10000).slow(2500); + const workspace_file = 'open'; + let editor: vscode.TextEditor; + + suiteSetup(async function () { + this.timeout(30000); + + await helper.showDocument(workspace_file); + editor = helper.get_editor(workspace_file); + }); + + // open 'open' file, should be recognized as hlasm + test('HLASM file open test', async () => { + // setting a language takes a while but shouldn't take longer than a second + await helper.sleep(1000); + assert.ok(editor.document.languageId === 'hlasm'); + }).timeout(10000).slow(4000); + + // change 'open' file to create diagnostic + test('Diagnostic test', async () => { + // register callback to check for the correctness of the diagnostic + const diagnostic_event = new Promise<[vscode.Uri, vscode.Diagnostic[]][]>((resolve, reject) => { + const listener = vscode.languages.onDidChangeDiagnostics((_) => { + listener.dispose(); + resolve(vscode.languages.getDiagnostics()); + }); + }); + // remove second parameter from LR instruction + await editor.edit(edit => { + edit.delete(new vscode.Range(new vscode.Position(2, 6), new vscode.Position(2, 7))); + }); + + const allDiags = await diagnostic_event; + const openDiags = allDiags.find(pair => pair[0].path.endsWith("open"))[1] + + assert.ok(openDiags.length == 1 && openDiags[0].code == 'M003', 'Wrong diagnostic'); + }).timeout(10000).slow(1000); + + // test completion for instructions + test('Completion Instructions test', async () => { + await helper.insertString(editor, new vscode.Position(7, 1), 'L'); + + await vscode.commands.executeCommand('editor.action.triggerSuggest'); + await helper.sleep(1000); + + await vscode.commands.executeCommand('acceptSelectedSuggestion'); + await helper.sleep(1000); + + const text = editor.document.getText(); + const acceptedLine = text.split('\n')[7]; + + assert.ok(acceptedLine.includes('L R,D12U(X,B)'), 'Wrong suggestion result' + acceptedLine); + }).timeout(10000).slow(4000); + + // test completion for variable symbols + test('Completion Variable symbol test', async () => { + await helper.insertString(editor, new vscode.Position(8, 0), '&'); + + await vscode.commands.executeCommand('editor.action.triggerSuggest'); + await helper.sleep(1000); + + await vscode.commands.executeCommand('acceptSelectedSuggestion') + await helper.sleep(1000); + + const text = editor.document.getText(); + const acceptedLine = text.split('\n')[8]; + + assert.ok(acceptedLine.includes('&VAR'), 'Wrong suggestion result' + acceptedLine); + }).timeout(10000).slow(4000); + + // go to definition for ordinary symbol + test('Definition Ordinary symbol test', async () => { + const result: vscode.Location[] = await vscode.commands.executeCommand('vscode.executeDefinitionProvider', editor.document.uri, new vscode.Position(1, 7)); + + assert.ok(result.length == 1 + && result[0].uri.fsPath == editor.document.fileName + && result[0].range.start.line == 9 + && result[0].range.start.character == 0, 'Wrong ordinary symbol definition location'); + }).timeout(10000).slow(1000); + + // hover for variable symbol + test('Hover Variable symbol test', async () => { + const result: vscode.Hover[] = await vscode.commands.executeCommand('vscode.executeHoverProvider', editor.document.uri, new vscode.Position(6, 8)); + + assert.ok(result.length == 1 + && result[0].contents.length == 1 + && (result[0].contents[0] as vscode.MarkdownString).value == 'SETA variable', 'Wrong variable symbol hover contents'); + }).timeout(10000).slow(1000); + + // go to definition for macros + test('Definition Macro test', async () => { + const result: vscode.Location[] = await vscode.commands.executeCommand('vscode.executeDefinitionProvider', editor.document.uri, new vscode.Position(6, 2)); + assert.ok(result.length == 1 + && result[0].uri.fsPath == path.join(helper.getWorkspacePath(), 'libs', 'mac.asm') + && result[0].range.start.line == 1 + && result[0].range.start.character == 4, 'Wrong macro definition location'); + }).timeout(10000).slow(1000); + + // debug open code test + test('Debug test', async () => { + const session_started_event = new Promise((resolve) => { + // when the debug session starts + const disposable = vscode.debug.onDidStartDebugSession((session) => { + disposable.dispose(); + resolve(session); + }); + }); + // start debugging + if (!await vscode.debug.startDebugging(vscode.workspace.workspaceFolders[0], 'Macro tracer: current program')) + throw new Error("Failed to start a debugging session"); + + const session = await session_started_event; + + // wait a second to let the debug session complete + await helper.sleep(1000); + // step over once + await vscode.commands.executeCommand('workbench.action.debug.stepOver'); + // wait 1 more second to let step over take place + await helper.sleep(1000); + // then check for VAR2 variable + const scopesResult = await session.customRequest('scopes', { frameId: 0 }); + + const scopes = scopesResult.body ? scopesResult.body.scopes : scopesResult.scopes; + + const reference = scopes.find((scope: { name: string }) => scope.name == 'Locals').variablesReference; + const variablesResult = await session.customRequest('variables', { variablesReference: reference }); + + await vscode.commands.executeCommand('workbench.action.debug.stop'); + + const variables = variablesResult.body ? variablesResult.body.variables : variablesResult.variables; + + assert.ok(variables.length == 1 && variables[0].value == 'SOMETHING' && variables[0].name == '&VAR2', 'Wrong debug variable &VAR2'); + }).timeout(10000).slow(4000); + + // verify that library patterns are working + test('Test library patterns', async () => { + const files = await vscode.workspace.findFiles('pattern_test/test_pattern.hlasm'); + + assert.ok(files && files[0]); + const file = files[0]; + + // open the file + const document = await vscode.workspace.openTextDocument(file); + + await vscode.window.showTextDocument(document); + + await helper.sleep(2000); + + const allDiags = vscode.languages.getDiagnostics(); + const patternDiags = allDiags.find(pair => pair[0].path.endsWith("test_pattern.hlasm")) + + if (patternDiags) + assert.ok(patternDiags[1].length == 0, 'Library patterns are not working'); + }).timeout(10000).slow(2500); }); diff --git a/clients/vscode-hlasmplugin/src/test/suite/testHelper.ts b/clients/vscode-hlasmplugin/src/test/suite/testHelper.ts new file mode 100644 index 000000000..857baeac3 --- /dev/null +++ b/clients/vscode-hlasmplugin/src/test/suite/testHelper.ts @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 Broadcom. + * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Broadcom, Inc. - initial API and implementation + */ +import * as assert from 'assert'; +import * as vscode from "vscode"; +import * as path from 'path'; + +export function getWorkspacePath(): string { + return vscode.workspace.workspaceFolders[0].uri.fsPath;; +} + +export function get_editor(workspace_file: string): vscode.TextEditor { + const editor = vscode.window.activeTextEditor; + assert.equal(editor.document.uri.fsPath, path.join(getWorkspacePath(), workspace_file)); + + return editor; +} + +export async function showDocument(workspace_file: string) { + const files = await vscode.workspace.findFiles(workspace_file); + + assert.ok(files && files[0]); + const file = files[0]; + + // open and show the file + const document = await vscode.workspace.openTextDocument(file); + + await vscode.window.showTextDocument(document); +} + +export async function insertString(editor: vscode.TextEditor, position: vscode.Position, str: string): Promise { + await editor.edit(edit => { + edit.insert(position, str); + }); + + // Get number of lines in string and compute the new end position + const str_split = str.split('\n'); + const lines = str_split.length; + + const movePosition = new vscode.Position(position.line + lines - 1, lines == 1 ? position.character + str.length : str_split[lines].length); + editor.selection = new vscode.Selection(movePosition, movePosition); + + return movePosition; +} + +export function sleep(ms: number): Promise { + return new Promise((resolve) => { setTimeout(resolve, ms); }); +} + diff --git a/clients/vscode-hlasmplugin/src/test/workspace/.hlasmplugin/proc_grps.json b/clients/vscode-hlasmplugin/src/test/workspace/.hlasmplugin/proc_grps.json index ad4c4a2a2..53bf578d5 100644 --- a/clients/vscode-hlasmplugin/src/test/workspace/.hlasmplugin/proc_grps.json +++ b/clients/vscode-hlasmplugin/src/test/workspace/.hlasmplugin/proc_grps.json @@ -2,6 +2,9 @@ "pgroups": [ { "name": "P1", + "asm_options": { + "OPTABLE": "Z15" + }, "libs": [ { "path": "libs"