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

Separate build-tags and test-tags #1842

Closed
johan-lejdung opened this issue Aug 13, 2018 · 13 comments
Closed

Separate build-tags and test-tags #1842

johan-lejdung opened this issue Aug 13, 2018 · 13 comments

Comments

@johan-lejdung
Copy link
Contributor

johan-lejdung commented Aug 13, 2018

Hi!

I have come across a use-case that is not covered by this extension, a use-case that I cannot imagine being alone with.

For many of my Go projects I have integration tests, these are tests that spin up docker containers and take longer to run. I also like to test my code on save.. To let me have the best of two worlds, fast running tests on save and longer integration tests on demand, I tag my integration tests with:

// +build integration

This stops the file from building unless I supply the tag with the build or test command.

Unfortunately this also disables the linting and syntax checks on the file, making it really hard to verify the code is working.

Atom solves this by having an option for build tags for build/install commands and a command for build tags for tests. I am not finding it possible to do a similar configuration with Visual Studio Code. All i find is go.buildTags which affects both build and save.

Are there any plans to fix that?

@ramya-rao-a
Copy link
Contributor

When you say you'd like to test your code on save, are you referring to the linter and syntax checks or actual tests that are run?

@johan-lejdung
Copy link
Contributor Author

Well both of it, but I am referring to actual tests being run.

As long as the tests are simple unit tests they run fast enough, but of course they only run if the linter and syntax checks pass :)

@ramya-rao-a
Copy link
Contributor

I would suggest the below:

  • Add the tag !fastRunning on the files that have the integration tests
  • Add "go.testFlags": ["-tags", "fastRunning"] to your settings
    At this point, linter and syntax checks will run on all files, test on save will not run on the integration tests.

Set up a test task to run just all tests. Tasks have no knowledge of the go extension and so no knowldge of its settings.

  • Run command Tasks: Configure Task -> Create tasks.json file from template -> Choose "Others" from the template options
  • Update the command to go test <your package name>.
  • Run command Tasks: Run Task and then choose your task to run all the tests on demand.

See https://code.visualstudio.com/Docs/editor/tasks to learn more about tasks

@ramya-rao-a
Copy link
Contributor

Oh wait, my bad. The go.testFlags get used when compiling so you wont get the syntax checks. This is because go test is used to compile test files and go build is used to compile non test files.

You can use a small variation of the above.

  • Add the integration tag like you first described
  • Have the task run the build and/or run tests using the tag

You can now run the task on demand every once in a while to get feedback on errors or to run the tests themselves

@johan-lejdung
Copy link
Contributor Author

johan-lejdung commented Aug 14, 2018

Great, but then we are back full-circle. I still wont have linting and syntax checks on my test files unless I run it manually, which I already do today - task or not -.

I think that adding proper support for this would be great, especially considering that both Atom and GoLand covers this use-case. I really like VS-Code and wouldn't want to switch editors just because of this.

@ramya-rao-a
Copy link
Contributor

Adding proper support is definitely not off the table, I was just brainstorming ideas before we get there. We can definitely add a new setting called go.testTags to be used for when we run the tests and not for when compile them. Would that serve this scenario?

@johan-lejdung
Copy link
Contributor Author

Much appreciated, for trying to help out and find alternative solutions!

Yeah that would be super, if you are stretched for time I could look into it this weekend.

@ramya-rao-a
Copy link
Contributor

I would very much appreciate a PR :) Below are some code pointers:

@johan-lejdung
Copy link
Contributor Author

johan-lejdung commented Aug 14, 2018 via email

@ramya-rao-a
Copy link
Contributor

No worries, take your time.

@johan-lejdung
Copy link
Contributor Author

@ramya-rao-a is this considered closed already or is it only after a release?

@ramya-rao-a
Copy link
Contributor

Yes, this can be considered as closed.

For people who want to try this, you can use the beta version of this extension until we release an update.

@ramya-rao-a
Copy link
Contributor

The new go.testTags setting is now available for use in the latest update to this extension (0.6.90)

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 24, 2018
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

2 participants