Skip to content

output quality depends on $PWD #517

Description

in multi-package projects, it is common for each package to be placed in a separate sub-directory. the quality of the output depends on whether the tests are run from the root of the project or from the sub-directory of the package which contains the tests:

$ cd ~PROJECT_ROOT
$ cabal run toy-exe
━━━ Toy ━━━
  ✗ prop_failing failed at Main.hs:14:3
    after 1 test.
    shrink path: 1:

    forAll0 =
      0

    forAll1 =
      0

    This failure can be reproduced by running:
    > recheckAt (Seed 1302999818739436304 15345910533038617549) "1:" prop_failing

  ✗ 1 failed.

vs the much better looking:

$ cd $PROJECT_ROOT/my-package
$ cabal run toy-exe
━━━ Toy ━━━
  ✗ prop_failing failed at Main.hs:14:3
    after 1 test.
    shrink path: 1:

       ┏━━ Main.hs ━━━
     8 ┃ prop_failing :: Property
     9 ┃ prop_failing = property $ do
    10 ┃   x <- forAll $ Gen.int (Range.linear 0 10)
       ┃   │ 0
    11 ┃   y <- forAll $ Gen.int (Range.linear 0 10)
       ┃   │ 0
    12 ┃   assert (x == x)
    13 ┃   assert (y == y)
    14 ┃   assert (x < y)
       ┃   ^^^^^^^^^^^^^^
    15 ┃   assert (x <= x)
    16 ┃   assert (y <= y)

    This failure can be reproduced by running:
    > recheckAt (Seed 7577190907837601680 195968907661934709) "1:" prop_failing

  ✗ 1 failed.

For easy reproducibility, here is the file structure I have used to produce the output above. The only thing which matters is that my toy.cabal file is in $PROJECT_ROOT/my-package instead of $PROJECT_ROOT.

$ tree $PROJECT_ROOT
$PROJECT_ROOT
├──
├── my-package
│   ├── Main.hs
│   └── toy.cabal
└── cabal.project

$ cat $PROJECT_ROOT/cabal.project
packages: my-package

$ cat $PROJECT_ROOT/my-package/toy.cabal
cabal-version:      3.0
name:               toy
version:            0.1.0.0
build-type:         Simple

executable toy-exe
    main-is:          Main.hs
    build-depends:    base
                    , hedgehog == 1.4
    hs-source-dirs:   .
    default-language: Haskell2010

$ cat $PROJECT_ROOT/my-package/Main.hs
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Hedgehog
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range

prop_failing :: Property
prop_failing = property $ do
  x <- forAll $ Gen.int (Range.linear 0 10)
  y <- forAll $ Gen.int (Range.linear 0 10)
  assert (x == x)
  assert (y == y)
  assert (x < y)
  assert (x <= x)
  assert (y <= y)

main :: IO Bool
main
  = checkParallel
  $ Group "Toy"
    [ ("prop_failing", prop_failing)
    ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions