Skip to content

Fix HaddockKeepTmpsCustom test for merge skew #10424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading