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

cabal v2-test does not respect -- #6198

Open
tdammers opened this issue Aug 18, 2019 · 9 comments · May be fixed by #7454
Open

cabal v2-test does not respect -- #6198

tdammers opened this issue Aug 18, 2019 · 9 comments · May be fixed by #7454

Comments

@tdammers
Copy link

Describe the bug

Passing additional arguments to the test suite with cabal new-test / v2-test seems impossible.

To Reproduce

  1. Create a cabal project with a (trivial) test suite with type: exitcode-stdio-1.0.
  2. Run cabal v2-test -- --foo.

Expected behavior

The --foo argument is passed to the compiled test suite.

Observed behavior

Cabal fails with an error message:

cabal: Unknown target '--foo'.
There is no component '--foo'.
The project has no package '--foo'.

System informataion

  • Debian 9, x64
  • cabal: 2.4.1.0
  • ghc: The Glorious Glasgow Haskell Compilation System, version 8.6.5

Additional context

Note that cabal v2-test --help has the following to say on the matter of passing arguments to test suites:

To pass command-line arguments to a test suite, see the v2-run command.

Which, in turn, suggests using --.

@m-renaud
Copy link
Collaborator

See #5416 for details. In summary, you need to use cabal v2-run test:TARGET -- --foo.

This isn't particularly intuitive, at the minimum the error message should be improved it link out to some external docs.

@fgaz
Copy link
Member

fgaz commented Aug 19, 2019

There's also a v2-test flag that adds arguments if I'm not mistaken

@harpocrates
Copy link
Collaborator

There's --test-option/--test-options. I use it all the time for accepting the Haddock test suite (since v2-test does some more essential stuff that v2-run doesn't do).

cabal new-test --with-ghc ghc-8.6.3 --test-options='--accept'

@symbiont-sam-halliday
Copy link

symbiont-sam-halliday commented Aug 29, 2019

Just wanted to say that I'd love to see this added as a feature.

btw --test-option(s) flushes the caches... the v2-run workaround is the only way to pass parameters in anything except the smallest of codebases. See #6114

Would this also solve Perhaps that would solve #6209 ?

@emilypi
Copy link
Member

emilypi commented May 21, 2021

@ptkato this is a good one for you

@ptkato ptkato self-assigned this Jun 7, 2021
@ptkato
Copy link
Collaborator

ptkato commented Jun 7, 2021

I've been scouring the cabal-install codebase after an easy, yet non-disruptive, way to implement this feature using --. Turns out it is not possible for v2-test, as pointed out by @23Skidoo in #3638 (comment), all the arguments are just mangled together and then it's not possible anymore to know, with certainty, which argument is what. Unlike v2-run, that simply picks the first argument as a target and assume the rest as extra arguments, we can't do that for v2-test, because we have other possible flags in addition to the target.

Other than messing up with those lines in Main.hs, which could incur in a much much bigger rewrite, I'm out of ideas, anyone?

@Mikolaj
Copy link
Member

Mikolaj commented Jun 9, 2021

I'm afraid it does look disruptive and non-trivial, but OTOH it's obviously needed. I'm more worried about the spec, though. Do we have a uniform understanding of -- across all commands? E.g., what does expandResponse do? Are there other cases than v2-test that would treat -- specially? Does it conflict with expandResponse?

@ptkato
Copy link
Collaborator

ptkato commented Jun 9, 2021

Do we have a uniform understanding of -- across all commands?

Kinda? It seems to be just ignored by every command, but other than that, not really.

E.g., what does expandResponse do? Are there other cases than v2-test that would treat -- specially? Does it conflict with expandResponse?

I don't think modifications to -- would affect expandResponse in any way, since they don't interact with each other.

I'm afraid it does look disruptive and non-trivial, but OTOH it's obviously needed. I'm more worried about the spec, though.

That's a valid concern, maybe we could rely on something like a tuple (as it is spit out by break), or another custom type tailored to our needs.

@ptkato
Copy link
Collaborator

ptkato commented Jun 17, 2021

Alright, I gave using tuples a shot, and it was a terrible idea, a very big chunk of code goes around relying on the arguments as [String], and right now it wouldn't be worth it refactoring all that code; not even mentioning the unforeseen consequences of literally touching every command out there.

I was discussing with @fendor, and we concluded that the best approach would be to implement the -- behaviour in terms of --*-options, not literally, but conceptually. Considering that -- is used to pass arguments to a target executable, I propose:

  • The adoption of a generic --target-options flag, which could be called upon in two ways: directly using --target-options as a flag for a command; or using --, which then would be manually wired to --target-options (in the Main function, most likely); and
  • Deprecate the current --*-options flags, and while at that, they would all map to the new --target-options flag instead.

These would imply in much smaller changes, since it would rely on the flag machinery already in place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants