Skip to content

Commit

Permalink
tests: use bracket instead of withFile for clearer exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom McLaughlin committed Dec 4, 2024
1 parent 53571f6 commit c64b7f1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/src/TestLib/LSP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ withLspSession' handleFn name filename codeToTest extraFiles session = do
info [i|LSP config: #{A.encode config}|]

homeDir <- liftIO $ createTempDirectory currentFolder "home"
pathToUse <- withFile "/dev/null" WriteMode $ \devNullHandle ->
pathToUse <- bracket (openFile "/dev/null" WriteMode) hClose $ \devNullHandle ->
(T.unpack . T.strip . T.pack) <$> readCreateProcess ((proc "nix" ["run", ".#print-basic-path"]) { std_err = UseHandle devNullHandle }) ""

forM_ extraFiles $ \(path, bytes) -> do
Expand Down
3 changes: 2 additions & 1 deletion tests/src/TestLib/NixEnvironmentContext.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import TestLib.NixTypes
import TestLib.Types
import TestLib.Util
import UnliftIO.Directory
import UnliftIO.Exception
import UnliftIO.IO
import UnliftIO.Process
import UnliftIO.Temporary
Expand All @@ -34,7 +35,7 @@ introduceNixEnvironment :: (
introduceNixEnvironment kernels otherConfig label = introduceWith [i|#{label} Nix|] nixEnvironment $ \action -> do
rootDir <- findFirstParentMatching (\x -> doesPathExist (x </> ".git"))

metadata :: A.Object <- withFile "/dev/null" WriteMode $ \devNullHandle -> do
metadata :: A.Object <- bracket (openFile "/dev/null" WriteMode) hClose $ \devNullHandle -> do
let cp = (proc "nix" ["flake", "metadata", "--json"]) {
cwd = Just rootDir
, std_err = UseHandle devNullHandle
Expand Down

0 comments on commit c64b7f1

Please sign in to comment.