kkardzis / curlhs

Haskell bindings to curl library (libcurl)
https://hackage.haskell.org/package/curlhs
ISC License
4 stars 3 forks source link

curlhs-0.1.6 test suite failure #6

Closed peti closed 9 years ago

peti commented 9 years ago

Citing from http://hydra.cryp.to/build/875475/nixlog/3/raw:

running tests
Running 1 test suites...
Test suite hspec: RUNNING...

Network.CURL720
  curl_version
    returns libcurl version string: "libcurl/7.x.x ..." FAILED [1]
Network.CURL730
  curl_version
    returns libcurl version string: "libcurl/7.x.x ..." FAILED [2]

Failures:

  test/Network/CURL720Spec.hs:14: (best-effort)
  1) Network.CURL720.curl_version returns libcurl version string: "libcurl/7.x.x ..."
       uncaught exception: ErrorCall (<curlhs> failed to call 'curl_version' (NULL))

  test/Network/CURL730Spec.hs:14: (best-effort)
  2) Network.CURL730.curl_version returns libcurl version string: "libcurl/7.x.x ..."
       uncaught exception: ErrorCall (<curlhs> failed to call 'curl_version' (NULL))

Source locations marked with "best-effort" are calculated heuristically and may be incorrect.

Randomized with seed 1366918666

Finished in 0.0005 seconds
2 examples, 2 failures
Test suite hspec: FAIL
kkardzis commented 9 years ago

curlhs requires libcurl at runtime (version 7.20 or above). It compiles without libcurl, but at runtime dlopen is used to load libcurl.so.4 (or libcurl.so), and if that fails, curlhs throws an exception (like in the tests above).

Is libcurl installed during tests?

peti commented 9 years ago

We install whatever the cabal file lists as dependencies.

kkardzis commented 9 years ago

Is it possible to specify additional dependencies? Besides what's in cabal?

I see 'curl-7.42.1' package on the 'Build dependencies' list, but only as indirect dependency. I think it should be there directly below 'curlhs' and on the 'Runtime dependencies' list too (but I don't know much about nixos packaging, sorry).

peti commented 9 years ago

Your Cabal file should specify an attribute extra-libraries: curl in the test suite stanza. If you do that, NixOS will automatically include the curl library in the environment. Similarly, cabal-install will check whether curl is available when people configure the build with --enable-tests.

kkardzis commented 9 years ago

extra-libraries: curl may work for nix, but I cannot accept this in general. This solution puts a hard requirement on libcurl (only for tests but still) and this is just not right. libcurl is optional.

curlhs compiles and runs without libcurl in scope (it is useless then, but it works). Users may catch exceptions and decide what to do when there is no libcurl (or wrong version). Maybe I should do the same in curlhs tests. Actually it was so already before (ee4c4867bbee59de5b53186264a88cd376bdbb42). I can bring it back, but this only hides the problem, I think.

One example (that I know of) which uses the similar technique (dlopen() optional dependencies) is the SDL2_image library (C library, not Haskell). Support for png, jpeg etc. is optional and depends on the availability of the suitable library. In the SDL2_image's default.nix file there is a line:

 buildInputs = [SDL2 libpng libjpeg libtiff libungif libXpm zlib];

Is something similar possible to do for Haskell packages? As I see, Haskell nix files are auto-generated from cabal files, but maybe there is some way to specify additional info on the nix level?

peti commented 9 years ago

Put the extra-libraries attribute into the test suite stanza.

kkardzis commented 9 years ago

Sorry, but this doesn't convince me. There must be another way.

peti commented 9 years ago

I don't understand your concerns. People who configure --enable-tests have a dependency on curl. People who don't want to run the test suite, don't have a dependency on curl. Where is the problem?

kkardzis commented 9 years ago

I don't want extra-libraries in curlhs.cabal because it is not really necessary to build te test suite and it is problematic on non-unix systems (yes, Windows and its problems with foreign libraries).

On the other side even people that don't run tests will want libcurl in the environment. The libraries are independent, but it doesn't make sense to use curlhs without libcurl.

What about mikmod package? There is no extra-libraries field in mikmod.cabal, however it depends on libmikmod package (it's listed here). I've found something like this in configuration-common.nix:

  # https://github.com/evanrinehart/mikmod/issues/1
  mikmod = addExtraLibrary super.mikmod pkgs.libmikmod;
peti commented 9 years ago

curl is necessary to run the test suite because without it the test suite will fail! What's the point of building a test suite that cannot be run? Or rather, that's going to report a test suite failure when you try to run it? That's even worse than not being able to run it in the first place.

The manual override for miknod is necessary only because our auto-generator isn't smart enough yet to deduce that a dependency on the miknod.h header implies a dependency on the miknod library. Once cabal2nix knows that these two things are connected, the override can be (and will be) removed.

kkardzis commented 9 years ago

Maybe auto-generator will never be smart enough to cover all use cases. I'm going different path than others. It may be wrong. But who knows.

peti commented 9 years ago

Well, it's free software and you can write and/or publish it any way you please.