commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
3.95k stars 842 forks source link

Test with coverage fails with long package name #6574

Closed brandonchinn178 closed 1 month ago

brandonchinn178 commented 1 month ago

General summary/comments (optional)

When running stack test --coverage with a long package name, Stack shows an error:

my-really-long-package-name-that-breaks-coverage> Test suite tests passed
Failed to find package key for my-really-long-package-name-that-breaks-coverage-0.1.0.0
Generating unified report.

This happens because when package names are really long, Cabal puts the id field on the next line:

id:
    my-really-long-package-name-that-breaks-coverage-0.1.0.0-DwR1MhUSIPXG07g7vE5zAV

This fails when Stack parses this file line-by-line: https://github.com/commercialhaskell/stack/blob/1dcce74ee5e9f78c5e4442d1e01afbe3768a1768/src/Stack/Coverage.hs#L619

Steps to reproduce

  1. stack new my-really-long-package-name-that-breaks-coverage
  2. cd my-really-long-package-name-that-breaks-coverage
  3. stack test --coverage

Expected

Should work

Actual

Failed

Stack version

stack --version
Version 2.15.5, Git revision 92439b8a94e82e9128a5bc5cd0b21b43e99ffc85 x86_64 hpack-0.36.0

Method of installation

Platform

Your platform (machine architecture and operating system)

mpilgrem commented 1 month ago

@brandonchinn178, many thanks for the report and the diagnosis. EDIT: It seems to me that the code should be using ghc-pkg field {pkg} {field} if it wants to get a specific field for a package in a package database.

mpilgrem commented 1 month ago

@brandonchinn178, I think #6579 will fix this (on Unix-like operating systems; Windows has unrelated problems with long file paths). I also reason that it should not introduce any significant hit to performance (despite making use of ghc-pkg field). However, if there is anything you could do to test it 'in the field', that would be appreciated.

mpilgrem commented 1 month ago

@brandonchinn178, my post above was premature - I need to work out why the CI is failing.

mpilgrem commented 1 month ago

@brandonchinn178, after that false start, the CI on #6579 is now green (and, if not using GHCup to maange Stack, available via stack upgrade --source-only --git-branch re6574).

brandonchinn178 commented 1 month ago

hm I'm running into an unrelated issue: how do I run just one specific test suite with coverage? I'm doing stack test package-foo --coverage, but its building all the binaries and other test suites with -hpc as well. This is an issue because we build a binary that we use as a preprocessor for other test suites, and running the preprocessor fails:

Hpc failure: module mismatch with .tix/.mix file hash number
(perhaps remove my-preprocessor.tix file?)

But after commenting out the problematic test suite, I was able to repro the failure with my normal stack, and verified the bug is fixed running the same command with stack built from this branch!

mpilgrem commented 1 month ago

@brandonchinn178, many thanks. I've merged that into the master branch.