Skip to content

Commit

Permalink
Merge pull request haskell#10424 from 9999years/fix-tmpdir
Browse files Browse the repository at this point in the history
Fix `HaddockKeepTmpsCustom` test for merge skew
  • Loading branch information
mergify[bot] authored Oct 5, 2024
2 parents 44e12fd + 82357a8 commit b1e842d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ main = cabalTest $ recordMode DoNotRecord $ withProjectFile "cabal.project" $ do
-- "foobar.ext" will be "fooXXX.ext".
let glob =
if isWindows
then "**/had*.txt"
else "**/haddock-response*.txt"
then "had*.txt"
else "haddock-response*.txt"

-- Check that there is a response file.
responseFiles <- assertGlobMatchesTestDir testDistDir glob
responseFiles <- assertGlobMatchesTestDir testTmpDir glob

-- Check that the matched response file is not empty, and is indeed a Haddock
-- response file.
Expand Down
34 changes: 20 additions & 14 deletions cabal-testsuite/PackageTests/HaddockKeepsTmps/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
{-# LANGUAGE LambdaCase #-}
import Test.Cabal.Prelude
import Data.List (sort, isPrefixOf)
import Distribution.Verbosity
import Data.List (isPrefixOf, sort)
import Distribution.Simple.Glob
import Distribution.Simple.Glob.Internal
import Distribution.Simple.Utils
import Distribution.Verbosity
import System.Directory
import Test.Cabal.Prelude

-- Test that "cabal haddock" preserves temporary files
-- We use haddock-keep-temp-file: True in the cabal.project.
main =
cabalTest $ recordMode DoNotRecord $ withProjectFile "cabal.project" $ do
pwd <- testTmpDir <$> getTestEnv
liftIO $ createDirectory (pwd </> "temp")
withEnv [(if isWindows then "TMP" else "TMPDIR", Just $ pwd </> "temp")] $
cabal "haddock" []
files <- liftIO $ listDirectory (pwd </> "temp")
case [ pwd </> "temp" </> f | f <- files, takeExtension f == ".txt" ] of
[] -> error "Expecting a response file being mentioned in the outcome"
files' ->
-- Assert the matched response file is not empty, and indeed a haddock rsp
assertAnyFileContains files' "--package-name"
cabal "haddock" []

-- From the docs for `System.IO.openTempFile`:
--
-- On Windows, the template prefix may be truncated to 3 chars, e.g.
-- "foobar.ext" will be "fooXXX.ext".
let glob =
if isWindows
then "had*.txt"
else "haddock-response*.txt"

-- Check that there is a response file.
responseFiles <- assertGlobMatchesTestDir testTmpDir glob

-- Check that the matched response file is not empty, and is indeed a Haddock
-- response file.
assertAnyFileContains responseFiles "--package-name"
4 changes: 4 additions & 0 deletions cabal-testsuite/src/Test/Cabal/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ runTestM mode m =
-- effect on Windows.
, ("CABAL_DIR", Just (testCabalDir env))
, ("CABAL_CONFIG", Just (testUserCabalConfigFile env))
-- Set `TMPDIR` so that temporary files aren't created in the global `TMPDIR`.
, ("TMPDIR", Just tmp_dir)
-- Windows uses `TMP` for the `TMPDIR`.
, ("TMP", Just tmp_dir)
],
testShouldFail = False,
testRelativeCurrentDir = ".",
Expand Down

0 comments on commit b1e842d

Please sign in to comment.