Gotchas of `[TARGETS]`; implicit vs `all` vs combinations
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
> 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;
* 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`](https://cabal.readthedocs.io/en/latest/cabal-commands.html#cabal-install) but no explicit mention of `all:tests` (or `all:benchmarks`). The `all:ctypes` target and `all` target are described as [target forms](https://cabal.readthedocs.io/en/stable/cabal-commands.html#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
```
Contributor guide
Assessment
This issue has not been assessed yet.