Re: patch: --enable-tests and --only-dependencies

On Fri, Feb 3, 2012 at 4:40 AM, Andres Löh
The way to handle tests for named packages would be to add a PackageConstraint for tests the way is already done for flags, but this is a lot more work because it would require getting deep into the dependency solver. However, it would make it easy to set the config flags during build for explicit targets so we could implement a test auto-run feature.
When I rewrote the solver, I was actually surprised that test flags are sort of bypassing the solver. I don't think it would be all that difficult to build it into the new solver properly, *if* I'd know what properly means. So if you can specify a reasonable behaviour you'd expect from the solver, I can try to implement it.
I looked at the top-down solver again to see if we could enable/disable tests and benchmarks through a constraint (the way flag assignments are done). To my surprise, it's not nearly as confusing as I thought it was the last time I looked at it (two years ago (!) during GSoC when I wrote that awful solver-bypassing test code). The attached patches do what I think we want. Test dependencies for targetted packages (named and source alike) are detected and installed, but '--enable-tests' is not propagated to dependencies. I only checked the top-down solver because I'm still not familiar with the modular solver. I also included a patch to automatically run the test suites when 'cabal install --enable-tests' is invoked and abort installation if the tests fail. I think this is a sensible default; if a user is going to ignore the results of the test suites, they probably don't want '--enable-tests'. Johan and Antoine: I tested my patch with some source packages I have around and the packages I could find on Hackage that have test suites, but that only assures me that '--enable-tests' does what _I_ think it should do. It sounds to me like you use this feature on a daily basis: could you try out this set of patches and let me know if this behavior meets your needs? Andres: I had to make a few changes to the modular solver to get cabal-install to compile with the new constraints, but I didn't go far enough to actually have the solver pull in the dependencies. I recorded these changes as a separate patch to make the changes more obvious. You understand the solvers better than I do; if I'm taking the wrong approach, please let me know. Otherwise, this is what I did outside the solvers, if you want to implement test and benchmark dependencies for the modular solver: 1. There is a new type, 'OptionalStanza', with two constructors indicating respectively that '--enable-tests' or '--enable-benchmarks' was specified. 2. Constraints are passed to the solver in the same way as flag assignments. The names of the target packages are determined, and a list [OptionalStanza] is associated with each. If a constructor is present in the list, that type of stanza is enabled. If the list is empty, neither tests nor benchmarks are enabled. When a solver is building an InstallPlan, it just needs to configure each package respecting the constraints to get the correct list of dependencies. Packages that aren't specified as targets will have no constraints, so they should be built without '--enable-tests' and '--enable-benchmarks'. Hopefully we can put this long-standing bug to rest! Thanks! -- Thomas Tuegel

Hi Thomas.
Andres: I had to make a few changes to the modular solver to get cabal-install to compile with the new constraints, but I didn't go far enough to actually have the solver pull in the dependencies. I recorded these changes as a separate patch to make the changes more obvious. You understand the solvers better than I do; if I'm taking the wrong approach, please let me know. Otherwise, this is what I did outside the solvers, if you want to implement test and benchmark dependencies for the modular solver:
Thanks for the patches. I'll take a closer look. One minor issue that's rather unfortunate is that you need a (minor) change to Cabal, not only cabal-install. For practical purposes, we're going to aim for a cabal-install release in the not too distant future, but IMHO it should work with the Cabal version that's shipped with ghc-7.4.1 and not require another upgrade there. Anyway, I'll see what I can do in order to adapt the modular solver.
When a solver is building an InstallPlan, it just needs to configure each package respecting the constraints to get the correct list of dependencies. Packages that aren't specified as targets will have no constraints, so they should be built without '--enable-tests' and '--enable-benchmarks'.
Did you have to adapt the install-plan checker in any way? Cheers, Andres -- Andres Löh, Haskell Consultant Well-Typed LLP, http://www.well-typed.com

On Tue, Feb 7, 2012 at 3:32 PM, Andres Löh
Thanks for the patches. I'll take a closer look. One minor issue that's rather unfortunate is that you need a (minor) change to Cabal, not only cabal-install. For practical purposes, we're going to aim for a cabal-install release in the not too distant future, but IMHO it should work with the Cabal version that's shipped with ghc-7.4.1 and not require another upgrade there.
I modified Cabal to avoid code duplication. I didn't know about the upcoming cabal-install release. I'm attaching a new patch bundle that doesn't modify Cabal. (These supersede the last set of patches I sent.) The only difference is a small change in Distribution.Client.Types.
Did you have to adapt the install-plan checker in any way?
Yes. It also needs to respect the constraints, i.e., configure packages with '--enable-tests' as appropriate, or it will complain that the install plan pulls in extra dependencies. -- Thomas Tuegel

On Thu, Feb 9, 2012 at 11:47 AM, Thomas Tuegel
On Tue, Feb 7, 2012 at 3:32 PM, Andres Löh
wrote: Thanks for the patches. I'll take a closer look. One minor issue that's rather unfortunate is that you need a (minor) change to Cabal, not only cabal-install. For practical purposes, we're going to aim for a cabal-install release in the not too distant future, but IMHO it should work with the Cabal version that's shipped with ghc-7.4.1 and not require another upgrade there.
I modified Cabal to avoid code duplication. I didn't know about the upcoming cabal-install release. I'm attaching a new patch bundle that doesn't modify Cabal. (These supersede the last set of patches I sent.) The only difference is a small change in Distribution.Client.Types.
I just realized that there's a glaring problem with automatically running tests: if you call '--enable-tests' on a package that doesn't have tests, this gets interpreted as an error. It's an easy fix, but it will _require_ modifying Cabal. So, we probably want to pass on the 'automatically run tests' patch in the next version of cabal-install. I think this is probably OK. The other patches (which are really a bug fix) can still go in. Running tests automatically is an added feature, so I don't think it will bug people too much if it's delayed until the next release of Cabal. -- Thomas Tuegel

On 9 February 2012 18:40, Thomas Tuegel
I just realized that there's a glaring problem with automatically running tests: if you call '--enable-tests' on a package that doesn't have tests, this gets interpreted as an error. It's an easy fix, but it will _require_ modifying Cabal. So, we probably want to pass on the 'automatically run tests' patch in the next version of cabal-install.
I think this is probably OK. The other patches (which are really a bug fix) can still go in. Running tests automatically is an added feature, so I don't think it will bug people too much if it's delayed until the next release of Cabal.
Sounds reasonable. Lets push the Cabal lib changes into cabal head, but make sure that the cabal-install release branch does not require that fix. Duncan

Duncan, Thomas.
I think this is probably OK. The other patches (which are really a bug fix) can still go in. Running tests automatically is an added feature, so I don't think it will bug people too much if it's delayed until the next release of Cabal.
Sounds reasonable. Lets push the Cabal lib changes into cabal head, but make sure that the cabal-install release branch does not require that fix.
I agree. I will do the pushing this weekend (if you haven't already done so). I'll try to make the necessary fixes to the modular solver so that both are in sync again. Cheers, Andres -- Andres Löh, Haskell Consultant Well-Typed LLP, http://www.well-typed.com
participants (3)
-
Andres Löh
-
Duncan Coutts
-
Thomas Tuegel