Skip to content

cabal new-test doesn't work with library-coverage for components with other-modules #5213

Closed

Description

@RyanGlScott
$ cabal --version
cabal-install version 2.0.0.0
compiled using version 2.0.1.0 of the Cabal library

I'll work on preparing a minimal example in a bit. In the meantime, you can trigger this issue with scotty-0.11.0:

$ cabal get scotty-0.11.0
Unpacking to scotty-0.11.0/
$ cd scotty-0.11.0/
$ cat > cabal.project << EOF
> packages: .
> package scotty
>   library-coverage: true
> EOF
$ cabal new-test
Resolving dependencies...
In order, the following will be built (use -v for more details):
 - scotty-0.11.0 (lib) (first run)
 - scotty-0.11.0 (test:spec) (first run)
Configuring library for scotty-0.11.0..
Preprocessing library for scotty-0.11.0..
Building library for scotty-0.11.0..
<build output elided>
Configuring test suite 'spec' for scotty-0.11.0..
Preprocessing test suite 'spec' for scotty-0.11.0..
Building test suite 'spec' for scotty-0.11.0..
<build output elided>
Running 1 test suites...
Test suite spec: RUNNING...
<test output elided>
Test suite spec: PASS
Test suite logged to:
/home/ryanglscott/Documents/Hacking/Haskell/scotty-0.11.0/dist-newstyle/build/x86_64-linux/ghc-8.2.2/scotty-0.11.0/c/spec/test/scotty-0.11.0-spec.log
hpc: can not find scotty-0.11.0-inplace/Web.Scotty.Util in ./.hpc, /home/ryanglscott/Documents/Hacking/Haskell/scotty-0.11.0/dist-newstyle/build/x86_64-linux/ghc-8.2.2/scotty-0.11.0/c/spec/hpc/vanilla/mix/scotty-0.11.0, /home/ryanglscott/Documents/Hacking/Haskell/scotty-0.11.0/dist-newstyle/build/x86_64-linux/ghc-8.2.2/scotty-0.11.0/c/spec/hpc/vanilla/mix/spec
CallStack (from HasCallStack):
  error, called at libraries/hpc/Trace/Hpc/Mix.hs:122:15 in hpc-0.6.0.3:Trace.Hpc.Mix
cabal: Tests failed for test:spec from scotty-0.11.0.

This error doesn't happen for another project, wai-middleware-static-0.8.1. Unlike scotty, wai-middleware-static has no other-modules, so I suspect that is the culprit here.

Activity

  1. RyanGlScott commented on Mar 14, 2018

    @RyanGlScott
    MemberAuthor

    A minimal reproducer can be found at https://github.com/RyanGlScott/cabal-gh5213:

    $ git clone https://github.com/RyanGlScott/cabal-gh5213
    Cloning into 'cabal-gh5213'...
    remote: Counting objects: 16, done.
    remote: Compressing objects: 100% (14/14), done.
    remote: Total 16 (delta 1), reused 12 (delta 0), pack-reused 0
    Unpacking objects: 100% (16/16), done.
    $ cd cabal-gh5213/
    $ cabal new-test
    Resolving dependencies...
    In order, the following will be built (use -v for more details):
     - cabal-gh5213-0.1 (lib) (first run)
     - cabal-gh5213-0.1 (test:tests) (first run)
    Configuring library for cabal-gh5213-0.1..
    Preprocessing library for cabal-gh5213-0.1..
    Building library for cabal-gh5213-0.1..
    [1 of 2] Compiling CabalGH5213Other ( src/CabalGH5213Other.hs, /home/ryanglscott/Documents/Hacking/Haskell/cabal-gh5213/dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/build/CabalGH5213Other.o )
    [2 of 2] Compiling CabalGH5213Exposed ( src/CabalGH5213Exposed.hs, /home/ryanglscott/Documents/Hacking/Haskell/cabal-gh5213/dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/build/CabalGH5213Exposed.o )
    Configuring test suite 'tests' for cabal-gh5213-0.1..
    Preprocessing test suite 'tests' for cabal-gh5213-0.1..
    Building test suite 'tests' for cabal-gh5213-0.1..
    [1 of 1] Compiling Main             ( tests/Main.hs, /home/ryanglscott/Documents/Hacking/Haskell/cabal-gh5213/dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/c/tests/build/tests/tests-tmp/Main.o )
    Linking /home/ryanglscott/Documents/Hacking/Haskell/cabal-gh5213/dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/c/tests/build/tests/tests ...
    Running 1 test suites...
    Test suite tests: RUNNING...
    42
    Test suite tests: PASS
    Test suite logged to:
    /home/ryanglscott/Documents/Hacking/Haskell/cabal-gh5213/dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/c/tests/test/cabal-gh5213-0.1-tests.log
    hpc: can not find cabal-gh5213-0.1-inplace/CabalGH5213Other in ./.hpc, /home/ryanglscott/Documents/Hacking/Haskell/cabal-gh5213/dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/c/tests/hpc/vanilla/mix/cabal-gh5213-0.1, /home/ryanglscott/Documents/Hacking/Haskell/cabal-gh5213/dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/c/tests/hpc/vanilla/mix/tests
    CallStack (from HasCallStack):
      error, called at libraries/hpc/Trace/Hpc/Mix.hs:122:15 in hpc-0.6.0.3:Trace.Hpc.Mix
    cabal: Tests failed for test:tests from cabal-gh5213-0.1.
    
  2. RyanGlScott commented on Mar 14, 2018

    @RyanGlScott
    MemberAuthor

    -v3 revealed that this is how hpc is being invoked:

    /opt/ghc/8.2.2/bin/hpc markup /home/ryanglscott/Documents/Hacking/Haskell/cabal-gh5213/dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/c/tests/hpc/vanilla/tix/tests/tests.tix '--destdir=/home/ryanglscott/Documents/Hacking/Haskell/cabal-gh5213/dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/c/tests/hpc/vanilla/html/tests' '--hpcdir=/home/ryanglscott/Documents/Hacking/Haskell/cabal-gh5213/dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/c/tests/hpc/vanilla/mix/tests' '--hpcdir=/home/ryanglscott/Documents/Hacking/Haskell/cabal-gh5213/dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/c/tests/hpc/vanilla/mix/cabal-gh5213-0.1' '--exclude=Main'
    

    It's worth noting that CabalGH5213Other.mix is being created:

    $ find dist-newstyle/ -wholename "*cabal-gh5213-0.1-inplace/CabalGH5213Other*"
    dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/hpc/dyn/mix/cabal-gh5213-0.1/cabal-gh5213-0.1-inplace/CabalGH5213Other.mix
    dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/hpc/vanilla/mix/cabal-gh5213-0.1/cabal-gh5213-0.1-inplace/CabalGH5213Other.mix
    

    I'm not sure why hpc can't find it, though, especially since it's passed '--hpcdir=/home/ryanglscott/Documents/Hacking/Haskell/cabal-gh5213/dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/c/tests/hpc/vanilla/mix/cabal-gh5213-0.1'.

  3. added
    cabal-install: v2-build system
    on Mar 14, 2018
  4. hvr commented on Mar 14, 2018

    @hvr
    Member

    I quick strace reveals, that hpc is looking at e.g.

    open("./.hpc/cabal-gh5213-0.1-inplace/CabalGH5213Other.mix", O_RDONLY|O_NOCTTY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
    open("./dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/t/tests/hpc/vanilla/mix/cabal-gh5213-0.1/cabal-gh5213-0.1-inplace/CabalGH5213Other.mix", O_RDONLY|O_NOCTTY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
    open("./dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/t/tests/hpc/vanilla/mix/tests/cabal-gh5213-0.1-inplace/CabalGH5213Other.mix", O_RDONLY|O_NOCTTY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
    

    whereas it should have been looking at

    ./dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/hpc/vanilla/mix/cabal-gh5213-0.1/cabal-gh5213-0.1-inplace/CabalGH5213Other.mix
    

    for reference, the flags in my case were:

    '--destdir=/tmp/cabal-gh5213/dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/t/tests/hpc/vanilla/html/tests'
    
    '--hpcdir=dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/t/tests/hpc/vanilla/mix/tests'
    
    '--hpcdir=dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/t/tests/hpc/vanilla/mix/cabal-gh5213-0.1'
    

    So it appears that cabal is not passing the right --hpcdir to hpc...

    ...or rather, that the .mix file isn't created in the right folder; the folder passed as --hpcdir is the proper one.

    We're indeed missing the --hpcdir pointing to the library component's .mix files!

    In other words, the

    --hpcdir=dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/t/tests/hpc/vanilla/mix/cabal-gh5213-0.1
    

    erroneously pointing into the test-components build-dir, should instead have been

    --hpcdir=dist-newstyle/build/x86_64-linux/ghc-8.2.2/cabal-gh5213-0.1/hpc/vanilla/mix/cabal-gh5213-0.1
    

    pointing to the library component's build-dir.

    The more I investigate, the more issues/tech-debt I notice... :-/

  5. self-assigned this
    on Mar 14, 2018
  6. hvr commented on Sep 5, 2018

    @hvr
    Member

    I forgot to tackle this in time for 2.4, but I'll try to get to this within the next 1-2 weeks; but it's probably not going to be ready in time for the cabal-install 2.4.0.0 rls; more like 2.4.1.0

  7. vu3rdd commented on Sep 5, 2018

    @vu3rdd

    Thanks @hvr.

  8. erikd commented on Feb 5, 2019

    @erikd
    Member

    Just hit this myself with cabal 2.4.1.0. Is that expected?

  9. 23Skidoo commented on Feb 5, 2019

    @23Skidoo
    Member

    "Expected" in the sense that it's a known issue, yes.

  10. cartazio commented on May 3, 2019

    @cartazio
    Contributor

    #4798 is related right?

  11. cartazio commented on May 4, 2019

    @cartazio
    Contributor

    a related problem folks with fancy code setups hit is when they try to do coverage and have local/not hackage deps, and naively cabal tries do enable coverage on the local package. the work around for now is to set --disable-coverage for that local dep in the cabal.project file. But i think thats an issue that might be related. but probably merits its own ticket

  12. cartazio commented on Feb 14, 2020

    @cartazio
    Contributor

    quoting @davean

    5:53 PM <davean> ocharles: you can specificly disable coverage on the other parts of the project and it will work
    5:54 PM <davean> package reflex-time
    5:54 PM <davean>   coverage: False
    5:54 PM <davean>   library-coverage: False
    5:54 PM <davean> as an example
    5:55 PM <davean> It should, of course, work to have coverage for all of them
    5:55 PM <davean> it just doesn't
    

    a near term improvment would be ANY sort of warning saying "this is a known issue, heres what you need to do "

  13. 65 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

cabal-install: v2-build systempriority: high 🔥type: bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions