Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not try to run tests for :GoTestCompile #1519

Merged
merged 1 commit into from
Oct 18, 2017

Conversation

bhcleek
Copy link
Collaborator

@bhcleek bhcleek commented Oct 18, 2017

Do not try to run a non-existent test for :GoTestCompile. Instead,
compile tests to a temporary file with go test -c in order to avoid
problems that may be caused by runtime errors in an init function when
trying to run a non-existent test.

To avoid the problems that 21376e6
resolved, this change relies on Vim's managing of the temporary
directory instead.

Fixes #1515

@fatih
Copy link
Owner

fatih commented Oct 18, 2017

What happens to testfile? The change previously wouldn't create any binary. Imho if we decide to get rid of it (due the problem outlined in #1515) we should also delete the created testfile

@bhcleek
Copy link
Collaborator Author

bhcleek commented Oct 18, 2017

As it stands right now, the OS will clean up the file if/when it needs to, and Vim will also clean it up when Vim exits, but I can add back the callbacks to try to clean it up after the go test -c completes.

FWIW, I vascillated on whether to delete it or not, because it won't for sure get deleted for the reasons outlined in 21376e689d6b701b4367cf121da4cfcf17e5fa19, but we can give it a best effort; if the callback to delete doesn't get run, then Vim will clean up the file when it exits.

@fatih
Copy link
Owner

fatih commented Oct 18, 2017

I'm not sure how Vim deletes it if we quit it. Can you show the source code in vim-go (if it's done here) or the doc in Vim for it? I believe the binary will be still in CWD.

@bhcleek
Copy link
Collaborator Author

bhcleek commented Oct 18, 2017

Yeah, sorry about that; I had made some changes, then altered those just a bit to verify the file location, and then I only undid a portion of the debugging changes, which resulted in a commit that wasn't what I originally intended.

I've amended the commit to show what I'd originally intended to submit. As you can see, the filename comes from tempname(), which provides a temporary filename. The directory that it's created it is deleted by Vim automatically when Vim exits. And of course, operating systems are free to clean up the temp directories as they see fit.

Let me know if you still want to proactively delete the file.

" we're going to tell to run a test function that doesn't exist. This
" triggers a build of the test file itself but no tests will run.
call extend(args, ["-run", "499EE4A2-5C85-4D35-98FC-7377CD87F263"])
let testfile = tempname(). ".test"
Copy link
Owner

Choose a reason for hiding this comment

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

can you change this to .vim-go.test. At least it wouldn't be a surprise for some if they somehow delve /tmp and see tens of these files

@fatih
Copy link
Owner

fatih commented Oct 18, 2017

lgtm, just a small comment.

Do not try to run a non-existent test for :GoTestCompile. Instead,
compile tests to a temporary file with `go test -c` in order to avoid
problems that may be caused by runtime errors in an init function when
trying to run a non-existent test.

To avoid the problems that 21376e6
resolved, this change relies on Vim's managing of the temporary
directory instead.
@bhcleek bhcleek merged commit 0643e9e into fatih:master Oct 18, 2017
@bhcleek bhcleek deleted the fix-go-test-compile branch October 18, 2017 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When ensuring if a test compiles, TestMain() and any init() functions are executed
2 participants