Skip to content

Commit 0ef4f44

Browse files
mpickeringMikolaj
authored andcommitted
testsuite: Run tests in temporary system directories
1. Working directory is not contaminated with results of the testsuite. Tests can be written in a more liberal way (creating/writing files etc). 2. The tests are more hermetic.. for example it was basically impossible to write a test which run outside of a project context. 3. The overall path lengths will be much shorter, which has been a consistent issue on windows. We can remove hacks like `withShorterPathForNewBuildStore`. Fixes #9711
1 parent d156a87 commit 0ef4f44

File tree

74 files changed

+332
-312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+332
-312
lines changed

Cabal/src/Distribution/Simple/Configure.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2587,7 +2587,12 @@ checkRelocatable verbosity pkg lbi =
25872587
-- @shortRelativePath prefix pkgroot@ will return a path with
25882588
-- @..@s and following check will fail without @canonicalizePath@.
25892589
canonicalized <- canonicalizePath libdir
2590-
unless (p `isPrefixOf` canonicalized) $
2590+
-- The @prefix@ itself must also be canonicalized because
2591+
-- canonicalizing @libdir@ may expand symlinks which would make
2592+
-- @prefix@ no longer being a prefix of @canonical libdir@,
2593+
-- while @canonical p@ could be a prefix of @canonical libdir@
2594+
p' <- canonicalizePath p
2595+
unless (p' `isPrefixOf` canonicalized) $
25912596
dieWithException verbosity $
25922597
LibDirDepsPrefixNotRelative libdir p
25932598
| otherwise =
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,82 @@
11
# cabal v1-configure
22
Resolving dependencies...
33
Configuring test-0...
4-
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.
4+
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.
55
# cabal v1-configure
66
Resolving dependencies...
77
Configuring test-0...
8-
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.
8+
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.
99
# cabal v1-configure
1010
Resolving dependencies...
1111
Configuring test-0...
12-
Warning: The path to the './configure' script, '/<ROOT>/cabal.dist/foo
12+
Warning: The path to the './configure' script, '/<ROOT>/foo
1313
bar/configure', contains the character '
1414
' (newline). This may cause the script to fail with an obscure error, or for building the package to fail later.
1515
# cabal v1-configure
1616
Resolving dependencies...
1717
Configuring test-0...
18-
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.
18+
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.
1919
# cabal v1-configure
2020
Resolving dependencies...
2121
Configuring test-0...
22-
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.
22+
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.
2323
# cabal v1-configure
2424
Resolving dependencies...
2525
Configuring test-0...
26-
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.
26+
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.
2727
# cabal v1-configure
2828
Resolving dependencies...
2929
Configuring test-0...
30-
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.
30+
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.
3131
# cabal v1-configure
3232
Resolving dependencies...
3333
Configuring test-0...
34-
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.
34+
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.
3535
# cabal v1-configure
3636
Resolving dependencies...
3737
Configuring test-0...
38-
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.
38+
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.
3939
# cabal v1-configure
4040
Resolving dependencies...
4141
Configuring test-0...
42-
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.
42+
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.
4343
# cabal v1-configure
4444
Resolving dependencies...
4545
Configuring test-0...
46-
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.
46+
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.
4747
# cabal v1-configure
4848
Resolving dependencies...
4949
Configuring test-0...
50-
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.
50+
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.
5151
# cabal v1-configure
5252
Resolving dependencies...
5353
Configuring test-0...
54-
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.
54+
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.
5555
# cabal v1-configure
5656
Resolving dependencies...
5757
Configuring test-0...
58-
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.
58+
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.
5959
# cabal v1-configure
6060
Resolving dependencies...
6161
Configuring test-0...
62-
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.
62+
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.
6363
# cabal v1-configure
6464
Resolving dependencies...
6565
Configuring test-0...
66-
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.
66+
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.
6767
# cabal v1-configure
6868
Resolving dependencies...
6969
Configuring test-0...
70-
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.
70+
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.
7171
# cabal v1-configure
7272
Resolving dependencies...
7373
Configuring test-0...
74-
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.
74+
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.
7575
# cabal v1-configure
7676
Resolving dependencies...
7777
Configuring test-0...
78-
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.
78+
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.
7979
# cabal v1-configure
8080
Resolving dependencies...
8181
Configuring test-0...
82-
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.
82+
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.

cabal-testsuite/PackageTests/AutoconfBadPaths/cabal.test.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Test.Cabal.Prelude
22
import Data.Foldable (traverse_)
3+
import Distribution.Simple.Utils
4+
import System.Directory
35
main = cabalTest $ do
46
-- Test the forbidden characters except NUL. Reference:
57
-- https://www.gnu.org/software/autoconf/manual/autoconf.html#File-System-Conventions
@@ -31,11 +33,21 @@ main = cabalTest $ do
3133
, "foo|bar"
3234
]
3335
where
36+
setup dir = do
37+
env <- getTestEnv
38+
let cwd = testCurrentDir env
39+
liftIO $ createDirectory (testCurrentDir env </> dir)
40+
liftIO $ copyFiles minBound (testCurrentDir env </> dir)
41+
[ (cwd, "configure")
42+
, (cwd, "Setup.hs")
43+
, (cwd, "test.cabal")
44+
]
3445
-- 'cabal' from the prelude requires the command to succeed; we
3546
-- don't mind if it fails, so long as we get the warning. This is
3647
-- an inlined+specialised version of 'cabal' for v1-configure.
37-
check dir = withSourceCopyDir dir $
48+
check dir =
3849
defaultRecordMode RecordMarked $ do
50+
setup dir
3951
recordHeader ["cabal", "v1-configure"]
4052
env <- getTestEnv
4153
let args =
@@ -46,7 +58,7 @@ main = cabalTest $ do
4658
]
4759
configured_prog <- requireProgramM cabalProgram
4860
r <- liftIO $ run (testVerbosity env)
49-
(Just (testCurrentDir env))
61+
(Just (testCurrentDir env </> dir))
5062
(testEnvironment env)
5163
(programPath configured_prog)
5264
args Nothing

cabal-testsuite/PackageTests/Check/ConfiguredPackage/Paths/InvalidWin/cabal.test.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Test.Cabal.Prelude
33
import System.Directory (createDirectoryIfMissing)
44

55
-- Invalid Windows filepath.
6-
main = cabalTest . withSourceCopy $ do
6+
main = cabalTest $ do
77
skipIfWindows
88
cwd <- testCurrentDir <$> getTestEnv
99
liftIO $ createDirectoryIfMissing False $ cwd </> "n?ul"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module Main where
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import Test.Cabal.Prelude
22

33
-- Relative filepath outside source tree.
44
main = cabalTest $
5-
fails $ cabal "check" []
5+
fails $ withDirectory "RelativeOutsideInner" $ cabal "check" []
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Test.Cabal.Prelude
22
main = cabalTest $ do
3-
withRepo "repo" . withSourceCopy $ do
3+
withRepo "repo" $ do
44
cabal "v1-freeze" ["--disable-benchmarks"]
55
cwd <- fmap testCurrentDir getTestEnv
66
assertFileDoesNotContain (cwd </> "cabal.config") "criterion"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Test.Cabal.Prelude
22
main = cabalTest $ do
3-
withRepo "repo" . withSourceCopy $ do
3+
withRepo "repo" $ do
44
cabal "v1-freeze" ["--disable-tests"]
55
cwd <- fmap testCurrentDir getTestEnv
66
assertFileDoesNotContain (cwd </> "cabal.config") "test-framework"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Test.Cabal.Prelude
22
main = cabalTest $ do
3-
withRepo "repo" . withSourceCopy $ do
3+
withRepo "repo" $ do
44
recordMode DoNotRecord $ cabal "v1-freeze" ["--dry-run"]
55
cwd <- fmap testCurrentDir getTestEnv
66
shouldNotExist (cwd </> "cabal.config")

0 commit comments

Comments
 (0)