Skip to content

Commit

Permalink
Test --working-dir in the testsuite
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mpickering committed Aug 21, 2024
1 parent a9c4cd0 commit 34a3994
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <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 <PATH>
# Setup register
Expand All @@ -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 <PATH>
# Setup register
Expand All @@ -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 <PATH>
# Setup register
Expand All @@ -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 <PATH>
# Setup register
Expand All @@ -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 <PATH>
# Setup register
Expand All @@ -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 <PATH>
# Setup register
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <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 <PATH>
# Setup register
Expand All @@ -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 <PATH>
# Setup register
Expand All @@ -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 <PATH>
# Setup register
Expand All @@ -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 <PATH>
# Setup register
Expand All @@ -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 <PATH>
# Setup register
Expand All @@ -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 <PATH>
# Setup register
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <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 <PATH>
# Setup register
Expand All @@ -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 <PATH>
# Setup register
Expand All @@ -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 <PATH>
# Setup register
Expand All @@ -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 <PATH>
# Setup register
Expand All @@ -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 <PATH>
# Setup register
Expand All @@ -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 <PATH>
# Setup register
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <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 <PATH>
# Setup register
Expand All @@ -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 = <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 <PATH>
# Setup register
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <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 <PATH>
# Setup register
Expand All @@ -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 = <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 <PATH>
# Setup register
Expand All @@ -41,11 +41,12 @@ Preprocessing library for sigs-0.1.0.0...
Running Haddock on library instantiated with
Data.Map = containers-<VERSION>: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 <PATH>
# Setup register
Registering library instantiated with Data.Map = containers-<VERSION>:Data.Map
Registering library instantiated with
Data.Map = containers-<VERSION>:Data.Map
for sigs-0.1.0.0...
# Setup configure
Configuring indef-0.1.0.0...
Expand All @@ -58,11 +59,12 @@ Preprocessing library for indef-0.1.0.0...
Running Haddock on library instantiated with
Data.Map = containers-<VERSION>: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 <PATH>
# Setup register
Registering library instantiated with Data.Map = containers-<VERSION>:Data.Map
Registering library instantiated with
Data.Map = containers-<VERSION>:Data.Map
for indef-0.1.0.0...
# Setup configure
Configuring exe-0.1.0.0...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <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 <PATH>
# Setup register
Expand All @@ -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 = <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 <PATH>
# Setup register
Expand All @@ -41,11 +41,12 @@ Preprocessing library for sigs-0.1.0.0...
Running Haddock on library instantiated with
Data.Map = containers-<VERSION>: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 <PATH>
# Setup register
Registering library instantiated with Data.Map = containers-<VERSION>:Data.Map
Registering library instantiated with
Data.Map = containers-<VERSION>:Data.Map
for sigs-0.1.0.0...
# Setup configure
Configuring indef-0.1.0.0...
Expand All @@ -58,11 +59,12 @@ Preprocessing library for indef-0.1.0.0...
Running Haddock on library instantiated with
Data.Map = containers-<VERSION>: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 <PATH>
# Setup register
Registering library instantiated with Data.Map = containers-<VERSION>:Data.Map
Registering library instantiated with
Data.Map = containers-<VERSION>:Data.Map
for indef-0.1.0.0...
# Setup configure
Configuring exe-0.1.0.0...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <PATH>
# Setup register
Expand All @@ -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
4 changes: 2 additions & 2 deletions cabal-testsuite/PackageTests/Backpack/Reexport1/setup.out
Original file line number Diff line number Diff line change
Expand Up @@ -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 <PATH>
# Setup register
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/TestNameCollision/setup.out
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 9 additions & 1 deletion cabal-testsuite/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ 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(..))"
, "import Distribution.Types.ModuleRenaming"
, "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
Expand All @@ -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"
Expand Down
Loading

0 comments on commit 34a3994

Please sign in to comment.