Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

pass <package> to dlv test/debug if applicable #1164

Merged
merged 2 commits into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,13 @@ class Delve {

let env = Object.assign({}, process.env, fileEnv, launchArgsEnv);

let dirname = isProgramDirectory ? program : path.dirname(program);
if (!fileEnv['GOPATH'] && !launchArgsEnv['GOPATH'] && (mode === 'debug' || mode === 'test')) {
// If user hasnt specified GOPATH & file/package to debug is not under env['GOPATH'], then infer it from the file/package path
// Not applicable to exec mode in which case `program` need not point to source code under GOPATH
let programNotUnderGopath = !env['GOPATH'] || !getCurrentGoWorkspaceFromGOPATH(env['GOPATH'], isProgramDirectory ? program : path.dirname(program));
let programNotUnderGopath = !env['GOPATH'] || !getCurrentGoWorkspaceFromGOPATH(env['GOPATH'], dirname);
if (programNotUnderGopath ) {
env['GOPATH'] = getInferredGopath(isProgramDirectory ? program : path.dirname(program)) || env['GOPATH'];
env['GOPATH'] = getInferredGopath(dirname) || env['GOPATH'];
}
}

Expand Down Expand Up @@ -282,9 +283,12 @@ class Delve {
}
verbose('Using dlv at: ' + dlv);

let currentGOWorkspace = getCurrentGoWorkspaceFromGOPATH(env['GOPATH'], dirname);
let dlvArgs = [mode || 'debug'];
if (mode === 'exec') {
dlvArgs = dlvArgs.concat([program]);
} else if (currentGOWorkspace) {
dlvArgs = dlvArgs.concat([dirname.substr(currentGOWorkspace.length + 1)]);
}
dlvArgs = dlvArgs.concat(['--headless=true', '--listen=' + host + ':' + port.toString()]);
if (launchArgs.showLog) {
Expand Down
10 changes: 8 additions & 2 deletions src/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import cp = require('child_process');
import path = require('path');
import vscode = require('vscode');
import util = require('util');
import { parseEnvFile, getGoRuntimePath } from './goPath';
import { getToolsEnvVars, getGoVersion, LineBuffer, SemVersion, resolvePath } from './util';
import { parseEnvFile, getGoRuntimePath, getCurrentGoWorkspaceFromGOPATH } from './goPath';
import { getToolsEnvVars, getGoVersion, LineBuffer, SemVersion, resolvePath, getCurrentGoPath } from './util';
import { GoDocumentSymbolProvider } from './goOutline';
import { getNonVendorPackages } from './goPackages';

Expand Down Expand Up @@ -127,6 +127,12 @@ export function goTest(testconfig: TestConfig): Thenable<boolean> {
return Promise.resolve();
}

// append the package name to args if applicable
Copy link
Contributor

@ramya-rao-a ramya-rao-a Sep 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • this might not work in case of multiple GOPATHs, because then process.env['GOPATH'] can have : or ; separated paths. Follow https://github.com/Microsoft/vscode-go/blob/0.6.63/src/goCheck.ts#L180-L181 instead
  • we are moving away from using GOPATH from process.env. Instead use getCurrentGoPath()
  • When the command Go: Test All Packages In Workspace is run, this go test command will fail with "can't load package.. no buildable Go source files in ..." if the workspace itself is just a folder containing packages and not a package itself. So one way is to have the package import path as part of the TestConfig object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL again, I am not sure how the third item can be solved(and seems it is more than the effort here)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testconfig.includeSubDirectories is true only for the "test all pks in workspace" scenario.
So you can add a check to ensure testconfig.includeSubDirectories is false before adding the importPath

let currentGoWorkspace = getCurrentGoWorkspaceFromGOPATH(getCurrentGoPath(), testconfig.dir);
if (currentGoWorkspace && !testconfig.includeSubDirectories) {
args.push(testconfig.dir.substr(currentGoWorkspace.length + 1));
}

targetArgs(testconfig).then(targets => {
let outTargets = args.slice(0);
if (targets.length > 2) {
Expand Down