From 8a73f7a2f9898dfe90719b159e2127c1ead4edfe Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Thu, 8 Aug 2024 16:42:02 +0100 Subject: [PATCH] Test --working-dir in the testsuite When testing `./Setup` only, when `withDirectory` is used, instead of changing into that directory when invoking processes, we now use the `--working-dir` flag and keep a fixed CWD. This will therefore passively test that `--working-dir` is working In addition, it makes it possible to test things easily such as `--working-dir` with a relative path as an argument. `cabal-install` will only invoke `--working-dir` with an absolute path and hence is isolated from any double interpretation issues. Testing against these double interpretation issues is very important as it also prevents over-interpretation of relative paths into absolute paths. Passing absolute paths to tools such as hsc2hs can lead to the build directory leaking into an interface file which leads to non-reproducible results. --- .../Includes2/setup-external.cabal.out | 12 +++--- .../Backpack/Includes2/setup-external.out | 12 +++--- .../Includes2/setup-per-component.out | 12 +++--- .../Includes3/setup-external-explicit.out | 4 +- .../Includes3/setup-external-ok.cabal.out | 14 ++++--- .../Backpack/Includes3/setup-external-ok.out | 14 ++++--- .../Backpack/Reexport1/setup.cabal.out | 4 +- .../PackageTests/Backpack/Reexport1/setup.out | 4 +- .../TestNameCollision/setup.cabal.out | 2 +- .../PackageTests/TestNameCollision/setup.out | 2 +- cabal-testsuite/Setup.hs | 10 ++++- cabal-testsuite/src/Test/Cabal/Prelude.hs | 39 ++++++++++++------- 12 files changed, 77 insertions(+), 52 deletions(-) diff --git a/cabal-testsuite/PackageTests/Backpack/Includes2/setup-external.cabal.out b/cabal-testsuite/PackageTests/Backpack/Includes2/setup-external.cabal.out index 0448dac63ff..127f860bd87 100644 --- a/cabal-testsuite/PackageTests/Backpack/Includes2/setup-external.cabal.out +++ b/cabal-testsuite/PackageTests/Backpack/Includes2/setup-external.cabal.out @@ -8,7 +8,7 @@ for mylib-0.1.0.0... Preprocessing library for mylib-0.1.0.0... Running Haddock on library instantiated with Database = for mylib-0.1.0.0... -Documentation created: ../setup-external.cabal.dist/work/mylib/dist/doc/html/mylib +Documentation created: ./mylib/../setup-external.cabal.dist/work/mylib/dist/doc/html/mylib # Setup copy Installing library in # Setup register @@ -22,7 +22,7 @@ Building library for mysql-0.1.0.0... # Setup haddock Preprocessing library for mysql-0.1.0.0... Running Haddock on library for mysql-0.1.0.0... -Documentation created: ../setup-external.cabal.dist/work/mysql/dist/doc/html/mysql +Documentation created: ./mysql/../setup-external.cabal.dist/work/mysql/dist/doc/html/mysql # Setup copy Installing library in # Setup register @@ -35,7 +35,7 @@ Building library for postgresql-0.1.0.0... # Setup haddock Preprocessing library for postgresql-0.1.0.0... Running Haddock on library for postgresql-0.1.0.0... -Documentation created: ../setup-external.cabal.dist/work/postgresql/dist/doc/html/postgresql +Documentation created: ./postgresql/../setup-external.cabal.dist/work/postgresql/dist/doc/html/postgresql # Setup copy Installing library in # Setup register @@ -51,7 +51,7 @@ Preprocessing library for mylib-0.1.0.0... Running Haddock on library instantiated with Database = mysql-0.1.0.0:Database.MySQL for mylib-0.1.0.0... -Documentation created: ../setup-external.cabal.dist/work/mylib/dist/doc/html/mylib +Documentation created: ./mylib/../setup-external.cabal.dist/work/mylib/dist/doc/html/mylib # Setup copy Installing library in # Setup register @@ -69,7 +69,7 @@ Preprocessing library for mylib-0.1.0.0... Running Haddock on library instantiated with Database = postgresql-0.1.0.0:Database.PostgreSQL for mylib-0.1.0.0... -Documentation created: ../setup-external.cabal.dist/work/mylib/dist/doc/html/mylib +Documentation created: ./mylib/../setup-external.cabal.dist/work/mylib/dist/doc/html/mylib # Setup copy Installing library in # Setup register @@ -84,7 +84,7 @@ Building library for src-0.1.0.0... # Setup haddock Preprocessing library for src-0.1.0.0... Running Haddock on library for src-0.1.0.0... -Documentation created: ../setup-external.cabal.dist/work/src/dist/doc/html/src +Documentation created: ./src/../setup-external.cabal.dist/work/src/dist/doc/html/src # Setup copy Installing library in # Setup register diff --git a/cabal-testsuite/PackageTests/Backpack/Includes2/setup-external.out b/cabal-testsuite/PackageTests/Backpack/Includes2/setup-external.out index 19a089db14f..f363c456afd 100644 --- a/cabal-testsuite/PackageTests/Backpack/Includes2/setup-external.out +++ b/cabal-testsuite/PackageTests/Backpack/Includes2/setup-external.out @@ -8,7 +8,7 @@ for mylib-0.1.0.0... Preprocessing library for mylib-0.1.0.0... Running Haddock on library instantiated with Database = for mylib-0.1.0.0... -Documentation created: ../setup-external.dist/work/mylib/dist/doc/html/mylib +Documentation created: ./mylib/../setup-external.dist/work/mylib/dist/doc/html/mylib # Setup copy Installing library in # Setup register @@ -22,7 +22,7 @@ Building library for mysql-0.1.0.0... # Setup haddock Preprocessing library for mysql-0.1.0.0... Running Haddock on library for mysql-0.1.0.0... -Documentation created: ../setup-external.dist/work/mysql/dist/doc/html/mysql +Documentation created: ./mysql/../setup-external.dist/work/mysql/dist/doc/html/mysql # Setup copy Installing library in # Setup register @@ -35,7 +35,7 @@ Building library for postgresql-0.1.0.0... # Setup haddock Preprocessing library for postgresql-0.1.0.0... Running Haddock on library for postgresql-0.1.0.0... -Documentation created: ../setup-external.dist/work/postgresql/dist/doc/html/postgresql +Documentation created: ./postgresql/../setup-external.dist/work/postgresql/dist/doc/html/postgresql # Setup copy Installing library in # Setup register @@ -51,7 +51,7 @@ Preprocessing library for mylib-0.1.0.0... Running Haddock on library instantiated with Database = mysql-0.1.0.0:Database.MySQL for mylib-0.1.0.0... -Documentation created: ../setup-external.dist/work/mylib/dist/doc/html/mylib +Documentation created: ./mylib/../setup-external.dist/work/mylib/dist/doc/html/mylib # Setup copy Installing library in # Setup register @@ -69,7 +69,7 @@ Preprocessing library for mylib-0.1.0.0... Running Haddock on library instantiated with Database = postgresql-0.1.0.0:Database.PostgreSQL for mylib-0.1.0.0... -Documentation created: ../setup-external.dist/work/mylib/dist/doc/html/mylib +Documentation created: ./mylib/../setup-external.dist/work/mylib/dist/doc/html/mylib # Setup copy Installing library in # Setup register @@ -84,7 +84,7 @@ Building library for src-0.1.0.0... # Setup haddock Preprocessing library for src-0.1.0.0... Running Haddock on library for src-0.1.0.0... -Documentation created: ../setup-external.dist/work/src/dist/doc/html/src +Documentation created: ./src/../setup-external.dist/work/src/dist/doc/html/src # Setup copy Installing library in # Setup register diff --git a/cabal-testsuite/PackageTests/Backpack/Includes2/setup-per-component.out b/cabal-testsuite/PackageTests/Backpack/Includes2/setup-per-component.out index 5fff9a72819..3eaa739df55 100644 --- a/cabal-testsuite/PackageTests/Backpack/Includes2/setup-per-component.out +++ b/cabal-testsuite/PackageTests/Backpack/Includes2/setup-per-component.out @@ -8,7 +8,7 @@ for I-0.1.0.0... Preprocessing library 'mylib' for I-0.1.0.0... Running Haddock on library 'mylib' instantiated with Database = for I-0.1.0.0... -Documentation created: ../setup-per-component.dist/work/Includes2/dist/doc/html/I/mylib +Documentation created: ./Includes2/../setup-per-component.dist/work/Includes2/dist/doc/html/I/mylib # Setup copy Installing internal library mylib in # Setup register @@ -22,7 +22,7 @@ Building library 'mysql' for I-0.1.0.0... # Setup haddock Preprocessing library 'mysql' for I-0.1.0.0... Running Haddock on library 'mysql' for I-0.1.0.0... -Documentation created: ../setup-per-component.dist/work/Includes2/dist/doc/html/I/mysql +Documentation created: ./Includes2/../setup-per-component.dist/work/Includes2/dist/doc/html/I/mysql # Setup copy Installing internal library mysql in # Setup register @@ -35,7 +35,7 @@ Building library 'postgresql' for I-0.1.0.0... # Setup haddock Preprocessing library 'postgresql' for I-0.1.0.0... Running Haddock on library 'postgresql' for I-0.1.0.0... -Documentation created: ../setup-per-component.dist/work/Includes2/dist/doc/html/I/postgresql +Documentation created: ./Includes2/../setup-per-component.dist/work/Includes2/dist/doc/html/I/postgresql # Setup copy Installing internal library postgresql in # Setup register @@ -54,7 +54,7 @@ Preprocessing library 'mylib' for I-0.1.0.0... Running Haddock on library 'mylib' instantiated with Database = mysql-0.1.0.0:Database.MySQL for I-0.1.0.0... -Documentation created: ../setup-per-component.dist/work/Includes2/dist/doc/html/I/mylib +Documentation created: ./Includes2/../setup-per-component.dist/work/Includes2/dist/doc/html/I/mylib # Setup copy Installing internal library mylib in # Setup register @@ -75,7 +75,7 @@ Preprocessing library 'mylib' for I-0.1.0.0... Running Haddock on library 'mylib' instantiated with Database = postgresql-0.1.0.0:Database.PostgreSQL for I-0.1.0.0... -Documentation created: ../setup-per-component.dist/work/Includes2/dist/doc/html/I/mylib +Documentation created: ./Includes2/../setup-per-component.dist/work/Includes2/dist/doc/html/I/mylib # Setup copy Installing internal library mylib in # Setup register @@ -90,7 +90,7 @@ Building library for I-0.1.0.0... # Setup haddock Preprocessing library for I-0.1.0.0... Running Haddock on library for I-0.1.0.0... -Documentation created: ../setup-per-component.dist/work/Includes2/dist/doc/html/I +Documentation created: ./Includes2/../setup-per-component.dist/work/Includes2/dist/doc/html/I # Setup copy Installing library in # Setup register diff --git a/cabal-testsuite/PackageTests/Backpack/Includes3/setup-external-explicit.out b/cabal-testsuite/PackageTests/Backpack/Includes3/setup-external-explicit.out index 72bf091632d..3697155460a 100644 --- a/cabal-testsuite/PackageTests/Backpack/Includes3/setup-external-explicit.out +++ b/cabal-testsuite/PackageTests/Backpack/Includes3/setup-external-explicit.out @@ -8,7 +8,7 @@ for sigs-0.1.0.0... Preprocessing library for sigs-0.1.0.0... Running Haddock on library instantiated with Data.Map = for sigs-0.1.0.0... -Documentation created: ../../setup-external-explicit.dist/work/repo/sigs-0.1.0.0/dist/doc/html/sigs +Documentation created: ./repo/sigs-0.1.0.0/../../setup-external-explicit.dist/work/repo/sigs-0.1.0.0/dist/doc/html/sigs # Setup copy Installing library in # Setup register @@ -24,7 +24,7 @@ for indef-0.1.0.0... Preprocessing library for indef-0.1.0.0... Running Haddock on library instantiated with Data.Map = for indef-0.1.0.0... -Documentation created: ../../setup-external-explicit.dist/work/repo/indef-0.1.0.0/dist/doc/html/indef +Documentation created: ./repo/indef-0.1.0.0/../../setup-external-explicit.dist/work/repo/indef-0.1.0.0/dist/doc/html/indef # Setup copy Installing library in # Setup register diff --git a/cabal-testsuite/PackageTests/Backpack/Includes3/setup-external-ok.cabal.out b/cabal-testsuite/PackageTests/Backpack/Includes3/setup-external-ok.cabal.out index 34e7a1204b5..e57a01ca56e 100644 --- a/cabal-testsuite/PackageTests/Backpack/Includes3/setup-external-ok.cabal.out +++ b/cabal-testsuite/PackageTests/Backpack/Includes3/setup-external-ok.cabal.out @@ -8,7 +8,7 @@ for sigs-0.1.0.0... Preprocessing library for sigs-0.1.0.0... Running Haddock on library instantiated with Data.Map = for sigs-0.1.0.0... -Documentation created: ../../setup-external-ok.cabal.dist/work/repo/sigs-0.1.0.0/dist/doc/html/sigs +Documentation created: ./repo/sigs-0.1.0.0/../../setup-external-ok.cabal.dist/work/repo/sigs-0.1.0.0/dist/doc/html/sigs # Setup copy Installing library in # Setup register @@ -24,7 +24,7 @@ for indef-0.1.0.0... Preprocessing library for indef-0.1.0.0... Running Haddock on library instantiated with Data.Map = for indef-0.1.0.0... -Documentation created: ../../setup-external-ok.cabal.dist/work/repo/indef-0.1.0.0/dist/doc/html/indef +Documentation created: ./repo/indef-0.1.0.0/../../setup-external-ok.cabal.dist/work/repo/indef-0.1.0.0/dist/doc/html/indef # Setup copy Installing library in # Setup register @@ -41,11 +41,12 @@ Preprocessing library for sigs-0.1.0.0... Running Haddock on library instantiated with Data.Map = containers-:Data.Map for sigs-0.1.0.0... -Documentation created: ../../setup-external-ok.cabal.dist/work/repo/sigs-0.1.0.0/dist/doc/html/sigs +Documentation created: ./repo/sigs-0.1.0.0/../../setup-external-ok.cabal.dist/work/repo/sigs-0.1.0.0/dist/doc/html/sigs # Setup copy Installing library in # Setup register -Registering library instantiated with Data.Map = containers-:Data.Map +Registering library instantiated with + Data.Map = containers-:Data.Map for sigs-0.1.0.0... # Setup configure Configuring indef-0.1.0.0... @@ -58,11 +59,12 @@ Preprocessing library for indef-0.1.0.0... Running Haddock on library instantiated with Data.Map = containers-:Data.Map for indef-0.1.0.0... -Documentation created: ../../setup-external-ok.cabal.dist/work/repo/indef-0.1.0.0/dist/doc/html/indef +Documentation created: ./repo/indef-0.1.0.0/../../setup-external-ok.cabal.dist/work/repo/indef-0.1.0.0/dist/doc/html/indef # Setup copy Installing library in # Setup register -Registering library instantiated with Data.Map = containers-:Data.Map +Registering library instantiated with + Data.Map = containers-:Data.Map for indef-0.1.0.0... # Setup configure Configuring exe-0.1.0.0... diff --git a/cabal-testsuite/PackageTests/Backpack/Includes3/setup-external-ok.out b/cabal-testsuite/PackageTests/Backpack/Includes3/setup-external-ok.out index 630edbba1a2..2d4e65cb2cd 100644 --- a/cabal-testsuite/PackageTests/Backpack/Includes3/setup-external-ok.out +++ b/cabal-testsuite/PackageTests/Backpack/Includes3/setup-external-ok.out @@ -8,7 +8,7 @@ for sigs-0.1.0.0... Preprocessing library for sigs-0.1.0.0... Running Haddock on library instantiated with Data.Map = for sigs-0.1.0.0... -Documentation created: ../../setup-external-ok.dist/work/repo/sigs-0.1.0.0/dist/doc/html/sigs +Documentation created: ./repo/sigs-0.1.0.0/../../setup-external-ok.dist/work/repo/sigs-0.1.0.0/dist/doc/html/sigs # Setup copy Installing library in # Setup register @@ -24,7 +24,7 @@ for indef-0.1.0.0... Preprocessing library for indef-0.1.0.0... Running Haddock on library instantiated with Data.Map = for indef-0.1.0.0... -Documentation created: ../../setup-external-ok.dist/work/repo/indef-0.1.0.0/dist/doc/html/indef +Documentation created: ./repo/indef-0.1.0.0/../../setup-external-ok.dist/work/repo/indef-0.1.0.0/dist/doc/html/indef # Setup copy Installing library in # Setup register @@ -41,11 +41,12 @@ Preprocessing library for sigs-0.1.0.0... Running Haddock on library instantiated with Data.Map = containers-:Data.Map for sigs-0.1.0.0... -Documentation created: ../../setup-external-ok.dist/work/repo/sigs-0.1.0.0/dist/doc/html/sigs +Documentation created: ./repo/sigs-0.1.0.0/../../setup-external-ok.dist/work/repo/sigs-0.1.0.0/dist/doc/html/sigs # Setup copy Installing library in # Setup register -Registering library instantiated with Data.Map = containers-:Data.Map +Registering library instantiated with + Data.Map = containers-:Data.Map for sigs-0.1.0.0... # Setup configure Configuring indef-0.1.0.0... @@ -58,11 +59,12 @@ Preprocessing library for indef-0.1.0.0... Running Haddock on library instantiated with Data.Map = containers-:Data.Map for indef-0.1.0.0... -Documentation created: ../../setup-external-ok.dist/work/repo/indef-0.1.0.0/dist/doc/html/indef +Documentation created: ./repo/indef-0.1.0.0/../../setup-external-ok.dist/work/repo/indef-0.1.0.0/dist/doc/html/indef # Setup copy Installing library in # Setup register -Registering library instantiated with Data.Map = containers-:Data.Map +Registering library instantiated with + Data.Map = containers-:Data.Map for indef-0.1.0.0... # Setup configure Configuring exe-0.1.0.0... diff --git a/cabal-testsuite/PackageTests/Backpack/Reexport1/setup.cabal.out b/cabal-testsuite/PackageTests/Backpack/Reexport1/setup.cabal.out index 6cdb5760236..d36358ef31e 100644 --- a/cabal-testsuite/PackageTests/Backpack/Reexport1/setup.cabal.out +++ b/cabal-testsuite/PackageTests/Backpack/Reexport1/setup.cabal.out @@ -6,7 +6,7 @@ Building library for p-0.1.0.0... # Setup haddock Preprocessing library for p-0.1.0.0... Running Haddock on library for p-0.1.0.0... -Documentation created: ../setup.cabal.dist/work/p/dist/doc/html/p +Documentation created: ./p/../setup.cabal.dist/work/p/dist/doc/html/p # Setup copy Installing library in # Setup register @@ -19,4 +19,4 @@ Building library for q-0.1.0.0... # Setup haddock Preprocessing library for q-0.1.0.0... Running Haddock on library for q-0.1.0.0... -Documentation created: ../setup.cabal.dist/work/q/dist/doc/html/q +Documentation created: ./q/../setup.cabal.dist/work/q/dist/doc/html/q diff --git a/cabal-testsuite/PackageTests/Backpack/Reexport1/setup.out b/cabal-testsuite/PackageTests/Backpack/Reexport1/setup.out index ba66136d02a..78312c7bcbb 100644 --- a/cabal-testsuite/PackageTests/Backpack/Reexport1/setup.out +++ b/cabal-testsuite/PackageTests/Backpack/Reexport1/setup.out @@ -6,7 +6,7 @@ Building library for p-0.1.0.0... # Setup haddock Preprocessing library for p-0.1.0.0... Running Haddock on library for p-0.1.0.0... -Documentation created: ../setup.dist/work/p/dist/doc/html/p +Documentation created: ./p/../setup.dist/work/p/dist/doc/html/p # Setup copy Installing library in # Setup register @@ -19,4 +19,4 @@ Building library for q-0.1.0.0... # Setup haddock Preprocessing library for q-0.1.0.0... Running Haddock on library for q-0.1.0.0... -Documentation created: ../setup.dist/work/q/dist/doc/html/q +Documentation created: ./q/../setup.dist/work/q/dist/doc/html/q diff --git a/cabal-testsuite/PackageTests/TestNameCollision/setup.cabal.out b/cabal-testsuite/PackageTests/TestNameCollision/setup.cabal.out index a86a3788e72..9e42bccb4fb 100644 --- a/cabal-testsuite/PackageTests/TestNameCollision/setup.cabal.out +++ b/cabal-testsuite/PackageTests/TestNameCollision/setup.cabal.out @@ -18,5 +18,5 @@ Building test suite 'parent' for child-0.1... Running 1 test suites... Test suite parent: RUNNING... Test suite parent: PASS -Test suite logged to: ../setup.cabal.dist/work/child/dist/test/child-0.1-parent.log +Test suite logged to: ./child/../setup.cabal.dist/work/child/dist/test/child-0.1-parent.log 1 of 1 test suites (1 of 1 test cases) passed. diff --git a/cabal-testsuite/PackageTests/TestNameCollision/setup.out b/cabal-testsuite/PackageTests/TestNameCollision/setup.out index c76a83141c1..70dfb63e581 100644 --- a/cabal-testsuite/PackageTests/TestNameCollision/setup.out +++ b/cabal-testsuite/PackageTests/TestNameCollision/setup.out @@ -18,5 +18,5 @@ Building test suite 'parent' for child-0.1... Running 1 test suites... Test suite parent: RUNNING... Test suite parent: PASS -Test suite logged to: ../setup.dist/work/child/dist/test/child-0.1-parent.log +Test suite logged to: ./child/../setup.dist/work/child/dist/test/child-0.1-parent.log 1 of 1 test suites (1 of 1 test cases) passed. diff --git a/cabal-testsuite/Setup.hs b/cabal-testsuite/Setup.hs index b5744198abc..3a4a335b86e 100644 --- a/cabal-testsuite/Setup.hs +++ b/cabal-testsuite/Setup.hs @@ -30,7 +30,10 @@ generateScriptEnvModule lbi verbosity = do createDirectoryIfMissing True moduledir rewriteFileEx verbosity (moduledir "ScriptEnv0.hs") $ unlines - [ "module Test.Cabal.ScriptEnv0 where" + [ "{-# LANGUAGE OverloadedStrings #-}" + , "{-# LANGUAGE FlexibleInstances #-}" + , "{-# OPTIONS_GHC -Wno-orphans #-}" + , "module Test.Cabal.ScriptEnv0 where" , "" , "import Distribution.Simple" , "import Distribution.System (Platform(..), Arch(..), OS(..))" @@ -38,6 +41,8 @@ generateScriptEnvModule lbi verbosity = do , "import Distribution.Simple.Program.Db" , "import Distribution.Backpack (OpenUnitId)" , "import Data.Map (fromList)" + , "import Data.String (IsString(..))" + , "import Distribution.Utils.Path" , "" , "lbiPackageDbStack :: PackageDBStackCWD" , "lbiPackageDbStack = " ++ show lbiPackageDbStack @@ -56,6 +61,9 @@ generateScriptEnvModule lbi verbosity = do , "" , "lbiWithSharedLib :: Bool" , "lbiWithSharedLib = " ++ show (withSharedLib lbi) + , "" + , "instance IsString (SymbolicPath from to) where" + , " fromString = makeSymbolicPath" ] where moduledir = libAutogenDir "Test" "Cabal" diff --git a/cabal-testsuite/src/Test/Cabal/Prelude.hs b/cabal-testsuite/src/Test/Cabal/Prelude.hs index 64c12b0f04d..7fa82cf8143 100644 --- a/cabal-testsuite/src/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/src/Test/Cabal/Prelude.hs @@ -43,7 +43,7 @@ import Distribution.PackageDescription import Test.Utils.TempTestDir (withTestDir) import Distribution.Verbosity (normal) import Distribution.Utils.Path - ( makeSymbolicPath, relativeSymbolicPath ) + ( makeSymbolicPath, relativeSymbolicPath, interpretSymbolicPathCWD ) import Distribution.Compat.Stack @@ -59,8 +59,6 @@ import qualified Crypto.Hash.SHA256 as SHA256 import qualified Data.ByteString.Base16 as Base16 import qualified Data.ByteString.Char8 as C import Data.List (isInfixOf, stripPrefix, isPrefixOf, intercalate) -import Data.List.NonEmpty (NonEmpty (..)) -import qualified Data.List.NonEmpty as NE import Data.Maybe (mapMaybe, fromMaybe) import System.Exit (ExitCode (..)) import System.FilePath @@ -80,11 +78,17 @@ import System.Posix.Resource ------------------------------------------------------------------------ -- * Utilities + runM :: FilePath -> [String] -> Maybe String -> TestM Result runM path args input = do + env <- getTestEnv + runM' (Just $ testCurrentDir env) path args input + +runM' :: Maybe FilePath -> FilePath -> [String] -> Maybe String -> TestM Result +runM' run_dir path args input = do env <- getTestEnv r <- liftIO $ run (testVerbosity env) - (Just $ testCurrentDir env) + run_dir (testEnvironment env) path args @@ -92,12 +96,17 @@ runM path args input = do recordLog r requireSuccess r -runProgramM :: Program -> [String] -> Maybe String -> TestM Result +runProgramM :: Program -> [String] -> Maybe String -> TestM Result runProgramM prog args input = do + env <- getTestEnv + runProgramM' (Just $ testCurrentDir env) prog args input + +runProgramM' :: Maybe FilePath -> Program -> [String] -> Maybe String -> TestM Result +runProgramM' run_dir prog args input = do configured_prog <- requireProgramM prog -- TODO: Consider also using other information from -- ConfiguredProgram, e.g., env and args - runM (programPath configured_prog) args input + runM' run_dir (programPath configured_prog) args input getLocalBuildInfoM :: TestM LocalBuildInfo getLocalBuildInfoM = do @@ -156,6 +165,7 @@ setup'' -> TestM Result setup'' prefix cmd args = do env <- getTestEnv + let work_dir = if testRelativeCurrentDir env == "." then Nothing else Just (testRelativeCurrentDir env) when ((cmd == "register" || cmd == "copy") && not (testHavePackageDb env)) $ error "Cannot register/copy without using 'withPackageDb'" ghc_path <- programPathM ghcProgram @@ -184,7 +194,10 @@ setup'' prefix cmd args = do ++ args _ -> args let rel_dist_dir = definitelyMakeRelative (testCurrentDir env) (testDistDir env) - full_args = cmd :| [marked_verbose, "--distdir", rel_dist_dir] ++ args' + work_dir_arg = case work_dir of + Nothing -> [] + Just wd -> ["--working-dir", wd] + full_args = work_dir_arg ++ (cmd : [marked_verbose, "--distdir", rel_dist_dir] ++ args') defaultRecordMode RecordMarked $ do recordHeader ["Setup", cmd] @@ -192,23 +205,23 @@ setup'' prefix cmd args = do -- -- `cabal` and `Setup.hs` do have different interface. -- - let pkgDir = makeSymbolicPath $ testCurrentDir env prefix + let pkgDir = makeSymbolicPath $ testTmpDir env testRelativeCurrentDir env prefix pdfile <- liftIO $ tryFindPackageDesc (testVerbosity env) (Just pkgDir) pdesc <- liftIO $ readGenericPackageDescription (testVerbosity env) (Just pkgDir) $ relativeSymbolicPath pdfile if testCabalInstallAsSetup env then if buildType (packageDescription pdesc) == Simple - then runProgramM cabalProgram ("act-as-setup" : "--" : NE.toList full_args) Nothing + then runProgramM' (Just (testTmpDir env)) cabalProgram ("act-as-setup" : "--" : full_args) Nothing else fail "Using act-as-setup for not 'build-type: Simple' package" else do if buildType (packageDescription pdesc) == Simple - then runM (testSetupPath env) (NE.toList full_args) Nothing + then runM' (Just $ testTmpDir env) (testSetupPath env) (full_args) Nothing -- Run the Custom script! else do r <- liftIO $ runghc (testScriptEnv env) - (Just $ testCurrentDir env) + (Just $ testTmpDir env) (testEnvironment env) - (testCurrentDir env prefix "Setup.hs") - (NE.toList full_args) + (testRelativeCurrentDir env prefix "Setup.hs") + (full_args) recordLog r requireSuccess r