Skip to content

extension: Test Suite Fails to Parse Subtests Correctly #3725

Open
@caioreix

Description

@caioreix

Describe the bug

When the code len of a subtest suite is called, it ends up causing an incorrect parse of the function, thus not properly generating the test command. It results in something like:
go test -timeout 30s -coverprofile=/tmp/vscode-xxx/go-code-cover -run ^\(\*testSuite\)\.TestSuite_Example$/^Success$ test

The expected output would be something like:
go test -timeout 30s -coverprofile=/tmp/vscode-xxx/go-code-cover -run ^TestSuite$ -m ^(TestSuite_Example$/^Success)$ test

This is happening due to escaping both the function name and the subtest name in this line:

export function escapeSubTestName(testFuncName: string, subTestName: string): string {
return `${testFuncName}/${subTestName}`
.replace(/\s/g, '_')
.split('/')
.map((part) => escapeRegExp(part), '')
.join('$/^');
}

Escaping only the second part would already solve the problem:
https://github.com/caioreix/vscode-go/blob/6061299ff2b1526292a9e1aeff77bf77b3f88f67/extension/src/subTestUtils.ts#L17-L25

Steps to reproduce the behavior:

To reproduce it, you can use the snippet below and click on the codelens 'run test' corresponding to the Success or Fail subtest (I used testify to make visualization easier, but the behavior is the same for any test suite):

package main

import (
	"testing"

	"github.com/stretchr/testify/suite"
)

type testSuite struct {
	suite.Suite
}

func TestSuite(t *testing.T) {
	suite.Run(t, new(testSuite))
}

func (t *testSuite) TestSuite_Example() {
	t.Run("Success", func() {})

	t.Run("Fail", func() {})
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions