Skip to content

Commit

Permalink
Merge pull request #10 from visualfc/test
Browse files Browse the repository at this point in the history
test: support gop
  • Loading branch information
xushiwei authored Oct 22, 2023
2 parents 8bee5c1 + fa9c7fc commit 9187d06
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/goBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export async function goBuild(

const buildEnv = toolExecutionEnvironment();
const tmpPath = getTempFilePath('go-code-check');
const isTestFile = fileUri && fileUri.fsPath.endsWith('_test.go');
const isTestFile = fileUri && (fileUri.fsPath.endsWith('_test.go') || fileUri.fsPath.endsWith('_test.gop'));
const buildFlags: string[] = isTestFile
? getTestFlags(goConfig)
: Array.isArray(goConfig['buildFlags'])
Expand Down
8 changes: 6 additions & 2 deletions src/goDebugConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,14 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
// file path instead of the currently active file.
filename = debugConfiguration['program'];
}
debugConfiguration['mode'] = filename?.endsWith('_test.go') ? 'test' : 'debug';
debugConfiguration['mode'] =
filename?.endsWith('_test.go') || filename?.endsWith('_test.gop') ? 'test' : 'debug';
}

if (debugConfiguration['mode'] === 'test' && debugConfiguration['program'].endsWith('_test.go')) {
if (
debugConfiguration['mode'] === 'test' &&
(debugConfiguration['program'].endsWith('_test.go') || debugConfiguration['program'].endsWith('_test.gop'))
) {
// Running a test file in file mode does not make sense, so change the program
// to the directory.
debugConfiguration['program'] = path.dirname(debugConfiguration['program']);
Expand Down
10 changes: 10 additions & 0 deletions src/goMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ export function isGoFile(document: vscode.TextDocument): boolean {
}
return false;
}

export const GOP_MODE: Filter = { language: 'gop', scheme: 'file' };
export const GOP_MOD_MODE: Filter = { language: 'gop.mod', scheme: 'file' };

export function isGopFile(document: vscode.TextDocument): boolean {
if (vscode.languages.match(GOP_MODE, document) || vscode.languages.match(GOP_MOD_MODE, document)) {
return true;
}
return false;
}
7 changes: 4 additions & 3 deletions src/goRunTestCodelens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ import { GoBaseCodeLensProvider } from './goBaseCodelens';
import { GoDocumentSymbolProvider } from './goDocumentSymbols';
import { getBenchmarkFunctions, getTestFunctions } from './testUtils';
import { GoExtensionContext } from './context';
import { GO_MODE } from './goMode';
import { GO_MODE, GOP_MODE } from './goMode';

export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider {
static activate(ctx: vscode.ExtensionContext, goCtx: GoExtensionContext) {
const testCodeLensProvider = new this(goCtx);
ctx.subscriptions.push(vscode.languages.registerCodeLensProvider(GO_MODE, testCodeLensProvider));
ctx.subscriptions.push(vscode.languages.registerCodeLensProvider(GOP_MODE, testCodeLensProvider));
ctx.subscriptions.push(
vscode.workspace.onDidChangeConfiguration(async (e: vscode.ConfigurationChangeEvent) => {
if (!e.affectsConfiguration('go')) {
if (!e.affectsConfiguration('go') && !e.affectsConfiguration('gop')) {
return;
}
const updatedGoConfig = getGoConfig();
Expand All @@ -46,7 +47,7 @@ export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider {
const config = getGoConfig(document.uri);
const codeLensConfig = config.get<{ [key: string]: any }>('enableCodeLens');
const codelensEnabled = codeLensConfig ? codeLensConfig['runtest'] : false;
if (!codelensEnabled || !document.fileName.endsWith('_test.go')) {
if (!codelensEnabled || (!document.fileName.endsWith('_test.go') && !document.fileName.endsWith('_test.gop'))) {
return [];
}

Expand Down
6 changes: 3 additions & 3 deletions src/goTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function _testAtCursor(
if (!editor) {
throw new NotFoundError('No editor is active.');
}
if (!editor.document.fileName.endsWith('_test.go')) {
if (!editor.document.fileName.endsWith('_test.go') && !editor.document.fileName.endsWith('_test.gop')) {
throw new NotFoundError('No tests found. Current file is not a test file.');
}

Expand Down Expand Up @@ -86,7 +86,7 @@ async function _subTestAtCursor(
vscode.window.showInformationMessage('No editor is active.');
return;
}
if (!editor.document.fileName.endsWith('_test.go')) {
if (!editor.document.fileName.endsWith('_test.go') && !editor.document.fileName.endsWith('_test.gop')) {
vscode.window.showInformationMessage('No tests found. Current file is not a test file.');
return;
}
Expand Down Expand Up @@ -377,7 +377,7 @@ export function testCurrentFile(isBenchmark: boolean, getConfig = getGoConfig):
vscode.window.showInformationMessage('No editor is active.');
return false;
}
if (!editor.document.fileName.endsWith('_test.go')) {
if (!editor.document.fileName.endsWith('_test.go') && !editor.document.fileName.endsWith('_test.gop')) {
vscode.window.showInformationMessage('No tests found. Current file is not a test file.');
return false;
}
Expand Down

0 comments on commit 9187d06

Please sign in to comment.