You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I observe the following behavior. Summary: cabal new-test fails to resolve dependencies, while cabal new-test --enable-tests succeeds and runs the tests. I think they should both succeed and run the tests.
% cabal new-test
cabal: Cannot test the package bad-tests-0.1.0.0 because none of the
components are available to build: the test suite 'bad-tests' is not available
because the solver did not find a plan that included the test suites
zsh: exit 1 cabal new-test
% cabal new-test --enable-tests
Resolving dependencies...
Build profile: -w ghc-8.2.1 -O1
In order, the following will be built (use -v for more details):
- bad-tests-0.1.0.0 (first run)
Preprocessing test suite 'bad-tests' for bad-tests-0.1.0.0..
Building test suite 'bad-tests' for bad-tests-0.1.0.0..
Running 1 test suites...
Test suite bad-tests: RUNNING...
Test suite bad-tests: PASS
Test suite logged to:
<redacted>
1 of 1 test suites (1 of 1 test cases) passed.
The project itself is quite minimal. Here's bad-tests.cabal:
Iirc this was a deliberate design choice by @dcoutts to avoid invocations of cabal new-test w/o any flags to suddenly force recomputing a new install-plan (which differs in dependencies), only to have to recompute yet another one when we invoke cabal new-build or cabal new-bench (which btw suffers from the same symptom). The current behaviour causes the install-plans to remain stable when alternating between invocations of build/bench/test.
PS: Also, when we run the test-suite or benchmarks, we want to test the same configuration that we're working on w/ new-build; and not some different arbitrary one.
Given that constraint (which I'm not sure I agree with), I suspect the correct behavior is to default to creating a build plan that includes the tests and benchmarks (even in new-build), then prune those away along with any dependencies that are in the plan exclusively for them if the user hasn't asked for them. And of course one could fall back to the current way of creating an install plan when --disable-tests/--disable-benchmarks is supplied.
A stable build plan is nice. Having a build plan at all in the first place is even nicer.
Reacted by Mikhail Glushenkov, Simon Jakobi, Juri, Artem Pelenitsyn, AndreasPK and Simon Hengel
@phadej you also need to take care of the dimension on how much to build by default. Currently this is conflated: cabal new-build --enable-tests solves & enables test components, and builds every enabled target component.
@phadej Perhaps "local packages" instead of "as much as possible"? Although I still think "all tests" is the right default. It would be just as surprising for cabal new-test mydependency to fail and cabal new-test --enable-tests mydependency to succeed as it is without the explicit testing target.
@hvr We already have the target specification language for specifying what to build, right? And, luckily, the new-* promise is "alpha only, for intrepid users, interface may change", etc. so retrospectively inconsistent behavior like having --enable-tests imply more build targets can be fixed.
@dmwit I'm not worried much about changing the meaning of what all means, but rather that
we need to define what cabal new-build all means (which fortunately is not the same as cabal new-build, which rather refers to build the current in-CWD target). What components are considered active? Everything that got solved for?
In addition to have a way to say "build everything that has been solved for", we also need a way to say "build everything active except benchmarks and tests" or something like that, as tests & benchmarks are most often not what you want built unless you say cabal new-test or cabal new-bench -- at least I certainly don't want them built everytime I ask "all" to be built (even though I may want to have solved for everything); afaik we have some awkward ways to express that now, but not conveniently.
PS: and also note, that tests/benchmarks can be enabled/disabled at package granularity; it's not a project global setting
Coming from old-style cabal, it would be weird if all didn't mean "all the libraries and executables", since that's the default things to build in that style.
From a natural-language perspective, it would be weird if all didn't mean "all the things available to be built".
We want to avoid claiming too many magic top-level target specifiers, so making more specific magic targets like cabal new-build libraries executables or similar is undesirable.
Does that sound right?
If so, what if all could be given some :-based specifiers for picking which kind of components to build? Then as a first pass, one could imagine something like:
all: something familiar to old-style users, just libraries and executables
all:all: really everything
all:exe, all:lib, generally all:<component-type>: all the artifacts of the given type
as usual you can give multiple targets, so if you want all the libraries, executables, and tests, you could say all:exe all:lib all:test or all all:test for short.
From a natural-language perspective, it would be weird if all didn't mean "all the things available to be built".
c.f. -Wall vs -Weverything in GHC and Clang ;-)
We want to avoid claiming too many magic top-level target specifiers, so making more specific magic targets like cabal new-build libraries executables or similar is undesirable.
We have this already.... that's what I referred to as awkward/incovenient way; i.e. my most common use-case is to say something like cabal new-build exes libs flibs (not sure whether libs includes sub-libs). The trouble is that it's annoying to type, for what I consider a common use-case. :-)
I also suggest you take a look at the source-code comments in Distribution.Client.TargetSelector to get a better feeling for our rather rich (and partly undocumented -- hint, hint) target selector grammar... :-)
Just to put it out there, what about emulating GHC/Clang's warnings, and have
Just to point out the absurdity of the current situation:
$ cabal new-build --enable-tests -w ghc-7.10.3
... testsuites are built ...
$ cabal new-test -w ghc-7.10.3
Resolving dependencies...
cabal: Cannot test the package bsb-http-chunked-0.0.0.2 because none of the
components are available to build: the test suite 'tests' and the test suite
'doctests' are not available because the solver did not find a plan that
included the test suites
@sjakobi what's your mental model there? Are you assuming that the --enable-tests flag is stateful? In your example you passed -w ghc-7.10.3 to both new-build and new-test (if you didn't, new-test could easily pick a different GHC version; would that be absurd as well?), and yet you didn't pass --enable-tests to both.
Would you be surprised if
$ cabal new-run -w ghc-7.10.3 test:tests`
failed to find an install-plan because --enable-tests was left off? Wouldn't it be also absurd, if calling cabal new-build; cabal new-test; cabal new-build would cause the last invocation of new-buildnot to be idempotent?
Short observation: most want to solve for everything (incl tests) but build e.g. only lib part. I mentioned it already before that three state of (`--enable-tests`, `--disable-tests`, and no flag) is confusing. TargetSelector should be really a "SolverConfiguratorTargetSelector", targets we solve for are superset of build targets
On 20 Mar 2018, at 12.32, Herbert Valerio Riedel ***@***.***> wrote:
@sjakobi what's your mental model there? Are you assuming that the --enable-tests flag is stateful? In your example you passed -w ghc-7.10.3 to both new-build and new-test (if you didn't, new-test could easily pick a different GHC version; would that be absurd as well?), and yet you didn't pass --enable-tests to both.
Would you be surprised if
$ cabal new-run -w ghc-7.10.3 test:tests`
failed to find an install-plan because --enable-tests was left off?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
Having cabal build --enable-tests succeed but a subsequent cabal test fail is very puzzling.
I resolved it with the suggested tests: True in a cabal.project.local file. (*)
However, I was pessimistic that (*) would make a difference and surprised when it did.
How can you cabal test when tests are disabled? That cabal test would not include --enable-tests---that's what you call a paradox.
[Judging from the (existence of a) long discussion there seem to be internal reasons of some sort why there is a third truth value between tests: False and tests: True, or is there?]
In the case of haskell-hvr/deepseq-generics#12 there is just a single test suite, that apparently builds with cabal build --enable-tests. So I don't understand what cabal test is whining about. Haven't run into this problem before.
cabal test fails but increasing verbosity does not provide any insights why:
$ cabal test -v3
File monitor 'config' unchanged.
this build was affected by the following (project) config files:
File monitor 'improved-plan' unchanged.
CallStack (from HasCallStack):
withMetadata, called at src/Distribution/Simple/Utils.hs:379:14 in Cabal-3.7.0.0-inplace:Distribution.Simple.Utils
Error: cabal: Cannot test the package deepseq-generics-0.2.0.0 because none of
the components are available to build: the test suite 'deepseq-generics-tests'
is not available because the solver did not find a plan that included the test
suites. Force the solver to enable this for all packages by adding the line
'tests: True' to the 'cabal.project.local' file.
cabal test --enable-tests succeeds, yes.
$ cabal test --enable-tests
Resolving dependencies...
Build profile: -w ghc-9.2.1 -O1
In order, the following will be built (use -v for more details):
- deepseq-generics-0.2.0.0 (lib) (configuration changed)
- deepseq-generics-0.2.0.0 (test:deepseq-generics-tests) (configuration changed)
Configuring library for deepseq-generics-0.2.0.0..
Preprocessing library for deepseq-generics-0.2.0.0..
Building library for deepseq-generics-0.2.0.0..
Configuring test suite 'deepseq-generics-tests' for deepseq-generics-0.2.0.0..
Preprocessing test suite 'deepseq-generics-tests' for deepseq-generics-0.2.0.0..
Building test suite 'deepseq-generics-tests' for deepseq-generics-0.2.0.0..
Running 1 test suites...
Test suite deepseq-generics-tests: RUNNING...
Test suite deepseq-generics-tests: PASS
Yes, I agree the error messages are confusing, too, even though the hint in the last sentence works. I vote for adding the implicit, default --enable-tests (or something similar) to cabal test and creating --only-buildable-tests option that mimics current default behaviour so that it's not lost. @gelisam: after all those years, are you still up for implementing that? Note that cabal new-configure has since changed semantics, so I don't know if your analysis in #5255 still stands.
@gelisam: after all those years, are you still up for implementing that?
If I remember correctly, I tried to implement it, but I gave up because the cabal codebase was too complex and confusing for me. Let's give it another shot!
Reacted by Mikolaj Konarski, Javier Neira and Andreas Abel
FYI, the difference in cabal v2-configure semantics is that it no longer does a (major) part of what cabal build repeats later on, but it just creates cabal.project.local according to the options given. I don't think cabal test was changed a lot since then, but given that cabal v2-configure is no longer expected before cabal test (nor cabal build), they need to work fine standalone.
Edit: e.g., if you build with cabal build --options-foo you should probably cabal test --options-foo, it's not assumed that you stuck the common options in cabal configure (but you could have in cabal.config.local, manually or via cabal configure).
Why would not we --enable-tests and --enable-benchmarks by default? This would guarantee a stable build plan for cabal build/test/bench and make UI more intuitive. If someone wants to run cabal build and solve only for a library, they can use cabal build --disable-tests.
Reacted by Artem Pelenitsyn, Jan Tojnar and Mikolaj Konarski
Why would not we --enable-tests and --enable-benchmarks by default? This would guarantee a stable build plan for cabal build/test/bench and make UI more intuitive. If someone wants to run cabal build and solve only for a library, they can use cabal build --disable-tests.
This idea is similar to the solution that the discussion in #7883 was converging on. By default, cabal build would solve for tests but not build them, and cabal test would solve for tests and build them.
Activity
hvr commentedon Jan 30, 2018
Iirc this was a deliberate design choice by @dcoutts to avoid invocations of
cabal new-testw/o any flags to suddenly force recomputing a new install-plan (which differs in dependencies), only to have to recompute yet another one when we invokecabal new-buildorcabal new-bench(which btw suffers from the same symptom). The current behaviour causes the install-plans to remain stable when alternating between invocations ofbuild/bench/test.PS: Also, when we run the test-suite or benchmarks, we want to test the same configuration that we're working on w/ new-build; and not some different arbitrary one.
PS2: The discussion @GrayJay linked starting at #3923 (comment) is very relevant
sebright commentedon Jan 31, 2018
This issue looks very similar to #3923 and #4421, except that they apply to new-build when it is given a test suite as an argument.
dmwit commentedon Jan 31, 2018
Given that constraint (which I'm not sure I agree with), I suspect the correct behavior is to default to creating a build plan that includes the tests and benchmarks (even in new-build), then prune those away along with any dependencies that are in the plan exclusively for them if the user hasn't asked for them. And of course one could fall back to the current way of creating an install plan when --disable-tests/--disable-benchmarks is supplied.
A stable build plan is nice. Having a build plan at all in the first place is even nicer.
phadej commentedon Jan 31, 2018
So we'd need three way flag
--disable-tests: no tests--enable-tests: solve for all testsEDIT in this case
new-testwould run what it can solve for.I really want to have an explicit flag for default behavior (i.e. "neither
--disable-testsor--enable-testsis given" isn't good enough)And the same for benchmarks.
hvr commentedon Feb 1, 2018
@phadej you also need to take care of the dimension on how much to build by default. Currently this is conflated:
cabal new-build --enable-testssolves & enables test components, and builds every enabled target component.dmwit commentedon Feb 1, 2018
@phadej Perhaps "local packages" instead of "as much as possible"? Although I still think "all tests" is the right default. It would be just as surprising for
cabal new-test mydependencyto fail andcabal new-test --enable-tests mydependencyto succeed as it is without the explicit testing target.@hvr We already have the target specification language for specifying what to build, right? And, luckily, the new-* promise is "alpha only, for intrepid users, interface may change", etc. so retrospectively inconsistent behavior like having
--enable-testsimply more build targets can be fixed.hvr commentedon Feb 8, 2018
@dmwit I'm not worried much about changing the meaning of what
allmeans, but rather thatwe need to define what
cabal new-build allmeans (which fortunately is not the same ascabal new-build, which rather refers to build the current in-CWDtarget). What components are considered active? Everything that got solved for?In addition to have a way to say "build everything that has been solved for", we also need a way to say "build everything active except benchmarks and tests" or something like that, as tests & benchmarks are most often not what you want built unless you say
cabal new-testorcabal new-bench-- at least I certainly don't want them built everytime I ask "all" to be built (even though I may want to have solved for everything); afaik we have some awkward ways to express that now, but not conveniently.PS: and also note, that tests/benchmarks can be enabled/disabled at package granularity; it's not a project global setting
dmwit commentedon Feb 9, 2018
I see. I suppose the problem is roughly this:
alldidn't mean "all the libraries and executables", since that's the default things to build in that style.alldidn't mean "all the things available to be built".cabal new-build libraries executablesor similar is undesirable.Does that sound right?
If so, what if
allcould be given some:-based specifiers for picking which kind of components to build? Then as a first pass, one could imagine something like:all: something familiar to old-style users, just libraries and executablesall:all: really everythingall:exe,all:lib, generallyall:<component-type>: all the artifacts of the given typeall:exe all:lib all:testorall all:testfor short.hvr commentedon Feb 9, 2018
c.f.
-Wallvs-Weverythingin GHC and Clang ;-)We have this already.... that's what I referred to as awkward/incovenient way; i.e. my most common use-case is to say something like
cabal new-build exes libs flibs(not sure whetherlibsincludes sub-libs). The trouble is that it's annoying to type, for what I consider a common use-case. :-)I also suggest you take a look at the source-code comments in
Distribution.Client.TargetSelectorto get a better feeling for our rather rich (and partly undocumented -- hint, hint) target selector grammar... :-)Just to put it out there, what about emulating GHC/Clang's warnings, and have
cabal new-build all(pragmatic "all")cabal new-build everything(true "all")or alternatively,
cabal new-build all(pragmatic "all")cabal new-build ALL(true "all")sjakobi commentedon Mar 19, 2018
Just to point out the absurdity of the current situation:
cabal-new: Run new-test with --enable-tests
hvr commentedon Mar 20, 2018
@sjakobi what's your mental model there? Are you assuming that the
--enable-testsflag is stateful? In your example you passed-w ghc-7.10.3to bothnew-buildandnew-test(if you didn't,new-testcould easily pick a different GHC version; would that be absurd as well?), and yet you didn't pass--enable-teststo both.Would you be surprised if
failed to find an install-plan because
--enable-testswas left off? Wouldn't it be also absurd, if callingcabal new-build; cabal new-test; cabal new-buildwould cause the last invocation ofnew-buildnot to be idempotent?phadej commentedon Mar 20, 2018
14 remaining items
Fix CI
Fix CI
andreasabel commentedon Nov 19, 2021
I just ran into this problem with haskell-hvr/deepseq-generics#12.
Having
cabal build --enable-testssucceed but a subsequentcabal testfail is very puzzling.I resolved it with the suggested
tests: Truein acabal.project.localfile. (*)However, I was pessimistic that (*) would make a difference and surprised when it did.
How can you
cabal testwhen tests are disabled? Thatcabal testwould not include--enable-tests---that's what you call a paradox.[Judging from the (existence of a) long discussion there seem to be internal reasons of some sort why there is a third truth value between
tests: Falseandtests: True, or is there?]In the case of haskell-hvr/deepseq-generics#12 there is just a single test suite, that apparently builds with
cabal build --enable-tests. So I don't understand whatcabal testis whining about. Haven't run into this problem before.Mikolaj commentedon Nov 19, 2021
cabal test --enable-testsworks fine, right? I'd guess the idea was that options should not be implicit. But this is misleading and boilerplate.andreasabel commentedon Nov 19, 2021
cabal testfails but increasing verbosity does not provide any insights why:cabal test --enable-testssucceeds, yes.Mikolaj commentedon Nov 19, 2021
Yes, I agree the error messages are confusing, too, even though the hint in the last sentence works. I vote for adding the implicit, default
--enable-tests(or something similar) tocabal testand creating--only-buildable-testsoption that mimics current default behaviour so that it's not lost. @gelisam: after all those years, are you still up for implementing that? Note thatcabal new-configurehas since changed semantics, so I don't know if your analysis in #5255 still stands.gelisam commentedon Nov 19, 2021
If I remember correctly, I tried to implement it, but I gave up because the cabal codebase was too complex and confusing for me. Let's give it another shot!
Mikolaj commentedon Nov 19, 2021
FYI, the difference in
cabal v2-configuresemantics is that it no longer does a (major) part of whatcabal buildrepeats later on, but it just createscabal.project.localaccording to the options given. I don't thinkcabal testwas changed a lot since then, but given thatcabal v2-configureis no longer expected beforecabal test(norcabal build), they need to work fine standalone.Edit: e.g., if you build with
cabal build --options-fooyou should probablycabal test --options-foo, it's not assumed that you stuck the common options incabal configure(but you could have incabal.config.local, manually or viacabal configure).Bodigrim commentedon Jun 18, 2022
Why would not we
--enable-testsand--enable-benchmarksby default? This would guarantee a stable build plan forcabal build/test/benchand make UI more intuitive. If someone wants to runcabal buildand solve only for a library, they can usecabal build --disable-tests.fgaz commentedon Jun 18, 2022
It could happen that there are no build plans with tests enabled but there are with tests disabled
sebright commentedon Jun 30, 2022
This idea is similar to the solution that the discussion in #7883 was converging on. By default,
cabal buildwould solve for tests but not build them, andcabal testwould solve for tests and build them.Mikolaj commentedon Jun 30, 2022
Is that a big problem? The user can manually disable tests or benchmarks,
sebright commentedon Feb 23, 2023
#7883 is a duplicate of this issue, but it has newer discussion of a possible solution, so I'm going to close this one.