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

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

Open
philderbeast opened this issue Apr 27, 2024 · 2 comments
Open

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

philderbeast opened this issue Apr 27, 2024 · 2 comments

Comments

@philderbeast
Copy link
Collaborator

philderbeast commented Apr 27, 2024

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.

[ "all:libs", ":all:libs"
, "all:flibs", ":all:flibs"
, "all:exes", ":all:exes"
, "all:tests", ":all:tests"
, "all:benchmarks", ":all:benchmarks"]

We could clear up some possible gotchas;

  • the all target is always all tests of a project (for cabal test all), even if the directory of a package when another reasonable expectation is all tests in the package. What is the interaction between project and implicit current package for [TARGETS] that don't scope to a package explicitly?

  • when in a package directory, the package is automatically set as the target and, using Cabal-tests as the example, cabal test is the same as running cabal test Cabal-tests or cabal test Cabal-tests:tests from the root of the project. We could reasonably expect all to be set automatically if in the same directory as a project, couldn't we?

  • There's a note about all:exes in the docs for cabal install but no explicit mention of all:tests (or all:benchmarks). The all:ctypes target and all target are described as target forms. It would be good to document all the all use cases. We can't use this to refine a target, trying Cabal-tests:all:tests won't work.

$ cabal test Cabal-tests:all:tests
Error: [Cabal-7131]
Unknown target 'Cabal-tests:all:tests'.
The package Cabal-tests has no component 'all'.
  • There's interaction between exact targets and the all targets but is the interaction a "union" or an "intersection" or something else?
$ 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
  • all: cannot be used redundantly before a package and if tried, cabal looks for an all package;
$ 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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

philderbeast commented Apr 27, 2024

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)

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

No branches or pull requests

1 participant