lib: add tests and code for nonexistant files and malformed globs
This commit is contained in:
parent
2c4d0c0acd
commit
5077443a84
@ -204,11 +204,17 @@ includedirectivep = do
|
|||||||
void newline
|
void newline
|
||||||
|
|
||||||
where
|
where
|
||||||
getFilePaths curdir fileglob =
|
getFilePaths curdir filename = do
|
||||||
if isLiteral (compile fileglob)
|
-- Compiling filename as a glob pattern works even if it is a literal
|
||||||
-- </> and globDir1 correctly handle case when 'fileglob' is absolute
|
fileglob <- case tryCompileWith compDefault{errorRecovery=False} filename of
|
||||||
then pure [curdir </> fileglob]
|
Right x -> pure x
|
||||||
else liftIO $ globDir1 (compile fileglob) curdir
|
Left e -> fail $ "Invalid glob pattern: " ++ e
|
||||||
|
-- Get all matching files in the current working directory
|
||||||
|
filepaths <- liftIO $ globDir1 fileglob curdir
|
||||||
|
if (not . null) filepaths
|
||||||
|
then pure filepaths
|
||||||
|
else fail $ "No existing files match pattern: " ++ filename
|
||||||
|
|
||||||
parseChild parentpos filepath = do
|
parseChild parentpos filepath = do
|
||||||
childInput <- lift $ readFilePortably filepath
|
childInput <- lift $ readFilePortably filepath
|
||||||
`orRethrowIOError` (show parentpos ++ " reading " ++ filepath)
|
`orRethrowIOError` (show parentpos ++ " reading " ++ filepath)
|
||||||
|
|||||||
@ -48,3 +48,15 @@ include *y.journal
|
|||||||
(B) 1
|
(B) 1
|
||||||
|
|
||||||
>>>=0
|
>>>=0
|
||||||
|
|
||||||
|
# 4. include invalid glob patterns
|
||||||
|
hledger -f - print
|
||||||
|
<<<
|
||||||
|
include [.journal
|
||||||
|
>>>=1
|
||||||
|
|
||||||
|
# 5. include nonexsitant file
|
||||||
|
hledger -f - print
|
||||||
|
<<<
|
||||||
|
include doesnotexist.journal
|
||||||
|
>>>=1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user