Skip to content

Commit

Permalink
Cabal: Honour -working-dir flag when running test executables
Browse files Browse the repository at this point in the history
A simple fix to run the test executable in the `-working-dir`.

Fixes haskell#10704
  • Loading branch information
mpickering committed Jan 8, 2025
1 parent 1c7243f commit 15f86f9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Cabal/src/Distribution/Simple/Test/ExeV10.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,16 @@ runTest pkg_descr lbi clbi hpcMarkupInfo flags suite = do
-- drain the output.
evaluate (force logText)

let mbWorkDir = interpretSymbolicPathCWD
<$> flagToMaybe (setupWorkingDir (testCommonFlags flags))

(exit, logText) <- case testWrapper flags of
Flag path ->
rawSystemIOWithEnvAndAction
verbosity
path
(cmd : opts)
Nothing
mbWorkDir
(Just shellEnv')
getLogText
-- these handles are automatically closed
Expand All @@ -143,7 +146,7 @@ runTest pkg_descr lbi clbi hpcMarkupInfo flags suite = do
verbosity
cmd
opts
Nothing
mbWorkDir
(Just shellEnv')
getLogText
-- these handles are automatically closed
Expand Down
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/TestChangeDir/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: regression-simple
5 changes: 5 additions & 0 deletions cabal-testsuite/PackageTests/TestChangeDir/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude

main = cabalTest . recordMode DoNotRecord $ do
-- Building a target that contains whitespace
cabal "test" ["regression-simple"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Revision history for regression-simple

## 0.1.0.0 -- YYYY-mm-dd

* First version. Released on an unsuspecting world.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I exist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cabal-version: 3.14
name: regression-simple
version: 0.1.0.0
license: NONE
author: Matthew Pickering
maintainer: [email protected]
build-type: Simple
extra-doc-files: CHANGELOG.md

common warnings
ghc-options: -Wall

test-suite regression-simple-test
import: warnings
default-language: Haskell2010
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Main.hs
build-depends: base ^>=4.20.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main (main) where

main :: IO ()
main = readFile "do-i-exist.txt" >>= print

0 comments on commit 15f86f9

Please sign in to comment.