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

Cannot use wildcard to test multiple files at once on Windows #2

Open
denismaier opened this issue Jan 29, 2025 · 9 comments
Open

Cannot use wildcard to test multiple files at once on Windows #2

denismaier opened this issue Jan 29, 2025 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@denismaier
Copy link

Hi,
testing multiple files at once does not work as expected on Windows (tested on powershell and cmd):

Image

Using git bash the above syntax works perfectly. Don't know if this is an issue with powershell and cmd, or if this related to modish, or a combination of both...

@nchachereau nchachereau changed the title Testing multiple files at once on Windows Cannot use wildcard to test multiple files at once on Windows Jan 29, 2025
@nchachereau
Copy link
Owner

nchachereau commented Jan 29, 2025

I'm afraid I'm quite unfamiliar with the Windows command line (been on Linux for the past 15 or even 20 years). Apparently, unlike Unix shells, the Windows shell * does not expand the wildcard before passing the arguments to the command. So that modish gets the string 'tests/*.yml' instead of several arguments, each pointing to one test file.

I cannot test right now, but maybe something like the following works in Powershell?

modish test (dir tests/*.yml) -- or maybe modish test (dir tests/*.yml).FullName

(Of course, note that for that specific example one can simply run modish test to run all tests files in YAML in the tests/ directory.)

I will have to decide whether modish should expand wildcards itself when it gets strings that do not match existing files. Not so sure what the best course of action is.

@nchachereau
Copy link
Owner

nchachereau commented Jan 29, 2025

Oh, and I changed the title of this issue because modish test tests/actual_file.yml tests/other_file.yml tests/third_file.yml should work (i.e. explicitly passing the different files, without using a wildcard). Could you confirm this?

@denismaier
Copy link
Author

Yes, that works as expected.

@denismaier
Copy link
Author

denismaier commented Jan 29, 2025

Apparently, there a multiple javascript packages that take care of wildcard patterns, e.g. glob

Some notes on usage

@nchachereau
Copy link
Owner

We would not even have to depend on an external package, but could use expandGlob from Deno's @std/fs.

What I am unsure about is when we should expand the input:

  • whenever the OS is Windows?
  • when trying to read a test file raises an OS Error 123? (Can we test for that?)
  • combining the previous two cases? (but error 123 is probably only ever raised on Windows anyway)
  • some other case?

@nchachereau nchachereau self-assigned this Jan 29, 2025
@nchachereau nchachereau added the enhancement New feature or request label Jan 29, 2025
@denismaier
Copy link
Author

denismaier commented Jan 29, 2025 via email

@nchachereau
Copy link
Owner

Well, it is perfectly valid for a filename in Unix to include wildcard characters such as * or ?. In your shell, if you write modish test tests/book*.yml, this then gets expanded by the shell (modish would then get, say, the list of files tests/book1.yml tests/book2.yml tests/book*.yml. If instead you quote the input, the shell does not expand it, and you expect the program to receive that exact argument (modish test 'tests/book*.yml').

Expanding in every case would thus introduce bugs for people on Linux or MacOS.

(Note: naming a file book*.yml might seem unlikely, but including ? or [...] in a filename is actually not that uncommon, for instance, for an epub of a book that has a question mark in its title.)

@denismaier
Copy link
Author

Ok, I see. The glob package claims to behave just like the shell would. It shouldn't make a difference whether the shell expands the wildcards or if expansion is done during processing. Is it possible to check whether the argument is quoted?

@nchachereau
Copy link
Owner

Note to self: this is a common problem (see e.g. pallets/click#1096 and BurntSushi/ripgrep#234).

Easiest way is probably to do it the way Click does it, i.e. always expand on Windows systems. I will implement the fix soon.

@nchachereau nchachereau added bug Something isn't working and removed enhancement New feature or request labels Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants