|
1 |
| -{-# LANGUAGE LambdaCase #-} |
2 |
| -import Test.Cabal.Prelude |
3 |
| -import Data.List (sort, isPrefixOf) |
4 |
| -import Distribution.Verbosity |
| 1 | +import Data.List (isPrefixOf, sort) |
5 | 2 | import Distribution.Simple.Glob
|
6 | 3 | import Distribution.Simple.Glob.Internal
|
7 | 4 | import Distribution.Simple.Utils
|
| 5 | +import Distribution.Verbosity |
8 | 6 | import System.Directory
|
| 7 | +import Test.Cabal.Prelude |
9 | 8 |
|
10 | 9 | -- Test that "cabal haddock" preserves temporary files
|
11 | 10 | -- We use haddock-keep-temp-file: True in the cabal.project.
|
12 | 11 | main =
|
13 | 12 | 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" |
0 commit comments