Skip to content
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

Add haddock --keep-temp-files test #10392

Conversation

9999years
Copy link
Collaborator

@9999years 9999years commented Sep 27, 2024

Split off of #10292

Thanks to @mpickering for helping with this test case.

  • Patches conform to the coding conventions.
  • Is this a PR that fixes CI? If so, it will need to be backported to older cabal release branches (ask maintainers for directions).

Depends-on: #10388

@mpickering
Copy link
Collaborator

This seems to depend on #10388

@geekosaur
Copy link
Collaborator

Yes, that's why there's a Depends-on: in the header.

@9999years 9999years force-pushed the wiggles/add-haddock-keep-temp-files-test branch 3 times, most recently from 3001d28 to 7a181f1 Compare September 30, 2024 21:41
@9999years
Copy link
Collaborator Author

@mpickering This seems to be failing on Windows, would you mind taking a look at it?

@mpickering
Copy link
Collaborator

mpickering commented Oct 1, 2024

It appears on windows the response file is called had5244.txt rather than haddock-response.txt, I will look into modifying the test.

@mpickering
Copy link
Collaborator

@9999years It seems that in the original patch I provided it worked on windows. Could you restore that approach to the test? I

+{-# LANGUAGE LambdaCase #-}
+import Test.Cabal.Prelude
+import Data.List (sort)
+import Distribution.Verbosity
+import Distribution.Simple.Glob
+import Distribution.Simple.Glob.Internal
+import Distribution.Simple.Utils
+
+-- 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
+    cabal "haddock" []
+
+    cwd <- fmap testCurrentDir getTestEnv
+
+    -- Windows has multiple response files, and only the last one (alphabetically) is the important one.
+    (safeLast . sort . globMatches <$> liftIO (runDirFileGlob silent Nothing cwd (GlobDirRecursive [WildCard, Literal "txt"]))) >>= \case
+      Nothing -> error "Expecting a response file to exist"
+      Just m -> do
+        -- Assert the matched response file is not empty, and indeed a haddock rsp
+        assertFileDoesContain (cwd </> m) "--package-name"

I tried to push a commit which restored the test to this form but I don't have permission to push to your branch.

@9999years
Copy link
Collaborator Author

Ah:

File name template. If the template is "foo.ext" then the created file will be "fooXXX.ext" where XXX is some random number. Note that this should not contain any path separator characters. On Windows, the template prefix may be truncated to 3 chars, e.g. "foobar.ext" will be "fooXXX.ext".

https://hackage.haskell.org/package/base-4.20.0.1/docs/System-IO.html#v:openTempFile

@9999years 9999years force-pushed the wiggles/add-haddock-keep-temp-files-test branch from 7a181f1 to 3109e54 Compare October 1, 2024 16:32
@9999years
Copy link
Collaborator Author

@mpickering I've updated the test. I think it's a bit more readable this way, and the error messages for failures will be more informative. Let me know what you think.

@9999years 9999years force-pushed the wiggles/add-haddock-keep-temp-files-test branch from 3109e54 to b0b6abd Compare October 1, 2024 17:12
@9999years 9999years marked this pull request as ready for review October 1, 2024 22:03
Copy link
Collaborator

@mpickering mpickering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine.

@mpickering mpickering added the merge me Tell Mergify Bot to merge label Oct 2, 2024
@mergify mergify bot added ready and waiting Mergify is waiting out the cooldown period merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days labels Oct 2, 2024
@geekosaur geekosaur added merge+no rebase and removed merge me Tell Mergify Bot to merge labels Oct 4, 2024
@geekosaur
Copy link
Collaborator

@mergify refresh

Copy link
Contributor

mergify bot commented Oct 4, 2024

refresh

✅ Pull request refreshed

@mergify mergify bot merged commit 5dae4e4 into haskell:master Oct 4, 2024
47 of 48 checks passed
@9999years 9999years deleted the wiggles/add-haddock-keep-temp-files-test branch October 4, 2024 16:26
9999years added a commit to 9999years/cabal that referenced this pull request Oct 4, 2024
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.
9999years added a commit to 9999years/cabal that referenced this pull request Oct 4, 2024
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.
Mikolaj pushed a commit to 9999years/cabal that referenced this pull request Oct 5, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days merge+no rebase ready and waiting Mergify is waiting out the cooldown period
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants