Skip to content

Commit 9d9bf65

Browse files
9999yearserikd
authored andcommitted
Fix HaddockKeepTmpsCustom test for merge skew
The `HaddockKeepTmpsCustom` test added in haskell#10392 skewed against haskell#10366, which changes where temporary files are written. We can work around this by setting `$TMPDIR` and `$TEMP` while running tests, so that temporary files are written to the test's temporary directory rather than the system one.
1 parent a7eacfa commit 9d9bf65

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ main = cabalTest $ recordMode DoNotRecord $ withProjectFile "cabal.project" $ do
1111
-- "foobar.ext" will be "fooXXX.ext".
1212
let glob =
1313
if isWindows
14-
then "**/had*.txt"
15-
else "**/haddock-response*.txt"
14+
then "had*.txt"
15+
else "haddock-response*.txt"
1616

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

2020
-- Check that the matched response file is not empty, and is indeed a Haddock
2121
-- response file.
Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
{-# LANGUAGE LambdaCase #-}
2-
import Test.Cabal.Prelude
3-
import Data.List (sort, isPrefixOf)
4-
import Distribution.Verbosity
1+
import Data.List (isPrefixOf, sort)
52
import Distribution.Simple.Glob
63
import Distribution.Simple.Glob.Internal
74
import Distribution.Simple.Utils
5+
import Distribution.Verbosity
86
import System.Directory
7+
import Test.Cabal.Prelude
98

109
-- Test that "cabal haddock" preserves temporary files
1110
-- We use haddock-keep-temp-file: True in the cabal.project.
1211
main =
1312
cabalTest $ recordMode DoNotRecord $ withProjectFile "cabal.project" $ do
14-
pwd <- testTmpDir <$> getTestEnv
15-
liftIO $ createDirectory (pwd </> "temp")
16-
withEnv [(if isWindows then "TMP" else "TMPDIR", Just $ pwd </> "temp")] $
17-
cabal "haddock" []
18-
files <- liftIO $ listDirectory (pwd </> "temp")
19-
case [ pwd </> "temp" </> f | f <- files, takeExtension f == ".txt" ] of
20-
[] -> error "Expecting a response file being mentioned in the outcome"
21-
files' ->
22-
-- Assert the matched response file is not empty, and indeed a haddock rsp
23-
assertAnyFileContains files' "--package-name"
13+
cabal "haddock" []
14+
15+
-- From the docs for `System.IO.openTempFile`:
16+
--
17+
-- On Windows, the template prefix may be truncated to 3 chars, e.g.
18+
-- "foobar.ext" will be "fooXXX.ext".
19+
let glob =
20+
if isWindows
21+
then "had*.txt"
22+
else "haddock-response*.txt"
23+
24+
-- Check that there is a response file.
25+
responseFiles <- assertGlobMatchesTestDir testTmpDir glob
26+
27+
-- Check that the matched response file is not empty, and is indeed a Haddock
28+
-- response file.
29+
assertAnyFileContains responseFiles "--package-name"

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ runTestM mode m =
410410
-- effect on Windows.
411411
, ("CABAL_DIR", Just (testCabalDir env))
412412
, ("CABAL_CONFIG", Just (testUserCabalConfigFile env))
413+
-- Set `TMPDIR` so that temporary files aren't created in the global `TMPDIR`.
414+
, ("TMPDIR", Just tmp_dir)
415+
-- Windows uses `TMP` for the `TMPDIR`.
416+
, ("TMP", Just tmp_dir)
413417
],
414418
testShouldFail = False,
415419
testRelativeCurrentDir = ".",

0 commit comments

Comments
 (0)