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

Display warning if test file has unwritten changes #723

Open
andrew-cybsafe opened this issue Mar 15, 2023 · 6 comments
Open

Display warning if test file has unwritten changes #723

andrew-cybsafe opened this issue Mar 15, 2023 · 6 comments

Comments

@andrew-cybsafe
Copy link
Contributor

I'd like vim-test to display a warning if the test file I'm in has unsaved changes. I know that I can use the autowrite option, but running :wall here seems a bit aggressive for my liking. So I propose:

  • a new setting let g:test#warn_if_unsaved_changes = 1
  • a new test in s:before_run() which displays a warning to the user if the file isn't saved
  • document setting in help docs & readme

As a possible extension, the message could wait for user input to either save the current file, save all files, run it anyway or abort.

I'm happy to give this a go, but wanted to get thoughts from the maintainers before doing so.

@codeinabox
Copy link
Collaborator

Let me have a think about this and get back to you

@andrew-cybsafe
Copy link
Contributor Author

@codeinabox any thoughts on this?

@codeinabox
Copy link
Collaborator

Would this only apply to the test file when running TestFile? Would it also apply to the source file, and if so how would we detect which unsaved changes impact the test and which don't?

@andrew-cybsafe
Copy link
Contributor Author

In the general case, it's not feasible to check whether there are unsaved changes that will affect a test as there could be unsaved changes in other buffers, in another vim process, or in another editor. If this proposed change was accepted, then I'd suggest that we add a warning note in the docs on this point.

For my specific use case, I tend to be tweaking the test file and forget to save it before running the test, so a simple check of the state of the test file would suffice.

To make this more useful to others, I was thinking that a prompt would be useful, something like:

You have unsaved changes. [w] write file, [a] write all files, [c] continue

so the user can choose what to do in a particular situation.

@codeinabox
Copy link
Collaborator

If this is a behaviour that will just apply to TestFile then it's a viable option. It's got me thinking instead of a prompt, it could save a temporary copy of the test file with the unsaved changes and test against that if the user has enabled an option, in short testing against the buffer instead of saved file - what do you think?

@andrew-cybsafe
Copy link
Contributor Author

Running the test against the version in the buffer would be really nice. However, making this work reliably across all the various test runners might be quite awkward. For example, with pytest the following file name schemes don't work:

test_subject.py.tmp
.tmp.test_subject.py
test_subject.vim_123.py

The name vimtest_123.py does work. However, this scheme might not work for other test runners.

We may need to provide a default naming scheme, e.g. vimtest_NNNNN.{original extension}, but allow each runner to override this by defining a function that we look for that optionally overrides the test name creation logic.

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

No branches or pull requests

2 participants