Expand root paths into source paths

This commit is contained in:
Vidar Holen 2019-04-24 18:51:24 -07:00
parent af46758ff1
commit c6c12f52bd
6 changed files with 70 additions and 30 deletions

View file

@ -150,6 +150,11 @@ checkOptionIncludes includes src =
checkWithRc rc = getErrors
(mockRcFile rc $ mockedSystemInterface [])
checkWithIncludesAndSourcePath includes mapper = getErrors
(mockedSystemInterface includes) {
siFindSource = mapper
}
prop_findsParseIssue = check "echo \"$12\"" == [1037]
prop_commentDisablesParseIssue1 =
@ -335,5 +340,24 @@ prop_brokenRcGetsWarning = result == [1134, 2086]
csIgnoreRC = False
}
prop_sourcePathRedirectsName = result == [2086]
where
f "dir/myscript" "lib" = return "foo/lib"
result = checkWithIncludesAndSourcePath [("foo/lib", "echo $1")] f emptyCheckSpec {
csScript = "#!/bin/bash\nsource lib",
csFilename = "dir/myscript",
csCheckSourced = True
}
prop_sourcePathRedirectsDirective = result == [2086]
where
f "dir/myscript" "lib" = return "foo/lib"
f _ _ = return "/dev/null"
result = checkWithIncludesAndSourcePath [("foo/lib", "echo $1")] f emptyCheckSpec {
csScript = "#!/bin/bash\n# shellcheck source=lib\nsource kittens",
csFilename = "dir/myscript",
csCheckSourced = True
}
return []
runTests = $quickCheckAll

View file

@ -73,8 +73,8 @@ import qualified Data.Map as Map
data SystemInterface m = SystemInterface {
-- Read a file by filename, or return an error
siReadFile :: String -> m (Either ErrorMessage String),
-- Find source file in alternate root paths
siFindSource :: String -> m (FilePath),
-- Given the current script and a sourced file, find the sourced file
siFindSource :: String -> String -> m FilePath,
-- Get the configuration file (name, contents) for a filename
siGetConfig :: String -> m (Maybe (FilePath, String))
}
@ -297,7 +297,7 @@ mockedSystemInterface files = SystemInterface {
case filter ((== file) . fst) files of
[] -> return $ Left "File not included in mock."
[(_, contents)] -> return $ Right contents
fs file = return file
fs _ file = return file
mockRcFile rcfile mock = mock {
siGetConfig = const . return $ Just (".shellcheckrc", rcfile)

View file

@ -2088,7 +2088,8 @@ readSource t@(T_Redirecting _ _ (T_SimpleCommand cmdId _ (cmd:file':rest'))) = d
if filename == "/dev/null" -- always allow /dev/null
then return (Right "")
else do
filename' <- system $ siFindSource sys filename
currentScript <- Mr.asks currentFilename
filename' <- system $ siFindSource sys currentScript filename
system $ siReadFile sys filename'
case input of
Left err -> do