Skip to content

Commit

Permalink
workflow: enable tests with go1.18beta1
Browse files Browse the repository at this point in the history
* disable dlv's go version check for legacy debug adapter testing.
(when delve supporting go1.18 go-delve/delve#2831
is released, this is unnecessary).

* adjust various tests that were affected by go1.18's change
to replace interface{} with any.

Tested by running the github workflows from my fork.

Fixes #1950

Change-Id: I4e4bceaf9ad2c89f421ad4cb4da04e96a69ac7cb
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/374055
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
  • Loading branch information
hyangah committed Dec 28, 2021
1 parent 691e15f commit 143b6d9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-long-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
version: ['stable', 'insiders']
go: ['1.15', '1.16', '1.17']
go: ['1.15', '1.16', '1.17', '1.18.0-beta1']

steps:
- name: Clone repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-long.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest] # TODO: reenable macos-latest
version: ['stable']
go: ['1.15', '1.16', '1.17']
go: ['1.15', '1.16', '1.17', '1.18.0-beta1']

steps:
- name: Clone repository
Expand Down
11 changes: 9 additions & 2 deletions test/gopls/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { LanguageClient } from 'vscode-languageclient/node';
import { getGoConfig } from '../../src/config';
import { buildLanguageClient, BuildLanguageClientOption, buildLanguageServerConfig } from '../../src/goLanguageServer';
import sinon = require('sinon');
import { getGoVersion, GoVersion } from '../../src/util';

// FakeOutputChannel is a fake output channel used to buffer
// the output of the tested language client in an in-memory
Expand Down Expand Up @@ -132,7 +133,11 @@ suite('Go Extension Tests With Gopls', function () {
const testdataDir = path.join(projectDir, 'test', 'testdata');
const env = new Env();

suiteSetup(async () => await env.setup(path.resolve(testdataDir, 'gogetdocTestData', 'test.go')));
let goVersion: GoVersion;
suiteSetup(async () => {
await env.setup(path.resolve(testdataDir, 'gogetdocTestData', 'test.go'));
goVersion = await getGoVersion();
});
suiteTeardown(() => env.teardown());

this.afterEach(function () {
Expand All @@ -155,7 +160,9 @@ suite('Go Extension Tests With Gopls', function () {
[
'func Println()',
new vscode.Position(19, 6),
'func fmt.Println(a ...interface{}) (n int, err error)',
goVersion.lt('1.18')
? 'func fmt.Println(a ...interface{}) (n int, err error)'
: 'func fmt.Println(a ...any) (n int, err error)',
'Println formats '
],
['func print()', new vscode.Position(23, 4), 'func print(txt string)', 'This is an unexported function ']
Expand Down
66 changes: 55 additions & 11 deletions test/integration/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ import { testCurrentFile } from '../../src/goTest';
import {
getBinPath,
getCurrentGoPath,
getGoVersion,
getImportPath,
GoVersion,
handleDiagnosticErrors,
ICheckResult,
isVendorSupported
Expand All @@ -57,6 +59,7 @@ const testAll = (isModuleMode: boolean) => {
let generateFunctionTestSourcePath: string;
let generatePackageTestSourcePath: string;
let previousEnv: any;
let goVersion: GoVersion;

suiteSetup(async () => {
previousEnv = Object.assign({}, process.env);
Expand All @@ -69,6 +72,8 @@ const testAll = (isModuleMode: boolean) => {
assert.ok(gopath, 'Cannot run tests if GOPATH is not set as environment variable');
return;
}
goVersion = await getGoVersion();

console.log(`Using GOPATH: ${gopath}`);

repoPath = isModuleMode ? fs.mkdtempSync(path.join(os.tmpdir(), 'legacy')) : path.join(gopath, 'src', 'test');
Expand Down Expand Up @@ -225,13 +230,16 @@ standard output. Spaces are always added between operands and a newline is
appended. It returns the number of bytes written and any write error
encountered.
`;
const printlnSig = goVersion.lt('1.18')
? 'Println(a ...interface{}) (n int, err error)'
: 'Println(a ...any) (n int, err error)';

const testCases: [vscode.Position, string, string, string[]][] = [
[
new vscode.Position(19, 13),
'Println(a ...interface{}) (n int, err error)',
printlnSig,
printlnDoc,
['a ...interface{}']
[goVersion.lt('1.18') ? 'a ...interface{}' : 'a ...any']
],
[
new vscode.Position(23, 7),
Expand Down Expand Up @@ -272,12 +280,16 @@ encountered.
Spaces are always added between operands and a newline is appended.
It returns the number of bytes written and any write error encountered.
`;
const printlnSig = goVersion.lt('1.18')
? 'Println(a ...interface{}) (n int, err error)'
: 'Println(a ...any) (n int, err error)';

const testCases: [vscode.Position, string, string, string[]][] = [
[
new vscode.Position(19, 13),
'Println(a ...interface{}) (n int, err error)',
printlnSig,
printlnDoc,
['a ...interface{}']
[goVersion.lt('1.18') ? 'a ...interface{}' : 'a ...any']
],
[
new vscode.Position(23, 7),
Expand Down Expand Up @@ -314,6 +326,10 @@ standard output. Spaces are always added between operands and a newline is
appended. It returns the number of bytes written and any write error
encountered.
`;
const printlnSig = goVersion.lt('1.18')
? 'Println func(a ...interface{}) (n int, err error)'
: 'Println func(a ...any) (n int, err error)';

const testCases: [vscode.Position, string | null, string | null][] = [
// [new vscode.Position(3,3), '/usr/local/go/src/fmt'],
[new vscode.Position(0, 3), null, null], // keyword
Expand All @@ -322,7 +338,7 @@ encountered.
[new vscode.Position(28, 16), null, null], // inside a number
[new vscode.Position(22, 5), 'main func()', '\n'],
[new vscode.Position(40, 23), 'import (math "math")', null],
[new vscode.Position(19, 6), 'Println func(a ...interface{}) (n int, err error)', printlnDoc],
[new vscode.Position(19, 6), printlnSig, printlnDoc],
[
new vscode.Position(23, 4),
'print func(txt string)',
Expand Down Expand Up @@ -350,6 +366,10 @@ encountered.
Spaces are always added between operands and a newline is appended.
It returns the number of bytes written and any write error encountered.
`;
const printlnSig = goVersion.lt('1.18')
? 'func Println(a ...interface{}) (n int, err error)'
: 'func Println(a ...any) (n int, err error)';

const testCases: [vscode.Position, string | null, string | null][] = [
[new vscode.Position(0, 3), null, null], // keyword
[new vscode.Position(23, 11), null, null], // inside a string
Expand All @@ -366,7 +386,7 @@ It returns the number of bytes written and any write error encountered.
'package math',
'Package math provides basic constants and mathematical functions.\n\nThis package does not guarantee bit-identical results across architectures.\n'
],
[new vscode.Position(19, 6), 'func Println(a ...interface{}) (n int, err error)', printlnDoc],
[new vscode.Position(19, 6), printlnSig, printlnDoc],
[
new vscode.Position(27, 14),
'type ABC struct {\n a int\n b int\n c int\n}',
Expand All @@ -384,7 +404,13 @@ It returns the number of bytes written and any write error encountered.
await testHoverProvider(config, testCases);
});

test('Linting - concurrent process cancelation', async () => {
test('Linting - concurrent process cancelation', async function () {
if (!goVersion.lt('1.18')) {
// TODO(hyangah): reenable test when staticcheck for go1.18 is released
// https://github.com/dominikh/go-tools/issues/1145
this.skip();
}

const util = require('../../src/util');
const processutil = require('../../src/utils/processUtils');
sinon.spy(util, 'runTool');
Expand Down Expand Up @@ -413,7 +439,12 @@ It returns the number of bytes written and any write error encountered.
);
});

test('Linting - lint errors with multiple open files', async () => {
test('Linting - lint errors with multiple open files', async function () {
if (!goVersion.lt('1.18')) {
// TODO(hyangah): reenable test when staticcheck for go1.18 is released
// https://github.com/dominikh/go-tools/issues/1145
this.skip();
}
// handleDiagnosticErrors may adjust the lint errors' ranges to make the error more visible.
// This adjustment applies only to the text documents known to vscode. This test checks
// the adjustment is made consistently across multiple open text documents.
Expand Down Expand Up @@ -448,7 +479,13 @@ It returns the number of bytes written and any write error encountered.
assert.deepStrictEqual(file1Diagnostics[0], file2Diagnostics[0]);
});

test('Error checking', async () => {
test('Error checking', async function () {
if (!goVersion.lt('1.18')) {
// TODO(hyangah): reenable test when staticcheck for go1.18 is released
// https://github.com/dominikh/go-tools/issues/1145
this.skip();
}

const config = Object.create(getGoConfig(), {
vetOnSave: { value: 'package' },
vetFlags: { value: ['-all'] },
Expand Down Expand Up @@ -901,10 +938,14 @@ standard output. Spaces are always added between operands and a newline is
appended. It returns the number of bytes written and any write error
encountered.
`;
const printlnSig = goVersion.lt('1.18')
? 'func(a ...interface{}) (n int, err error)'
: 'func(a ...any) (n int, err error)';

const provider = new GoCompletionItemProvider();
const testCases: [vscode.Position, string, string | null, string | null][] = [
[new vscode.Position(7, 4), 'fmt', 'fmt', null],
[new vscode.Position(7, 6), 'Println', 'func(a ...interface{}) (n int, err error)', printlnDoc]
[new vscode.Position(7, 6), 'Println', printlnSig, printlnDoc]
];
const uri = vscode.Uri.file(path.join(fixturePath, 'baseTest', 'test.go'));
const textDocument = await vscode.workspace.openTextDocument(uri);
Expand Down Expand Up @@ -980,7 +1021,10 @@ encountered.
if (!item1) {
assert.fail('Suggestion with label "Print" not found in test case withFunctionSnippet.');
}
assert.equal((<vscode.SnippetString>item1.insertText).value, 'Print(${1:a ...interface{\\}})');
assert.equal(
(<vscode.SnippetString>item1.insertText).value,
goVersion.lt('1.18') ? 'Print(${1:a ...interface{\\}})' : 'Print(${1:a ...any})'
);
});
const withFunctionSnippetNotype = provider
.provideCompletionItemsInternal(
Expand Down
16 changes: 15 additions & 1 deletion test/integration/goDebug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ suite('GoDebugSession Tests', async () => {
process.env.GOPATH = '/usr/gopath';
process.env.GOROOT = '/usr/goroot';
remoteSourcesAndPackages = new RemoteSourcesAndPackages();
// eslint-disable-next-line prettier/prettier
fileSystem = ({ existsSync: () => false } as unknown) as typeof fs;
delve.program = workspaceFolder;
delve.isApiV1 = false;
Expand Down Expand Up @@ -287,6 +288,7 @@ suite('RemoteSourcesAndPackages Tests', () => {
let remoteSourcesAndPackages: RemoteSourcesAndPackages;
let delve: Delve;
setup(() => {
// eslint-disable-next-line prettier/prettier
delve = ({ callPromise: () => ({}), isApiV1: false } as unknown) as Delve;
remoteSourcesAndPackages = new RemoteSourcesAndPackages();
});
Expand Down Expand Up @@ -399,7 +401,13 @@ const testAll = (ctx: Mocha.Context, isDlvDap: boolean) => {
): Promise<cp.ChildProcess> {
const serverFolder = path.join(DATA_ROOT, 'helloWorldServer');
const toolPath = getBinPath('dlv');
const args = ['debug', '--api-version=2', '--headless', `--listen=127.0.0.1:${dlvPort}`];
const args = [
'debug',
'--check-go-version=false',
'--api-version=2',
'--headless',
`--listen=127.0.0.1:${dlvPort}`
];
if (acceptMultiClient) {
args.push('--accept-multiclient');
}
Expand Down Expand Up @@ -2170,6 +2178,12 @@ const testAll = (ctx: Mocha.Context, isDlvDap: boolean) => {
config['showLog'] = true;
config['trace'] = 'verbose';
}

// disable version check (like in dlv-dap).
if (!isDlvDap) {
const dlvFlags = config['dlvFlags'] || [];
config['dlvFlags'] = ['--check-go-version=false'].concat(dlvFlags);
}
// Give each test a distinct debug binary. If a previous test
// and a new test use the same binary location, it is possible
// that the second test could build the binary, and then the
Expand Down

0 comments on commit 143b6d9

Please sign in to comment.