From 3bfd51ec1fe99af16d93625c77c663fb6830851d Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Wed, 8 Jan 2025 14:06:57 +0000 Subject: [PATCH] Cabal: Honour -working-dir flag when running test executables A simple fix to run the test executable in the `-working-dir`. Fixes #10704 --- Cabal/src/Distribution/Simple/Test/ExeV10.hs | 8 ++++-- .../PackageTests/TestChangeDir/cabal.project | 3 +++ .../PackageTests/TestChangeDir/cabal.test.hs | 6 +++++ .../regression-simple/CHANGELOG.md | 5 ++++ .../regression-simple/bench/Main.hs | 4 +++ .../regression-simple/do-i-exist.txt | 1 + .../regression-simple/regression-simple.cabal | 27 +++++++++++++++++++ .../regression-simple/test/Main.hs | 4 +++ changelog.d/pr-10725 | 12 +++++++++ 9 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 cabal-testsuite/PackageTests/TestChangeDir/cabal.project create mode 100644 cabal-testsuite/PackageTests/TestChangeDir/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/TestChangeDir/regression-simple/CHANGELOG.md create mode 100644 cabal-testsuite/PackageTests/TestChangeDir/regression-simple/bench/Main.hs create mode 100644 cabal-testsuite/PackageTests/TestChangeDir/regression-simple/do-i-exist.txt create mode 100644 cabal-testsuite/PackageTests/TestChangeDir/regression-simple/regression-simple.cabal create mode 100644 cabal-testsuite/PackageTests/TestChangeDir/regression-simple/test/Main.hs create mode 100644 changelog.d/pr-10725 diff --git a/Cabal/src/Distribution/Simple/Test/ExeV10.hs b/Cabal/src/Distribution/Simple/Test/ExeV10.hs index a90ce833703..8e20efffe51 100644 --- a/Cabal/src/Distribution/Simple/Test/ExeV10.hs +++ b/Cabal/src/Distribution/Simple/Test/ExeV10.hs @@ -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 @@ -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 diff --git a/cabal-testsuite/PackageTests/TestChangeDir/cabal.project b/cabal-testsuite/PackageTests/TestChangeDir/cabal.project new file mode 100644 index 00000000000..410dbc32d08 --- /dev/null +++ b/cabal-testsuite/PackageTests/TestChangeDir/cabal.project @@ -0,0 +1,3 @@ +packages: regression-simple + +tests: True diff --git a/cabal-testsuite/PackageTests/TestChangeDir/cabal.test.hs b/cabal-testsuite/PackageTests/TestChangeDir/cabal.test.hs new file mode 100644 index 00000000000..2aaf2ac3933 --- /dev/null +++ b/cabal-testsuite/PackageTests/TestChangeDir/cabal.test.hs @@ -0,0 +1,6 @@ +import Test.Cabal.Prelude + +main = cabalTest . recordMode DoNotRecord $ do + -- Building a target that contains whitespace + cabal "test" ["regression-simple"] + cabal "bench" ["regression-simple"] diff --git a/cabal-testsuite/PackageTests/TestChangeDir/regression-simple/CHANGELOG.md b/cabal-testsuite/PackageTests/TestChangeDir/regression-simple/CHANGELOG.md new file mode 100644 index 00000000000..728a34daa36 --- /dev/null +++ b/cabal-testsuite/PackageTests/TestChangeDir/regression-simple/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for regression-simple + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/cabal-testsuite/PackageTests/TestChangeDir/regression-simple/bench/Main.hs b/cabal-testsuite/PackageTests/TestChangeDir/regression-simple/bench/Main.hs new file mode 100644 index 00000000000..d4be9546a21 --- /dev/null +++ b/cabal-testsuite/PackageTests/TestChangeDir/regression-simple/bench/Main.hs @@ -0,0 +1,4 @@ +module Main (main) where + +main :: IO () +main = readFile "do-i-exist.txt" >>= print diff --git a/cabal-testsuite/PackageTests/TestChangeDir/regression-simple/do-i-exist.txt b/cabal-testsuite/PackageTests/TestChangeDir/regression-simple/do-i-exist.txt new file mode 100644 index 00000000000..044c92dc6a5 --- /dev/null +++ b/cabal-testsuite/PackageTests/TestChangeDir/regression-simple/do-i-exist.txt @@ -0,0 +1 @@ +I exist diff --git a/cabal-testsuite/PackageTests/TestChangeDir/regression-simple/regression-simple.cabal b/cabal-testsuite/PackageTests/TestChangeDir/regression-simple/regression-simple.cabal new file mode 100644 index 00000000000..8a795b6677d --- /dev/null +++ b/cabal-testsuite/PackageTests/TestChangeDir/regression-simple/regression-simple.cabal @@ -0,0 +1,27 @@ +cabal-version: 3.14 +name: regression-simple +version: 0.1.0.0 +license: NONE +author: Matthew Pickering +maintainer: matthewtpickering@gmail.com +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 + +benchmark regression-simple-bench + import: warnings + default-language: Haskell2010 + type: exitcode-stdio-1.0 + hs-source-dirs: bench + main-is: Main.hs + build-depends: base ^>=4.20.0.0 diff --git a/cabal-testsuite/PackageTests/TestChangeDir/regression-simple/test/Main.hs b/cabal-testsuite/PackageTests/TestChangeDir/regression-simple/test/Main.hs new file mode 100644 index 00000000000..d4be9546a21 --- /dev/null +++ b/cabal-testsuite/PackageTests/TestChangeDir/regression-simple/test/Main.hs @@ -0,0 +1,4 @@ +module Main (main) where + +main :: IO () +main = readFile "do-i-exist.txt" >>= print diff --git a/changelog.d/pr-10725 b/changelog.d/pr-10725 new file mode 100644 index 00000000000..07ebe4e263f --- /dev/null +++ b/changelog.d/pr-10725 @@ -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. + +}