From 1592c519c5d1ec5a0c5c56f7aba2c9dd48a487f2 Mon Sep 17 00:00:00 2001 From: parsonsmatt Date: Mon, 4 Nov 2024 10:33:28 -0700 Subject: [PATCH] Fix tests --- .../UnitTests/Distribution/Simple/Glob.hs | 4 ++-- Cabal/src/Distribution/Simple/Glob.hs | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Cabal-tests/tests/UnitTests/Distribution/Simple/Glob.hs b/Cabal-tests/tests/UnitTests/Distribution/Simple/Glob.hs index fce1ffbc050..c07fbb38623 100644 --- a/Cabal-tests/tests/UnitTests/Distribution/Simple/Glob.hs +++ b/Cabal-tests/tests/UnitTests/Distribution/Simple/Glob.hs @@ -107,13 +107,13 @@ testMatchesVersion version pat expected = do -- check can't identify that kind of match. expected' = filter (\case GlobMatchesDirectory _ -> False; _ -> True) expected unless (sort expected' == sort actual) $ - assertFailure $ "Unexpected result (pure matcher): " ++ show actual + assertFailure $ "Unexpected result (pure matcher): " ++ show actual ++ "\nExpected: " ++ show expected checkIO globPat = withSystemTempDirectory "globstar-sample" $ \tmpdir -> do makeSampleFiles tmpdir actual <- runDirFileGlob Verbosity.normal (Just version) tmpdir globPat unless (isEqual actual expected) $ - assertFailure $ "Unexpected result (impure matcher): " ++ show actual + assertFailure $ "Unexpected result (impure matcher): " ++ show actual ++ "\nExpected: " ++ show expected testFailParseVersion :: CabalSpecVersion -> FilePath -> GlobSyntaxError -> Assertion testFailParseVersion version pat expected = diff --git a/Cabal/src/Distribution/Simple/Glob.hs b/Cabal/src/Distribution/Simple/Glob.hs index 2d1404bc870..d15c4a0dfff 100644 --- a/Cabal/src/Distribution/Simple/Glob.hs +++ b/Cabal/src/Distribution/Simple/Glob.hs @@ -432,13 +432,17 @@ runDirFileGlob verbosity mspec rawRoot pat = do case pathOrVariablePattern of Left filename -> do - let filepath = root joinedPrefix filename - debug verbosity $ "Treating glob as filepath literal: " ++ filepath - exist <- doesFileExist filepath - pure $ - if exist - then [GlobMatch filepath] - else [] + let filepath = joinedPrefix filename + debug verbosity $ "Treating glob as filepath literal '" ++ filepath ++ "' in directory '" ++ root ++ "'." + directoryExists <- doesDirectoryExist (root filepath) + if directoryExists + then pure [GlobMatchesDirectory filepath] + else do + exist <- doesFileExist (root filepath) + pure $ + if exist + then [GlobMatch filepath] + else [] Right variablePattern -> do debug verbosity $ "Expanding glob '" ++ show (pretty pat) ++ "' in directory '" ++ root ++ "'." directoryExists <- doesDirectoryExist (root joinedPrefix)