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

gotest -run flag needs to override user setting supplied -run flag #2260

Closed
DanMaples opened this issue Jan 18, 2019 · 3 comments
Closed

gotest -run flag needs to override user setting supplied -run flag #2260

DanMaples opened this issue Jan 18, 2019 · 3 comments

Comments

@DanMaples
Copy link

DanMaples commented Jan 18, 2019

The tool to run tests inserts a -run TestNameOne|TestNameTwo when ran by clicking the run file tests or the run test hover text in a *_test.go file. (see vscode-go/src/testUtils.ts:375)

This conflicts with user settings supplied -run regex flags, resulting in the error of:
go test: run flag may be set only once

In our project, our tests have suffixes of "_unit", "_acceptance", "_regression", etc... so our user settings file has:

"go.testFlags": [
        "-run",
        "^(.*_unit)$"
    ],

in it so that when tests are run on a file save, only the unit tests run.

Clicking run test results in:

Running tool: /usr/local/go/bin/go test github.com/CompanyName/projectName/packageName -run ^(TestNameOne_unit)$ -run ^(.*_unit)$

go test: run flag may be set only once
run "go help test" or "go help testflag" for more information
Error: Tests failed.

When clicking on the run package tests hover text, no -run regex is inserted by the tool so the command looks like:

Running tool: /usr/local/go/bin/go test -timeout 120s github.com/CompanyName/projectName/packageName -v -run ^(.*_unit)$

and it runs as expected.

It seems to us that there are a few potential solutions here, but we don't want to dictate any solution to you. It might just be easiest to say "Ignore the user settings -run regex commands when the tool is creating its own`

Thank you for your help, please let me know if there is anything else I can provide.
-Dan

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Jan 20, 2019

Thanks for reporting this @DanMaples!

I believe we add the -run followed by the test functions when running individual tests or when running all the tests in the file. As you have already noticed, we dont do this when running all the tests in the package.

It might just be easiest to say "Ignore the user settings -run regex commands when the tool is creating its own`

This would be the right approach. Also ignore such user settings when not needed in cases like when we run go test -c to find build errors

PRs are most welcome to make this change.
Code Pointers:

  • Build and Debug extension
  • The getTestFlags() function in the testUtils.ts file is the one that reads from the settings. All we need to do is to go through the different features that call this and prune out the run regex as needed

The below are the places where getTestFlags() is used

  • goBuild.ts: To run go test to file build errors in test file
  • goCheck.ts: To run tests when either go.testOnSave or go.coverOnSave settings are enabled
  • goCover.ts: To all tests in the package when the Toggle Code Coverage in Package command is run
  • goRunTestCodelens.ts: To create the codelens links above test functions
  • goTest.ts: For all the test related commands

@scriptonist
Copy link
Contributor

Hey, 👋 I can try to work on this. I'm very new to the codebase and TS itself. I may take some time and would need some help to tackle this. If It's alright I can start working on this 😅 😃

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Nov 5, 2019

The latest update to this extension (0.11.8) has the fix for this.

Thanks @DanMaples for reporting and @scriptonist for the fix

Happy Coding!

@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants