I'm following the GettingStarted guide and when I run 'cabal test' and got this message:
Deprecated: "Please use the new testing interface instead!"
What is the new testing interface?
This message is actually from cabal, not darcs, and is referring to the cabal testing interface.
Most Haskell projects include a file Setup.hs or Setup.lhs that cabal runs in order to build the project. Usually it's sufficient to just call the default Distribution.Simple.defaultMain, but UserHooks in the cabal library defines many hooks to extend cabal's default behavior. One of those hooks is runTests, and this used to be the only way to tell Cabal about the package's test suite. However runTests is now deprecated in favor of the test suite section of the cabal package file. darcs's Setup.lhs file overrides the runTests hook, which triggers the deprecation warning.
As a darcs user, you don't need to worry about this message. If you're interested in contributing to the darcs project, fixing this should be relatively straightforward and I'm sure the patches would be gratefully accepted.
Related
Running stack test --coverage generates a nice HTML report showing what lines your test suite covers. How can I achieve the same thing using cabal new-test?
I'm able to pass --enable-coverage to generate a .tix file but I'm not sure what to run on the .tix file to generate the HTML report. I'm pretty sure it involves hpc but I haven't been able to work out the right command.
I have the standard Cabal configuration of my application being a library, with a test-suite for that library.
It appears it's as easy as passing --enable-coverage to cabal new-test. I had previously been running tests with cabal new-run test:test to workaround some limitations of new-test (e.g. lacking streaming and colors), so the fix is to use new-test instead of new-run.
Cabal 3.6 should be able to generate the HPC report. There is one caveat; this error may appear:
Error:
Internal libraries only supported with per-component builds.
Per-component builds were disabled because program coverage is enabled
https://github.com/haskell/cabal/issues/6440
To avoid the error, add to cabal.project:
package *
coverage: True
library-coverage: True
then cabal test (without --enable-coverage). The report should be somewhere in dist-newstyle.
There have been attempt in other package managers to build brigdes to other ecosystems. E.g., there is composer-npm-bridge, which allows to pull packages from node registry into a PHP project. Is it possible to build something like this using cabal? More concretely, how would one go about pulling packages from luarocks into a Haskell project?
It is in principle possible: with build-type: custom, cabal will compile and run your Setup.hs in place of its own build mechanisms, and you can put arbitrary Haskell code in Setup.hs. Alternately, if you can fit your setup process into the usual configure-make-make install dance, then the build-type: configure option may be just the ticket.
See the user's guide for more complete details on these configuration options.
stack new usually creates a default Setup.hs file. I removed it from a project and it still builds alright for any lts resolver down to lts-2. It also passes cabal check at least for cabal version 1.24. (Though not for cabal 1.22.)
Can I conclude from this result that including a default Setup.hs in a project is not trendy anymore and I can drop it? In particular, will many prospective users be diverted from installing the package if it's not passing cabal check for cabal 1.22?
P.S. This question is more specific than the other, similar one in that I want to know, specifically, if the package not passing cabal check for a certain version of cabal due to the absence of an otherwise unnecessary Setup.hs will be counted against that package in some situations, and whether there are any other downsides to not having a Setup.hs in a project, considering the current state of the Haskell ecosystem. Whether a Setup.hs is necessary or useful overall is not a question here.
If you run cabal sdist on a project without a Setup.hs file, cabal creates one for you -- try it!
As such, there's no point to removing the file, because it will just get regenerated when you package for distribution anyway.
I have a stack multi-package project where the "multi-package" is zip-conduit-0.2.2.2 (I needed to tweak some dependency versions to get it to compile with nightly-2015-10-12).
I use zip-conduit in the main package and I also want to in Setup.hs in order to be able to package up zip files.
I have build-type: Custom in my cabal file and stack build attempts to build Setup.hs. The problem is that building Setup.hs cannot find the dependency zip-conduit-0.2.2.2.
Can I use a multi-package dependency in Setup.hs? If so how? and if not, what is my alternative?
Note: I have seen this reference https://github.com/commercialhaskell/stack/pull/899, but I don't understand it.
It looks like you need to set the explicit-setup-deps setting to true for that package. It's unfortunate that Stack can't handle this situation automatically, but without dependency information in .cabal files, there seems to be no alternative.
See the linked issues from the documentation if you're interested in the history here.
I don't think it is possible to declare package dependencies for Setup.hs itself.
Some ideas:
Require that the dependent packages have already been installed.
Have Setup.hs shell out to an external command to perform the zipping, and just require that the external command has to exist.
Make the installer program an additional exe target in the cabal file. Before proceeding with the build of the library, Setup.hs can build the installer program target, then build the library, then use the built installer exe to install the library.
When i google for how to integrate unit tests with cabal files, i either find
http://www.haskell.org/haskellwiki/How_to_write_a_Haskell_program which does not seem to describe the integration of HUnit/QuickCheck with the Cabal file
or i see messages like "wait for Cabal x.y which will support cabal test" but i can not find any documentation for this either
How would you run all unit test using cabal (for example everytime i do a "cabal build") today?
Make sure you have the latest version of Cabal and cabal-install installed.
Have a test-suite section in your .cabal file. See this section of cabal's documentation for an explanation of how to write a test-suite section in your Cabal file and this section for instructions on how to run it.
I've been using the built-in test support for some time and it has saved me from having to maintain fragile Makefiles just for my tests. There are still some rough edges in the command line output of cabal test, but they have been fixed in HEAD so in the next Cabal/cabal-install release everything should be very smooth.