Skip to content

Commit

Permalink
Merge pull request #9717 from mpickering/wip/system-testsuite
Browse files Browse the repository at this point in the history
testsuite: Run tests in temporary system directories
  • Loading branch information
mergify[bot] authored Feb 28, 2024
2 parents d156a87 + 0ef4f44 commit 9e5e815
Show file tree
Hide file tree
Showing 74 changed files with 332 additions and 312 deletions.
7 changes: 6 additions & 1 deletion Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2587,7 +2587,12 @@ checkRelocatable verbosity pkg lbi =
-- @shortRelativePath prefix pkgroot@ will return a path with
-- @..@s and following check will fail without @canonicalizePath@.
canonicalized <- canonicalizePath libdir
unless (p `isPrefixOf` canonicalized) $
-- The @prefix@ itself must also be canonicalized because
-- canonicalizing @libdir@ may expand symlinks which would make
-- @prefix@ no longer being a prefix of @canonical libdir@,
-- while @canonical p@ could be a prefix of @canonical libdir@
p' <- canonicalizePath p
unless (p' `isPrefixOf` canonicalized) $
dieWithException verbosity $
LibDirDepsPrefixNotRelative libdir p
| otherwise =
Expand Down
40 changes: 20 additions & 20 deletions cabal-testsuite/PackageTests/AutoconfBadPaths/cabal.out
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo bar/configure', contains the character ' ' (space). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo bar/configure', contains the character ' ' (space). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo bar/configure', contains the character ' ' (tab). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo bar/configure', contains the character ' ' (tab). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo
Warning: The path to the './configure' script, '/<ROOT>/foo
bar/configure', contains the character '
' (newline). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo"bar/configure', contains the character '"' (double quote). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo"bar/configure', contains the character '"' (double quote). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo#bar/configure', contains the character '#' (hash). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo#bar/configure', contains the character '#' (hash). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo$bar/configure', contains the character '$' (dollar sign). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo$bar/configure', contains the character '$' (dollar sign). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo&bar/configure', contains the character '&' (ampersand). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo&bar/configure', contains the character '&' (ampersand). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo'bar/configure', contains the character ''' (single quote). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo'bar/configure', contains the character ''' (single quote). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo(bar/configure', contains the character '(' (left bracket). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo(bar/configure', contains the character '(' (left bracket). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo)bar/configure', contains the character ')' (right bracket). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo)bar/configure', contains the character ')' (right bracket). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo*bar/configure', contains the character '*' (star). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo*bar/configure', contains the character '*' (star). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo;bar/configure', contains the character ';' (semicolon). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo;bar/configure', contains the character ';' (semicolon). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo<bar/configure', contains the character '<' (less-than sign). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo<bar/configure', contains the character '<' (less-than sign). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo=bar/configure', contains the character '=' (equals sign). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo=bar/configure', contains the character '=' (equals sign). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo>bar/configure', contains the character '>' (greater-than sign). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo>bar/configure', contains the character '>' (greater-than sign). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo?bar/configure', contains the character '?' (question mark). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo?bar/configure', contains the character '?' (question mark). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo[bar/configure', contains the character '[' (left square bracket). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo[bar/configure', contains the character '[' (left square bracket). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo/bar/configure', contains the character '/' (backslash). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo/bar/configure', contains the character '/' (backslash). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo`bar/configure', contains the character '`' (backtick). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo`bar/configure', contains the character '`' (backtick). This may cause the script to fail with an obscure error, or for building the package to fail later.
# cabal v1-configure
Resolving dependencies...
Configuring test-0...
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo|bar/configure', contains the character '|' (pipe). This may cause the script to fail with an obscure error, or for building the package to fail later.
Warning: The path to the './configure' script, '/<ROOT>/foo|bar/configure', contains the character '|' (pipe). This may cause the script to fail with an obscure error, or for building the package to fail later.
16 changes: 14 additions & 2 deletions cabal-testsuite/PackageTests/AutoconfBadPaths/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Test.Cabal.Prelude
import Data.Foldable (traverse_)
import Distribution.Simple.Utils
import System.Directory
main = cabalTest $ do
-- Test the forbidden characters except NUL. Reference:
-- https://www.gnu.org/software/autoconf/manual/autoconf.html#File-System-Conventions
Expand Down Expand Up @@ -31,11 +33,21 @@ main = cabalTest $ do
, "foo|bar"
]
where
setup dir = do
env <- getTestEnv
let cwd = testCurrentDir env
liftIO $ createDirectory (testCurrentDir env </> dir)
liftIO $ copyFiles minBound (testCurrentDir env </> dir)
[ (cwd, "configure")
, (cwd, "Setup.hs")
, (cwd, "test.cabal")
]
-- 'cabal' from the prelude requires the command to succeed; we
-- don't mind if it fails, so long as we get the warning. This is
-- an inlined+specialised version of 'cabal' for v1-configure.
check dir = withSourceCopyDir dir $
check dir =
defaultRecordMode RecordMarked $ do
setup dir
recordHeader ["cabal", "v1-configure"]
env <- getTestEnv
let args =
Expand All @@ -46,7 +58,7 @@ main = cabalTest $ do
]
configured_prog <- requireProgramM cabalProgram
r <- liftIO $ run (testVerbosity env)
(Just (testCurrentDir env))
(Just (testCurrentDir env </> dir))
(testEnvironment env)
(programPath configured_prog)
args Nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Test.Cabal.Prelude
import System.Directory (createDirectoryIfMissing)

-- Invalid Windows filepath.
main = cabalTest . withSourceCopy $ do
main = cabalTest $ do
skipIfWindows
cwd <- testCurrentDir <$> getTestEnv
liftIO $ createDirectoryIfMissing False $ cwd </> "n?ul"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Main where
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- Relative filepath outside source tree.
main = cabalTest $
fails $ cabal "check" []
fails $ withDirectory "RelativeOutsideInner" $ cabal "check" []
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Test.Cabal.Prelude
main = cabalTest $ do
withRepo "repo" . withSourceCopy $ do
withRepo "repo" $ do
cabal "v1-freeze" ["--disable-benchmarks"]
cwd <- fmap testCurrentDir getTestEnv
assertFileDoesNotContain (cwd </> "cabal.config") "criterion"
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/Freeze/disable-tests.test.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Test.Cabal.Prelude
main = cabalTest $ do
withRepo "repo" . withSourceCopy $ do
withRepo "repo" $ do
cabal "v1-freeze" ["--disable-tests"]
cwd <- fmap testCurrentDir getTestEnv
assertFileDoesNotContain (cwd </> "cabal.config") "test-framework"
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/Freeze/dry-run.test.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Test.Cabal.Prelude
main = cabalTest $ do
withRepo "repo" . withSourceCopy $ do
withRepo "repo" $ do
recordMode DoNotRecord $ cabal "v1-freeze" ["--dry-run"]
cwd <- fmap testCurrentDir getTestEnv
shouldNotExist (cwd </> "cabal.config")
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Test.Cabal.Prelude
main = cabalTest $ do
withRepo "repo" . withSourceCopy $ do
withRepo "repo" $ do
cabal "v1-freeze" ["--enable-benchmarks"]
cwd <- fmap testCurrentDir getTestEnv
assertFileDoesContain (cwd </> "cabal.config") "criterion"
Expand Down
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/Freeze/enable-tests.test.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Test.Cabal.Prelude
main = cabalTest $ do
withRepo "repo" . withSourceCopy $ do
withRepo "repo" $ do
cabal "v1-freeze" ["--enable-tests"]
cwd <- fmap testCurrentDir getTestEnv
assertFileDoesContain (cwd </> "cabal.config") "test-framework"
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/Freeze/freeze.test.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Test.Cabal.Prelude
main = cabalTest $ do
withRepo "repo" . withSourceCopy $ do
withRepo "repo" $ do
cabal "v1-freeze" []
cwd <- fmap testCurrentDir getTestEnv
assertFileDoesNotContain (cwd </> "cabal.config") "exceptions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ Installing library in <PATH>
Configuring library for a-0.1.0.0...
Preprocessing library for a-0.1.0.0...
Running Haddock on library for a-0.1.0.0...
Documentation created: <ROOT>/haddock-project.dist/source/dist-newstyle/build/<ARCH>/ghc-<GHCVER>/a-0.1.0.0/doc/html/a/
Documentation created: <ROOT>/dist-newstyle/build/<ARCH>/ghc-<GHCVER>/a-0.1.0.0/doc/html/a/
Documentation created: haddocks/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Test.Cabal.Prelude
import System.Directory (doesFileExist, removeDirectory)

main = cabalTest . withRepo "repo" . withSourceCopy $ do
main = cabalTest . withRepo "repo" $ do
skipUnlessGhcVersion ">= 9.4.0"
env <- getTestEnv
let testDir = testCurrentDir env
Expand Down
9 changes: 4 additions & 5 deletions cabal-testsuite/PackageTests/Init/init-backup.test.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import Test.Cabal.Prelude

main = cabalTest $
withSourceCopyDir "app" $ do
cwd <- fmap testSourceCopyDir getTestEnv
main = cabalTest $ do
cwd <- fmap testCurrentDir getTestEnv

(initOut, buildOut) <- withDirectory cwd $ do
initOut <- cabalWithStdin "init" ["-i"]
(initOut, buildOut) <- do
initOut <- cabalWithStdin "init" ["-i", "-p", "app"]
"2\ny\n5\n\n\n2\n\n\n\n\n\n\n\n\n\n"
setup "configure" []
buildOut <- setup' "build" ["app"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Test.Cabal.Prelude
import System.Directory

main = cabalTest $ do
tmpDir <- testTmpDir <$> getTestEnv
withDirectory tmpDir $ do
tmpDir <- testCurrentDir <$> getTestEnv
liftIO $ createDirectory (tmpDir </> "empty")
withDirectory (tmpDir </> "empty") $ do
res <- cabalWithStdin "init"
["-i"]
(replicate 20 '\n') -- Default all the way down.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import Test.Cabal.Prelude

main = cabalTest $
withSourceCopyDir "app" $ do
cwd <- fmap testSourceCopyDir getTestEnv
main = cabalTest $ do
env <- getTestEnv
buildOut <-
cabalWithStdin "init" ["-i", "-p", "app"]
"2\n\n5\n\n\n2\n\n\n\n\n\n\n3\n\n"

buildOut <- withDirectory cwd $ do
cabalWithStdin "init" ["-i"]
"2\n\n5\n\n\n2\n\n\n\n\n\n\n\n3\n\n"

assertFileDoesContain (cwd </> "app.cabal") "GHC2021"
assertFileDoesContain (testCurrentDir env </> "app.cabal") "GHC2021"
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import Test.Cabal.Prelude

main = cabalTest $
withSourceCopyDir "app" $ do
cwd <- fmap testSourceCopyDir getTestEnv

buildOut <- withDirectory cwd $ do
cabalWithStdin "init" ["-i"]
"2\n\n1\n\n\n10\n\n\n\n\n\n\n\n\n\n"
main = cabalTest $ do
cwd <- testCurrentDir <$> getTestEnv
buildOut <- do
cabalWithStdin "init" ["-i", "-p", "app"]
"2\n\n1\n\n10\n\n\n\n\n\n\n\n\n\n"
setup "configure" []
setup' "build" ["app"]

Expand Down
7 changes: 3 additions & 4 deletions cabal-testsuite/PackageTests/Init/init-interactive.test.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import Test.Cabal.Prelude

main = cabalTest $
withSourceCopyDir "app" $ do
cwd <- fmap testSourceCopyDir getTestEnv
main = cabalTest $ do
cwd <- fmap testCurrentDir getTestEnv

buildOut <- withDirectory cwd $ do
cabalWithStdin "init" ["-i"]
cabalWithStdin "init" ["-i", "-p", "app"]
"2\n\n5\n\n\n\n\n\n\n\n\n\n\n\n\n"
setup "configure" []
setup' "build" ["app"]
Expand Down
9 changes: 4 additions & 5 deletions cabal-testsuite/PackageTests/Init/init-legacy.test.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import Test.Cabal.Prelude

main = cabalTest $
withSourceCopyDir "app" $ do
cwd <- fmap testSourceCopyDir getTestEnv
main = cabalTest $ do
cwd <- fmap testCurrentDir getTestEnv

buildOut <- withDirectory cwd $ do
cabal "init" ["-n", "--exe", "--application-dir=app", "--main-is=Main.hs", "--cabal-version=1.24"]
buildOut <- do
cabal "init" ["-n", "--exe", "-p", "app", "--application-dir=app", "--main-is=Main.hs", "--cabal-version=1.24"]
setup "configure" []
setup' "build" ["app"]

Expand Down
10 changes: 5 additions & 5 deletions cabal-testsuite/PackageTests/Init/init.test.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Test.Cabal.Prelude
import System.Directory

main = cabalTest $
withSourceCopyDir "app" $ do
cwd <- fmap testSourceCopyDir getTestEnv
main = cabalTest $ do
cwd <- fmap testCurrentDir getTestEnv

buildOut <- withDirectory cwd $ do
cabal "init" ["-n", "--exe", "--application-dir=app", "--main-is=Main.hs"]
buildOut <- do
cabal "init" ["-n", "--exe", "-p", "app", "--application-dir=app", "--main-is=Main.hs"]
setup "configure" []
setup' "build" ["app"]

Expand Down
Loading

0 comments on commit 9e5e815

Please sign in to comment.