haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.62k stars 697 forks source link

Gotchas of `[TARGETS]`; implicit vs `all` vs combinations #9942

Open philderbeast opened 6 months ago

philderbeast commented 6 months ago

cabal test [TARGETS] [FLAGS] runs the specified test suites (all the test suites in the current package by default), first ensuring they are up to date.

In the docs we could say that there is an implicit current package if we're in the same directory as a .cabal package description file.

https://github.com/haskell/cabal/blob/bccc59f78f64d8db8605380d6735e0730d8bea23/cabal-install/tests/IntegrationTests2.hs#L196-L200

We could clear up some possible gotchas;

$ cabal test Cabal-tests:all:tests
Error: [Cabal-7131]
Unknown target 'Cabal-tests:all:tests'.
The package Cabal-tests has no component 'all'.
$ cabal test Cabal-tests:tests --dry-run
Build profile: -w ghc-9.8.2 -O1
In order, the following would be built (use -v for more details):
 - Cabal-tests-3 (test:check-tests) (ephemeral targets)
 - Cabal-tests-3 (test:custom-setup-tests) (ephemeral targets)
 - Cabal-tests-3 (test:hackage-tests) (ephemeral targets)
 - Cabal-tests-3 (test:no-thunks-test) (ephemeral targets)
 - Cabal-tests-3 (test:parser-tests) (ephemeral targets)
 - Cabal-tests-3 (test:rpmvercmp) (ephemeral targets)
 - Cabal-tests-3 (test:unit-tests) (ephemeral targets)

$ cabal test Cabal-tests:tests all:tests --dry-run
Build profile: -w ghc-9.8.2 -O1
In order, the following would be built (use -v for more details):
 - Cabal-tests-3 (test:check-tests) (ephemeral targets)
 - Cabal-tests-3 (test:custom-setup-tests) (ephemeral targets)
 - Cabal-tests-3 (test:hackage-tests) (ephemeral targets)
 - Cabal-tests-3 (test:no-thunks-test) (ephemeral targets)
 - Cabal-tests-3 (test:parser-tests) (ephemeral targets)
 - Cabal-tests-3 (test:rpmvercmp) (ephemeral targets)
 - Cabal-tests-3 (test:unit-tests) (ephemeral targets)
 - cabal-benchmarks-3 (test:cabal-benchmarks) (ephemeral targets)
 - cabal-install-3.13.0.0 (test:integration-tests2)
 - cabal-install-3.13.0.0 (test:long-tests)
 - cabal-install-3.13.0.0 (test:mem-use-tests)
 - cabal-install-3.13.0.0 (test:unit-tests)
 - cabal-install-solver-3.13.0.0 (test:unit-tests) (ephemeral targets)
 - solver-benchmarks-3 (test:unit-tests) (ephemeral targets)

$ cabal test Cabal-tests:tests all:exes --dry-run
No tests to run for all the executables in the project
$ cabal test all:Cabal-tests:tests --dry-run
Error: [Cabal-7043]
Cannot test the package all, it is not in this project (either directly or indirectly). If you want to add it to the project then edit the cabal.project file.

I generated code snippets with;

$ git rev-parse HEAD
bccc59f78f64d8db8605380d6735e0730d8bea23
philderbeast commented 6 months ago

I get an ambiguous target for a package named "all" too;

$ mkdir all

$ cd all

$ cabal init
...

$ cabal build all
Error: [Cabal-7132]
Ambiguous target 'all'. It could be:
    :all (package *)
   all:all (component)

$ cabal test all:tests
Error: [Cabal-7132]
Ambiguous target 'all:tests'. It could be:
    :all:tests (package *:filter)
   pkg:all:tests (package:filter)
philderbeast commented 6 months ago

I also get an ambiguous target if I name a testsuite all.

$ cabal build all
Error: [Cabal-7132]
Ambiguous target 'all'. It could be:
    :all (package *)
   all-component:all (component)