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 #10704
  • Loading branch information
mpickering committed Jan 8, 2025
1 parent 1c7243f commit 67f5964
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 2 deletions.
8 changes: 6 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,17 @@ 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 +147,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
12 changes: 12 additions & 0 deletions changelog.d/pr-10725
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
synopsis: Honour the `-working-dir` flag when executing testsuite executables.
packages: Cabal
prs: #10725
issues: #10704
significance:

description: {

Honour the `-working-dir` flag when executing testsuite executables. This fixes a
regression in Cabal-3.14.0.0.

}

0 comments on commit 67f5964

Please sign in to comment.