-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
findFile et al: ignore dirs when abs path is given
When an absolute path is given, the list of search directories is now completely ignored by findFile. Previously, if the list was empty, findFile would always fail regardless of whether the absolute path was found. This behavior extends to similar functions as well. Fixes #72.
- Loading branch information
1 parent
af307f5
commit 1adba7a
Showing
4 changed files
with
174 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,51 @@ | ||
{-# LANGUAGE CPP #-} | ||
module FindFile001 where | ||
#include "util.inl" | ||
import qualified Data.List as List | ||
import System.FilePath ((</>)) | ||
|
||
main :: TestEnv -> IO () | ||
main _t = do | ||
|
||
createDirectory "bar" | ||
createDirectory "qux" | ||
writeFile "foo" "" | ||
found <- findFile ("." : undefined) "foo" | ||
T(expectEq) () found (Just ("." </> "foo")) | ||
writeFile ("bar" </> "foo") "" | ||
writeFile ("qux" </> "foo") ":3" | ||
|
||
-- make sure findFile is lazy enough | ||
T(expectEq) () (Just ("." </> "foo")) =<< findFile ("." : undefined) "foo" | ||
|
||
-- make sure relative paths work | ||
T(expectEq) () (Just ("." </> "bar" </> "foo")) =<< | ||
findFile ["."] ("bar" </> "foo") | ||
|
||
T(expectEq) () (Just ("." </> "foo")) =<< findFile [".", "bar"] ("foo") | ||
T(expectEq) () (Just ("bar" </> "foo")) =<< findFile ["bar", "."] ("foo") | ||
|
||
let f fn = (== ":3") <$> readFile fn | ||
for_ (List.permutations ["qux", "bar", "."]) $ \ ds -> do | ||
|
||
let (match, noMatch) = List.partition (== "qux") ds | ||
|
||
T(expectEq) ds (Just (List.head match </> "foo")) =<< | ||
findFileWith f ds "foo" | ||
|
||
T(expectEq) ds ((</> "foo") <$> match) =<< findFilesWith f ds "foo" | ||
|
||
T(expectEq) ds (Just (List.head noMatch </> "foo")) =<< | ||
findFileWith ((not <$>) . f) ds "foo" | ||
|
||
T(expectEq) ds ((</> "foo") <$> noMatch) =<< | ||
findFilesWith ((not <$>) . f) ds "foo" | ||
|
||
T(expectEq) ds Nothing =<< findFileWith (\ _ -> return False) ds "foo" | ||
|
||
T(expectEq) ds [] =<< findFilesWith (\ _ -> return False) ds "foo" | ||
|
||
-- make sure absolute paths are handled properly irrespective of 'dirs' | ||
-- https://github.com/haskell/directory/issues/72 | ||
absPath <- makeAbsolute ("bar" </> "foo") | ||
absPath2 <- makeAbsolute ("bar" </> "nonexistent") | ||
T(expectEq) () (Just absPath) =<< findFile [] absPath | ||
T(expectEq) () Nothing =<< findFile [] absPath2 |