Skip to content

Commit c64a32d

Browse files
mpickeringMikolaj
authored andcommitted
testsuite: Set TMPDIR to a specific folder rather than the test root
If things start getting created in the TMPDIR, then it is better to not place them directly in the project root next to the source and test files. This also makes it easier to write tests which are sensitive to what is created in the CWD.
1 parent 8a5a331 commit c64a32d

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ main = cabalTest $ recordMode DoNotRecord $ withProjectFile "cabal.project" $ do
1515
else "haddock-response*.txt"
1616

1717
-- Check that there is a response file.
18-
responseFiles <- assertGlobMatchesTestDir testTmpDir glob
18+
responseFiles <- assertGlobMatchesTestDir testSystemTmpDir glob
1919

2020
-- Check that the matched response file is not empty, and is indeed a Haddock
2121
-- response file.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ main =
2222
else "haddock-response*.txt"
2323

2424
-- Check that there is a response file.
25-
responseFiles <- assertGlobMatchesTestDir testTmpDir glob
25+
responseFiles <- assertGlobMatchesTestDir testSystemTmpDir glob
2626

2727
-- Check that the matched response file is not empty, and is indeed a Haddock
2828
-- response file.

cabal-testsuite/src/Test/Cabal/Monad.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module Test.Cabal.Monad (
3434
testPrefixDir,
3535
testLibInstallDir,
3636
testDistDir,
37+
testSystemTmpDir,
3738
testPackageDbDir,
3839
testRepoDir,
3940
testKeysDir,
@@ -407,9 +408,9 @@ runTestM mode m =
407408
, ("CABAL_DIR", Just (testCabalDir env))
408409
, ("CABAL_CONFIG", Just (testUserCabalConfigFile env))
409410
-- Set `TMPDIR` so that temporary files aren't created in the global `TMPDIR`.
410-
, ("TMPDIR", Just tmp_dir)
411+
, ("TMPDIR", Just (testSystemTmpDir env))
411412
-- Windows uses `TMP` for the `TMPDIR`.
412-
, ("TMP", Just tmp_dir)
413+
, ("TMP", Just (testSystemTmpDir env))
413414
],
414415
testShouldFail = False,
415416
testRelativeCurrentDir = ".",
@@ -548,6 +549,7 @@ initWorkDir :: TestM ()
548549
initWorkDir = do
549550
env <- getTestEnv
550551
liftIO $ createDirectoryIfMissing True (testWorkDir env)
552+
liftIO $ createDirectoryIfMissing True (testSystemTmpDir env)
551553

552554

553555

@@ -824,6 +826,11 @@ testName env = testSubName env <.> testMode env
824826
testWorkDir :: TestEnv -> FilePath
825827
testWorkDir env = testTmpDir env </> (testName env <.> "dist")
826828

829+
-- The folder which TMPDIR is set to.
830+
-- This is different to testTmpDir, which is the folder which is the test is run from.
831+
testSystemTmpDir :: TestEnv -> FilePath
832+
testSystemTmpDir env = testWorkDir env </> "tmp"
833+
827834
-- | The absolute prefix where installs go.
828835
testPrefixDir :: TestEnv -> FilePath
829836
testPrefixDir env = testWorkDir env </> "usr"

0 commit comments

Comments
 (0)