{-
    Copyright 2012-2020 Vidar Holen

    This file is part of ShellCheck.
    https://www.shellcheck.net

    ShellCheck is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ShellCheck is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
-}
{-# LANGUAGE TemplateHaskell #-}
module ShellCheck.Checker (checkScript, ShellCheck.Checker.runTests) where

import ShellCheck.Interface
import ShellCheck.Parser
import ShellCheck.Analyzer

import Data.Either
import Data.Functor
import Data.List
import Data.Maybe
import Data.Ord
import Control.Monad.Identity
import qualified Data.Map as Map
import qualified System.IO
import Prelude hiding (readFile)
import Control.Monad

import Test.QuickCheck.All

tokenToPosition :: Map Id (Position, Position) -> TokenComment -> PositionedComment
tokenToPosition Map Id (Position, Position)
startMap TokenComment
t = PositionedComment -> Maybe PositionedComment -> PositionedComment
forall a. a -> Maybe a -> a
fromMaybe PositionedComment
forall a. a
fail (Maybe PositionedComment -> PositionedComment)
-> Maybe PositionedComment -> PositionedComment
forall a b. (a -> b) -> a -> b
$ do
    (Position, Position)
span <- Id -> Map Id (Position, Position) -> Maybe (Position, Position)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (TokenComment -> Id
tcId TokenComment
t) Map Id (Position, Position)
startMap
    PositionedComment -> Maybe PositionedComment
forall (m :: * -> *) a. Monad m => a -> m a
return (PositionedComment -> Maybe PositionedComment)
-> PositionedComment -> Maybe PositionedComment
forall a b. (a -> b) -> a -> b
$ PositionedComment
newPositionedComment {
        pcStartPos :: Position
pcStartPos = (Position, Position) -> Position
forall a b. (a, b) -> a
fst (Position, Position)
span,
        pcEndPos :: Position
pcEndPos = (Position, Position) -> Position
forall a b. (a, b) -> b
snd (Position, Position)
span,
        pcComment :: Comment
pcComment = TokenComment -> Comment
tcComment TokenComment
t,
        pcFix :: Maybe Fix
pcFix = TokenComment -> Maybe Fix
tcFix TokenComment
t
    }
  where
    fail :: a
fail = [Char] -> a
forall a. HasCallStack => [Char] -> a
error [Char]
"Internal shellcheck error: id doesn't exist. Please report!"

shellFromFilename :: [Char] -> Maybe Shell
shellFromFilename [Char]
filename = [Shell] -> Maybe Shell
forall a. [a] -> Maybe a
listToMaybe [Shell]
candidates
  where
    shellExtensions :: [([Char], Shell)]
shellExtensions = [([Char]
".ksh", Shell
Ksh)
                      ,([Char]
".bash", Shell
Bash)
                      ,([Char]
".bats", Shell
Bash)
                      ,([Char]
".dash", Shell
Dash)]
                      -- The `.sh` is too generic to determine the shell:
                      -- We fallback to Bash in this case and emit SC2148 if there is no shebang
    candidates :: [Shell]
candidates =
        [Shell
sh | ([Char]
ext,Shell
sh) <- [([Char], Shell)]
shellExtensions, [Char]
ext [Char] -> [Char] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isSuffixOf` [Char]
filename]

checkScript :: Monad m => SystemInterface m -> CheckSpec -> m CheckResult
checkScript :: SystemInterface m -> CheckSpec -> m CheckResult
checkScript SystemInterface m
sys CheckSpec
spec = do
    [PositionedComment]
results <- [Char] -> m [PositionedComment]
checkScript (CheckSpec -> [Char]
csScript CheckSpec
spec)
    CheckResult -> m CheckResult
forall (m :: * -> *) a. Monad m => a -> m a
return CheckResult
emptyCheckResult {
        crFilename :: [Char]
crFilename = CheckSpec -> [Char]
csFilename CheckSpec
spec,
        crComments :: [PositionedComment]
crComments = [PositionedComment]
results
    }
  where
    checkScript :: [Char] -> m [PositionedComment]
checkScript [Char]
contents = do
        ParseResult
result <- SystemInterface m -> ParseSpec -> m ParseResult
forall (m :: * -> *).
Monad m =>
SystemInterface m -> ParseSpec -> m ParseResult
parseScript SystemInterface m
sys ParseSpec
newParseSpec {
            psFilename :: [Char]
psFilename = CheckSpec -> [Char]
csFilename CheckSpec
spec,
            psScript :: [Char]
psScript = [Char]
contents,
            psCheckSourced :: Bool
psCheckSourced = CheckSpec -> Bool
csCheckSourced CheckSpec
spec,
            psIgnoreRC :: Bool
psIgnoreRC = CheckSpec -> Bool
csIgnoreRC CheckSpec
spec,
            psShellTypeOverride :: Maybe Shell
psShellTypeOverride = CheckSpec -> Maybe Shell
csShellTypeOverride CheckSpec
spec
        }
        let parseMessages :: [PositionedComment]
parseMessages = ParseResult -> [PositionedComment]
prComments ParseResult
result
        let tokenPositions :: Map Id (Position, Position)
tokenPositions = ParseResult -> Map Id (Position, Position)
prTokenPositions ParseResult
result
        let analysisSpec :: Token -> AnalysisSpec
analysisSpec Token
root =
                AnalysisSpec
as {
                    asScript :: Token
asScript = Token
root,
                    asShellType :: Maybe Shell
asShellType = CheckSpec -> Maybe Shell
csShellTypeOverride CheckSpec
spec,
                    asFallbackShell :: Maybe Shell
asFallbackShell = [Char] -> Maybe Shell
shellFromFilename ([Char] -> Maybe Shell) -> [Char] -> Maybe Shell
forall a b. (a -> b) -> a -> b
$ CheckSpec -> [Char]
csFilename CheckSpec
spec,
                    asCheckSourced :: Bool
asCheckSourced = CheckSpec -> Bool
csCheckSourced CheckSpec
spec,
                    asExecutionMode :: ExecutionMode
asExecutionMode = ExecutionMode
Executed,
                    asTokenPositions :: Map Id (Position, Position)
asTokenPositions = Map Id (Position, Position)
tokenPositions,
                    asOptionalChecks :: [[Char]]
asOptionalChecks = CheckSpec -> [[Char]]
csOptionalChecks CheckSpec
spec
                } where as :: AnalysisSpec
as = Token -> AnalysisSpec
newAnalysisSpec Token
root
        let analysisMessages :: [TokenComment]
analysisMessages =
                [TokenComment]
-> (Token -> [TokenComment]) -> Maybe Token -> [TokenComment]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe []
                    (AnalysisResult -> [TokenComment]
arComments (AnalysisResult -> [TokenComment])
-> (Token -> AnalysisResult) -> Token -> [TokenComment]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnalysisSpec -> AnalysisResult
analyzeScript (AnalysisSpec -> AnalysisResult)
-> (Token -> AnalysisSpec) -> Token -> AnalysisResult
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Token -> AnalysisSpec
analysisSpec)
                        (Maybe Token -> [TokenComment]) -> Maybe Token -> [TokenComment]
forall a b. (a -> b) -> a -> b
$ ParseResult -> Maybe Token
prRoot ParseResult
result
        let translator :: TokenComment -> PositionedComment
translator = Map Id (Position, Position) -> TokenComment -> PositionedComment
tokenToPosition Map Id (Position, Position)
tokenPositions
        [PositionedComment] -> m [PositionedComment]
forall (m :: * -> *) a. Monad m => a -> m a
return ([PositionedComment] -> m [PositionedComment])
-> ([PositionedComment] -> [PositionedComment])
-> [PositionedComment]
-> m [PositionedComment]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PositionedComment] -> [PositionedComment]
forall a. Eq a => [a] -> [a]
nub ([PositionedComment] -> [PositionedComment])
-> ([PositionedComment] -> [PositionedComment])
-> [PositionedComment]
-> [PositionedComment]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PositionedComment] -> [PositionedComment]
sortMessages ([PositionedComment] -> [PositionedComment])
-> ([PositionedComment] -> [PositionedComment])
-> [PositionedComment]
-> [PositionedComment]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PositionedComment -> Bool)
-> [PositionedComment] -> [PositionedComment]
forall a. (a -> Bool) -> [a] -> [a]
filter PositionedComment -> Bool
shouldInclude ([PositionedComment] -> m [PositionedComment])
-> [PositionedComment] -> m [PositionedComment]
forall a b. (a -> b) -> a -> b
$
            ([PositionedComment]
parseMessages [PositionedComment] -> [PositionedComment] -> [PositionedComment]
forall a. [a] -> [a] -> [a]
++ (TokenComment -> PositionedComment)
-> [TokenComment] -> [PositionedComment]
forall a b. (a -> b) -> [a] -> [b]
map TokenComment -> PositionedComment
translator [TokenComment]
analysisMessages)

    shouldInclude :: PositionedComment -> Bool
shouldInclude PositionedComment
pc =
            Severity
severity Severity -> Severity -> Bool
forall a. Ord a => a -> a -> Bool
<= CheckSpec -> Severity
csMinSeverity CheckSpec
spec Bool -> Bool -> Bool
&&
            case CheckSpec -> Maybe [Integer]
csIncludedWarnings CheckSpec
spec of
                Maybe [Integer]
Nothing -> Integer
code Integer -> [Integer] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` CheckSpec -> [Integer]
csExcludedWarnings CheckSpec
spec
                Just [Integer]
includedWarnings -> Integer
code Integer -> [Integer] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Integer]
includedWarnings
        where
            code :: Integer
code     = Comment -> Integer
cCode (PositionedComment -> Comment
pcComment PositionedComment
pc)
            severity :: Severity
severity = Comment -> Severity
cSeverity (PositionedComment -> Comment
pcComment PositionedComment
pc)

    sortMessages :: [PositionedComment] -> [PositionedComment]
sortMessages = (PositionedComment
 -> ([Char], Integer, Integer, Severity, Integer, [Char]))
-> [PositionedComment] -> [PositionedComment]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn PositionedComment
-> ([Char], Integer, Integer, Severity, Integer, [Char])
order
    order :: PositionedComment
-> ([Char], Integer, Integer, Severity, Integer, [Char])
order PositionedComment
pc =
        let pos :: Position
pos = PositionedComment -> Position
pcStartPos PositionedComment
pc
            comment :: Comment
comment = PositionedComment -> Comment
pcComment PositionedComment
pc in
        (Position -> [Char]
posFile Position
pos,
         Position -> Integer
posLine Position
pos,
         Position -> Integer
posColumn Position
pos,
         Comment -> Severity
cSeverity Comment
comment,
         Comment -> Integer
cCode Comment
comment,
         Comment -> [Char]
cMessage Comment
comment)
    getPosition :: PositionedComment -> Position
getPosition = PositionedComment -> Position
pcStartPos


getErrors :: SystemInterface Identity -> CheckSpec -> [Integer]
getErrors SystemInterface Identity
sys CheckSpec
spec =
    [Integer] -> [Integer]
forall a. Ord a => [a] -> [a]
sort ([Integer] -> [Integer])
-> (CheckResult -> [Integer]) -> CheckResult -> [Integer]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PositionedComment -> Integer) -> [PositionedComment] -> [Integer]
forall a b. (a -> b) -> [a] -> [b]
map PositionedComment -> Integer
getCode ([PositionedComment] -> [Integer])
-> (CheckResult -> [PositionedComment]) -> CheckResult -> [Integer]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CheckResult -> [PositionedComment]
crComments (CheckResult -> [Integer]) -> CheckResult -> [Integer]
forall a b. (a -> b) -> a -> b
$
        Identity CheckResult -> CheckResult
forall a. Identity a -> a
runIdentity (SystemInterface Identity -> CheckSpec -> Identity CheckResult
forall (m :: * -> *).
Monad m =>
SystemInterface m -> CheckSpec -> m CheckResult
checkScript SystemInterface Identity
sys CheckSpec
spec)
  where
    getCode :: PositionedComment -> Integer
getCode = Comment -> Integer
cCode (Comment -> Integer)
-> (PositionedComment -> Comment) -> PositionedComment -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PositionedComment -> Comment
pcComment

check :: [Char] -> [Integer]
check = [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes []

checkWithSpec :: [([Char], [Char])] -> CheckSpec -> [Integer]
checkWithSpec [([Char], [Char])]
includes =
    SystemInterface Identity -> CheckSpec -> [Integer]
getErrors ([([Char], [Char])] -> SystemInterface Identity
mockedSystemInterface [([Char], [Char])]
includes)

checkWithIncludes :: [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes [([Char], [Char])]
includes [Char]
src =
    [([Char], [Char])] -> CheckSpec -> [Integer]
checkWithSpec [([Char], [Char])]
includes CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
src,
        csExcludedWarnings :: [Integer]
csExcludedWarnings = [Integer
2148]
    }

checkRecursive :: [([Char], [Char])] -> [Char] -> [Integer]
checkRecursive [([Char], [Char])]
includes [Char]
src =
    [([Char], [Char])] -> CheckSpec -> [Integer]
checkWithSpec [([Char], [Char])]
includes CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
src,
        csExcludedWarnings :: [Integer]
csExcludedWarnings = [Integer
2148],
        csCheckSourced :: Bool
csCheckSourced = Bool
True
    }

checkOptionIncludes :: Maybe [Integer] -> [Char] -> [Integer]
checkOptionIncludes Maybe [Integer]
includes [Char]
src =
    [([Char], [Char])] -> CheckSpec -> [Integer]
checkWithSpec [] CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
src,
        csIncludedWarnings :: Maybe [Integer]
csIncludedWarnings = Maybe [Integer]
includes,
        csCheckSourced :: Bool
csCheckSourced = Bool
True
    }

checkWithRc :: [Char] -> CheckSpec -> [Integer]
checkWithRc [Char]
rc = SystemInterface Identity -> CheckSpec -> [Integer]
getErrors
    ([Char] -> SystemInterface Identity -> SystemInterface Identity
forall (m :: * -> *).
Monad m =>
[Char] -> SystemInterface m -> SystemInterface m
mockRcFile [Char]
rc (SystemInterface Identity -> SystemInterface Identity)
-> SystemInterface Identity -> SystemInterface Identity
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])] -> SystemInterface Identity
mockedSystemInterface [])

checkWithIncludesAndSourcePath :: [([Char], [Char])]
-> ([Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char])
-> CheckSpec
-> [Integer]
checkWithIncludesAndSourcePath [([Char], [Char])]
includes [Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char]
mapper = SystemInterface Identity -> CheckSpec -> [Integer]
getErrors
    ([([Char], [Char])] -> SystemInterface Identity
mockedSystemInterface [([Char], [Char])]
includes) {
        siFindSource :: [Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char]
siFindSource = [Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char]
mapper
    }

checkWithRcIncludesAndSourcePath :: [Char]
-> [([Char], [Char])]
-> ([Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char])
-> CheckSpec
-> [Integer]
checkWithRcIncludesAndSourcePath [Char]
rc [([Char], [Char])]
includes [Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char]
mapper = SystemInterface Identity -> CheckSpec -> [Integer]
getErrors
    ([Char] -> SystemInterface Identity -> SystemInterface Identity
forall (m :: * -> *).
Monad m =>
[Char] -> SystemInterface m -> SystemInterface m
mockRcFile [Char]
rc (SystemInterface Identity -> SystemInterface Identity)
-> SystemInterface Identity -> SystemInterface Identity
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])] -> SystemInterface Identity
mockedSystemInterface [([Char], [Char])]
includes) {
        siFindSource :: [Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char]
siFindSource = [Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char]
mapper
    }

prop_findsParseIssue :: Bool
prop_findsParseIssue = [Char] -> [Integer]
check [Char]
"echo \"$12\"" [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
1037]

prop_commentDisablesParseIssue1 :: Bool
prop_commentDisablesParseIssue1 =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> [Integer]
check [Char]
"#shellcheck disable=SC1037\necho \"$12\""
prop_commentDisablesParseIssue2 :: Bool
prop_commentDisablesParseIssue2 =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> [Integer]
check [Char]
"#shellcheck disable=SC1037\n#lol\necho \"$12\""

prop_findsAnalysisIssue :: Bool
prop_findsAnalysisIssue =
    [Char] -> [Integer]
check [Char]
"echo $1" [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2086]
prop_commentDisablesAnalysisIssue1 :: Bool
prop_commentDisablesAnalysisIssue1 =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> [Integer]
check [Char]
"#shellcheck disable=SC2086\necho $1"
prop_commentDisablesAnalysisIssue2 :: Bool
prop_commentDisablesAnalysisIssue2 =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> [Integer]
check [Char]
"#shellcheck disable=SC2086\n#lol\necho $1"

prop_optionDisablesIssue1 :: Bool
prop_optionDisablesIssue1 =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ SystemInterface Identity -> CheckSpec -> [Integer]
getErrors
                ([([Char], [Char])] -> SystemInterface Identity
mockedSystemInterface [])
                CheckSpec
emptyCheckSpec {
                    csScript :: [Char]
csScript = [Char]
"echo $1",
                    csExcludedWarnings :: [Integer]
csExcludedWarnings = [Integer
2148, Integer
2086]
                }

prop_optionDisablesIssue2 :: Bool
prop_optionDisablesIssue2 =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ SystemInterface Identity -> CheckSpec -> [Integer]
getErrors
                ([([Char], [Char])] -> SystemInterface Identity
mockedSystemInterface [])
                CheckSpec
emptyCheckSpec {
                    csScript :: [Char]
csScript = [Char]
"echo \"$10\"",
                    csExcludedWarnings :: [Integer]
csExcludedWarnings = [Integer
2148, Integer
1037]
                }

prop_wontParseBadShell :: Bool
prop_wontParseBadShell =
    [Integer
1071] [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char] -> [Integer]
check [Char]
"#!/usr/bin/python\ntrue $1\n"

prop_optionDisablesBadShebang :: Bool
prop_optionDisablesBadShebang =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ SystemInterface Identity -> CheckSpec -> [Integer]
getErrors
                ([([Char], [Char])] -> SystemInterface Identity
mockedSystemInterface [])
                CheckSpec
emptyCheckSpec {
                    csScript :: [Char]
csScript = [Char]
"#!/usr/bin/python\ntrue\n",
                    csShellTypeOverride :: Maybe Shell
csShellTypeOverride = Shell -> Maybe Shell
forall a. a -> Maybe a
Just Shell
Sh
                }

prop_annotationDisablesBadShebang :: Bool
prop_annotationDisablesBadShebang =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> [Integer]
check [Char]
"#!/usr/bin/python\n# shellcheck shell=sh\ntrue\n"


prop_canParseDevNull :: Bool
prop_canParseDevNull =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> [Integer]
check [Char]
"source /dev/null"

prop_failsWhenNotSourcing :: Bool
prop_failsWhenNotSourcing =
    [Integer
1091, Integer
2154] [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char] -> [Integer]
check [Char]
"source lol; echo \"$bar\""

prop_worksWhenSourcing :: Bool
prop_worksWhenSourcing =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes [([Char]
"lib", [Char]
"bar=1")] [Char]
"source lib; echo \"$bar\""

prop_worksWhenSourcingWithDashDash :: Bool
prop_worksWhenSourcingWithDashDash =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes [([Char]
"lib", [Char]
"bar=1")] [Char]
"source -- lib; echo \"$bar\""

prop_worksWhenDotting :: Bool
prop_worksWhenDotting =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes [([Char]
"lib", [Char]
"bar=1")] [Char]
". lib; echo \"$bar\""

-- FIXME: This should really be giving [1093], "recursively sourced"
prop_noInfiniteSourcing :: Bool
prop_noInfiniteSourcing =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes  [([Char]
"lib", [Char]
"source lib")] [Char]
"source lib"

prop_canSourceBadSyntax :: Bool
prop_canSourceBadSyntax =
    [Integer
1094, Integer
2086] [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes [([Char]
"lib", [Char]
"for f; do")] [Char]
"source lib; echo $1"

prop_cantSourceDynamic :: Bool
prop_cantSourceDynamic =
    [Integer
1090] [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes [([Char]
"lib", [Char]
"")] [Char]
". \"$1\""

prop_cantSourceDynamic2 :: Bool
prop_cantSourceDynamic2 =
    [Integer
1090] [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes [([Char]
"lib", [Char]
"")] [Char]
"source ~/foo"

prop_canStripPrefixAndSource :: Bool
prop_canStripPrefixAndSource =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes [([Char]
"./lib", [Char]
"")] [Char]
"source \"$MYDIR/lib\""

prop_canStripPrefixAndSource2 :: Bool
prop_canStripPrefixAndSource2 =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes [([Char]
"./utils.sh", [Char]
"")] [Char]
"source \"$(dirname \"${BASH_SOURCE[0]}\")/utils.sh\""

prop_canSourceDynamicWhenRedirected :: Bool
prop_canSourceDynamicWhenRedirected =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes [([Char]
"lib", [Char]
"")] [Char]
"#shellcheck source=lib\n. \"$1\""

prop_recursiveAnalysis :: Bool
prop_recursiveAnalysis =
    [Integer
2086] [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [([Char], [Char])] -> [Char] -> [Integer]
checkRecursive [([Char]
"lib", [Char]
"echo $1")] [Char]
"source lib"

prop_recursiveParsing :: Bool
prop_recursiveParsing =
    [Integer
1037] [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [([Char], [Char])] -> [Char] -> [Integer]
checkRecursive [([Char]
"lib", [Char]
"echo \"$10\"")] [Char]
"source lib"

prop_nonRecursiveAnalysis :: Bool
prop_nonRecursiveAnalysis =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes [([Char]
"lib", [Char]
"echo $1")] [Char]
"source lib"

prop_nonRecursiveParsing :: Bool
prop_nonRecursiveParsing =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes [([Char]
"lib", [Char]
"echo \"$10\"")] [Char]
"source lib"

prop_sourceDirectiveDoesntFollowFile :: Bool
prop_sourceDirectiveDoesntFollowFile =
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes
                [([Char]
"foo", [Char]
"source bar"), ([Char]
"bar", [Char]
"baz=3")]
                [Char]
"#shellcheck source=foo\n. \"$1\"; echo \"$baz\""

prop_filewideAnnotationBase :: Bool
prop_filewideAnnotationBase = [Integer
2086] [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char] -> [Integer]
check [Char]
"#!/bin/sh\necho $1"
prop_filewideAnnotation1 :: Bool
prop_filewideAnnotation1 = [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$
    [Char] -> [Integer]
check [Char]
"#!/bin/sh\n# shellcheck disable=2086\necho $1"
prop_filewideAnnotation2 :: Bool
prop_filewideAnnotation2 = [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$
    [Char] -> [Integer]
check [Char]
"#!/bin/sh\n# shellcheck disable=2086\ntrue\necho $1"
prop_filewideAnnotation3 :: Bool
prop_filewideAnnotation3 = [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$
    [Char] -> [Integer]
check [Char]
"#!/bin/sh\n#unrelated\n# shellcheck disable=2086\ntrue\necho $1"
prop_filewideAnnotation4 :: Bool
prop_filewideAnnotation4 = [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$
    [Char] -> [Integer]
check [Char]
"#!/bin/sh\n# shellcheck disable=2086\n#unrelated\ntrue\necho $1"
prop_filewideAnnotation5 :: Bool
prop_filewideAnnotation5 = [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$
    [Char] -> [Integer]
check [Char]
"#!/bin/sh\n\n\n\n#shellcheck disable=2086\ntrue\necho $1"
prop_filewideAnnotation6 :: Bool
prop_filewideAnnotation6 = [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$
    [Char] -> [Integer]
check [Char]
"#shellcheck shell=sh\n#unrelated\n#shellcheck disable=2086\ntrue\necho $1"
prop_filewideAnnotation7 :: Bool
prop_filewideAnnotation7 = [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$
    [Char] -> [Integer]
check [Char]
"#!/bin/sh\n# shellcheck disable=2086\n#unrelated\ntrue\necho $1"

prop_filewideAnnotationBase2 :: Bool
prop_filewideAnnotationBase2 = [Integer
2086, Integer
2181] [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char] -> [Integer]
check [Char]
"true\n[ $? == 0 ] && echo $1"
prop_filewideAnnotation8 :: Bool
prop_filewideAnnotation8 = [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$
    [Char] -> [Integer]
check [Char]
"# Disable $? warning\n#shellcheck disable=SC2181\n# Disable quoting warning\n#shellcheck disable=2086\ntrue\n[ $? == 0 ] && echo $1"

prop_sourcePartOfOriginalScript :: Bool
prop_sourcePartOfOriginalScript = -- #1181: -x disabled posix warning for 'source'
    Integer
3046 Integer -> [Integer] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [([Char], [Char])] -> [Char] -> [Integer]
checkWithIncludes [([Char]
"./saywhat.sh", [Char]
"echo foo")] [Char]
"#!/bin/sh\nsource ./saywhat.sh"

prop_spinBug1413 :: Bool
prop_spinBug1413 = [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> [Integer]
check [Char]
"fun() {\n# shellcheck disable=SC2188\n> /dev/null\n}\n"

prop_deducesTypeFromExtension :: Bool
prop_deducesTypeFromExtension = [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Integer]
result
  where
    result :: [Integer]
result = [([Char], [Char])] -> CheckSpec -> [Integer]
checkWithSpec [] CheckSpec
emptyCheckSpec {
        csFilename :: [Char]
csFilename = [Char]
"file.ksh",
        csScript :: [Char]
csScript = [Char]
"(( 3.14 ))"
    }

prop_deducesTypeFromExtension2 :: Bool
prop_deducesTypeFromExtension2 = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2079]
  where
    result :: [Integer]
result = [([Char], [Char])] -> CheckSpec -> [Integer]
checkWithSpec [] CheckSpec
emptyCheckSpec {
        csFilename :: [Char]
csFilename = [Char]
"file.bash",
        csScript :: [Char]
csScript = [Char]
"(( 3.14 ))"
    }

prop_canDisableShebangWarning :: Bool
prop_canDisableShebangWarning = [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [Integer]
result
  where
    result :: [Integer]
result = [([Char], [Char])] -> CheckSpec -> [Integer]
checkWithSpec [] CheckSpec
emptyCheckSpec {
        csFilename :: [Char]
csFilename = [Char]
"file.sh",
        csScript :: [Char]
csScript = [Char]
"#shellcheck disable=SC2148\nfoo"
    }

prop_canDisableAllWarnings :: Bool
prop_canDisableAllWarnings = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2086]
  where
    result :: [Integer]
result = [([Char], [Char])] -> CheckSpec -> [Integer]
checkWithSpec [] CheckSpec
emptyCheckSpec {
        csFilename :: [Char]
csFilename = [Char]
"file.sh",
        csScript :: [Char]
csScript = [Char]
"#!/bin/sh\necho $1\n#shellcheck disable=all\necho `echo $1`"
    }

prop_canDisableParseErrors :: Bool
prop_canDisableParseErrors = [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ [Integer]
result
  where
    result :: [Integer]
result = [([Char], [Char])] -> CheckSpec -> [Integer]
checkWithSpec [] CheckSpec
emptyCheckSpec {
        csFilename :: [Char]
csFilename = [Char]
"file.sh",
        csScript :: [Char]
csScript = [Char]
"#shellcheck disable=SC1073,SC1072,SC2148\n()"
    }

prop_shExtensionDoesntMatter :: Bool
prop_shExtensionDoesntMatter = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2148]
  where
    result :: [Integer]
result = [([Char], [Char])] -> CheckSpec -> [Integer]
checkWithSpec [] CheckSpec
emptyCheckSpec {
        csFilename :: [Char]
csFilename = [Char]
"file.sh",
        csScript :: [Char]
csScript = [Char]
"echo 'hello world'"
    }

prop_sourcedFileUsesOriginalShellExtension :: Bool
prop_sourcedFileUsesOriginalShellExtension = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2079]
  where
    result :: [Integer]
result = [([Char], [Char])] -> CheckSpec -> [Integer]
checkWithSpec [([Char]
"file.ksh", [Char]
"(( 3.14 ))")] CheckSpec
emptyCheckSpec {
        csFilename :: [Char]
csFilename = [Char]
"file.bash",
        csScript :: [Char]
csScript = [Char]
"source file.ksh",
        csCheckSourced :: Bool
csCheckSourced = Bool
True
    }

prop_canEnableOptionalsWithSpec :: Bool
prop_canEnableOptionalsWithSpec = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2244]
  where
    result :: [Integer]
result = [([Char], [Char])] -> CheckSpec -> [Integer]
checkWithSpec [] CheckSpec
emptyCheckSpec {
        csFilename :: [Char]
csFilename = [Char]
"file.sh",
        csScript :: [Char]
csScript = [Char]
"#!/bin/sh\n[ \"$1\" ]",
        csOptionalChecks :: [[Char]]
csOptionalChecks = [[Char]
"avoid-nullary-conditions"]
    }

prop_optionIncludes1 :: Bool
prop_optionIncludes1 =
    -- expect 2086, but not included, so nothing reported
    [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Integer] -> Bool) -> [Integer] -> Bool
forall a b. (a -> b) -> a -> b
$ Maybe [Integer] -> [Char] -> [Integer]
checkOptionIncludes ([Integer] -> Maybe [Integer]
forall a. a -> Maybe a
Just [Integer
2080]) [Char]
"#!/bin/sh\n var='a b'\n echo $var"

prop_optionIncludes2 :: Bool
prop_optionIncludes2 =
    -- expect 2086, included, so it is reported
    [Integer
2086] [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe [Integer] -> [Char] -> [Integer]
checkOptionIncludes ([Integer] -> Maybe [Integer]
forall a. a -> Maybe a
Just [Integer
2086]) [Char]
"#!/bin/sh\n var='a b'\n echo $var"

prop_optionIncludes3 :: Bool
prop_optionIncludes3 =
    -- expect 2086, no inclusions provided, so it is reported
    [Integer
2086] [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe [Integer] -> [Char] -> [Integer]
checkOptionIncludes Maybe [Integer]
forall a. Maybe a
Nothing [Char]
"#!/bin/sh\n var='a b'\n echo $var"

prop_optionIncludes4 :: Bool
prop_optionIncludes4 =
    -- expect 2086 & 2154, only 2154 included, so only that's reported
    [Integer
2154] [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe [Integer] -> [Char] -> [Integer]
checkOptionIncludes ([Integer] -> Maybe [Integer]
forall a. a -> Maybe a
Just [Integer
2154]) [Char]
"#!/bin/sh\n var='a b'\n echo $var\n echo $bar"


prop_readsRcFile :: Bool
prop_readsRcFile = [Integer] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Integer]
result
  where
    result :: [Integer]
result = [Char] -> CheckSpec -> [Integer]
checkWithRc [Char]
"disable=2086" CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
"#!/bin/sh\necho $1",
        csIgnoreRC :: Bool
csIgnoreRC = Bool
False
    }

prop_canUseNoRC :: Bool
prop_canUseNoRC = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2086]
  where
    result :: [Integer]
result = [Char] -> CheckSpec -> [Integer]
checkWithRc [Char]
"disable=2086" CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
"#!/bin/sh\necho $1",
        csIgnoreRC :: Bool
csIgnoreRC = Bool
True
    }

prop_NoRCWontLookAtFile :: Bool
prop_NoRCWontLookAtFile = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2086]
  where
    result :: [Integer]
result = [Char] -> CheckSpec -> [Integer]
checkWithRc ([Char] -> [Char]
forall a. HasCallStack => [Char] -> a
error [Char]
"Fail") CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
"#!/bin/sh\necho $1",
        csIgnoreRC :: Bool
csIgnoreRC = Bool
True
    }

prop_brokenRcGetsWarning :: Bool
prop_brokenRcGetsWarning = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
1134, Integer
2086]
  where
    result :: [Integer]
result = [Char] -> CheckSpec -> [Integer]
checkWithRc [Char]
"rofl" CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
"#!/bin/sh\necho $1",
        csIgnoreRC :: Bool
csIgnoreRC = Bool
False
    }

prop_canEnableOptionalsWithRc :: Bool
prop_canEnableOptionalsWithRc = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2244]
  where
    result :: [Integer]
result = [Char] -> CheckSpec -> [Integer]
checkWithRc [Char]
"enable=avoid-nullary-conditions" CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
"#!/bin/sh\n[ \"$1\" ]"
    }

prop_sourcePathRedirectsName :: Bool
prop_sourcePathRedirectsName = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2086]
  where
    f :: [Char] -> p -> p -> [Char] -> m [Char]
f [Char]
"dir/myscript" p
_ p
_ [Char]
"lib" = [Char] -> m [Char]
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
"foo/lib"
    result :: [Integer]
result = [([Char], [Char])]
-> ([Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char])
-> CheckSpec
-> [Integer]
checkWithIncludesAndSourcePath [([Char]
"foo/lib", [Char]
"echo $1")] [Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char]
forall (m :: * -> *) p p.
Monad m =>
[Char] -> p -> p -> [Char] -> m [Char]
f CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
"#!/bin/bash\nsource lib",
        csFilename :: [Char]
csFilename = [Char]
"dir/myscript",
        csCheckSourced :: Bool
csCheckSourced = Bool
True
    }

prop_sourcePathAddsAnnotation :: Bool
prop_sourcePathAddsAnnotation = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2086]
  where
    f :: [Char] -> p -> [[Char]] -> [Char] -> m [Char]
f [Char]
"dir/myscript" p
_ [[Char]
"mypath"] [Char]
"lib" = [Char] -> m [Char]
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
"foo/lib"
    result :: [Integer]
result = [([Char], [Char])]
-> ([Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char])
-> CheckSpec
-> [Integer]
checkWithIncludesAndSourcePath [([Char]
"foo/lib", [Char]
"echo $1")] [Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char]
forall (m :: * -> *) p.
Monad m =>
[Char] -> p -> [[Char]] -> [Char] -> m [Char]
f CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
"#!/bin/bash\n# shellcheck source-path=mypath\nsource lib",
        csFilename :: [Char]
csFilename = [Char]
"dir/myscript",
        csCheckSourced :: Bool
csCheckSourced = Bool
True
    }

prop_sourcePathRedirectsDirective :: Bool
prop_sourcePathRedirectsDirective = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2086]
  where
    f :: [Char] -> p -> p -> [Char] -> m [Char]
f [Char]
"dir/myscript" p
_ p
_ [Char]
"lib" = [Char] -> m [Char]
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
"foo/lib"
    f [Char]
_ p
_ p
_ [Char]
_ = [Char] -> m [Char]
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
"/dev/null"
    result :: [Integer]
result = [([Char], [Char])]
-> ([Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char])
-> CheckSpec
-> [Integer]
checkWithIncludesAndSourcePath [([Char]
"foo/lib", [Char]
"echo $1")] [Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char]
forall (m :: * -> *) p p.
Monad m =>
[Char] -> p -> p -> [Char] -> m [Char]
f CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
"#!/bin/bash\n# shellcheck source=lib\nsource kittens",
        csFilename :: [Char]
csFilename = [Char]
"dir/myscript",
        csCheckSourced :: Bool
csCheckSourced = Bool
True
    }

prop_rcCanAllowExternalSources :: Bool
prop_rcCanAllowExternalSources = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2086]
  where
    f :: [Char] -> Maybe Bool -> d -> [Char] -> m [Char]
f [Char]
"dir/myscript" (Just Bool
True) d
_ [Char]
"mylib" = [Char] -> m [Char]
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
"resolved/mylib"
    f [Char]
a Maybe Bool
b d
c [Char]
d = [Char] -> m [Char]
forall a. HasCallStack => [Char] -> a
error ([Char] -> m [Char]) -> [Char] -> m [Char]
forall a b. (a -> b) -> a -> b
$ ([Char], [Char], Maybe Bool, d, [Char]) -> [Char]
forall a. Show a => a -> [Char]
show ([Char]
"Unexpected", [Char]
a, Maybe Bool
b, d
c, [Char]
d)
    result :: [Integer]
result = [Char]
-> [([Char], [Char])]
-> ([Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char])
-> CheckSpec
-> [Integer]
checkWithRcIncludesAndSourcePath [Char]
"external-sources=true" [([Char]
"resolved/mylib", [Char]
"echo $1")] [Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char]
forall (m :: * -> *) d.
(Monad m, Show d) =>
[Char] -> Maybe Bool -> d -> [Char] -> m [Char]
f CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
"#!/bin/bash\nsource mylib",
        csFilename :: [Char]
csFilename = [Char]
"dir/myscript",
        csCheckSourced :: Bool
csCheckSourced = Bool
True
    }

prop_rcCanDenyExternalSources :: Bool
prop_rcCanDenyExternalSources = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2086]
  where
    f :: [Char] -> Maybe Bool -> d -> [Char] -> m [Char]
f [Char]
"dir/myscript" (Just Bool
False) d
_ [Char]
"mylib" = [Char] -> m [Char]
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
"resolved/mylib"
    f [Char]
a Maybe Bool
b d
c [Char]
d = [Char] -> m [Char]
forall a. HasCallStack => [Char] -> a
error ([Char] -> m [Char]) -> [Char] -> m [Char]
forall a b. (a -> b) -> a -> b
$ ([Char], [Char], Maybe Bool, d, [Char]) -> [Char]
forall a. Show a => a -> [Char]
show ([Char]
"Unexpected", [Char]
a, Maybe Bool
b, d
c, [Char]
d)
    result :: [Integer]
result = [Char]
-> [([Char], [Char])]
-> ([Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char])
-> CheckSpec
-> [Integer]
checkWithRcIncludesAndSourcePath [Char]
"external-sources=false" [([Char]
"resolved/mylib", [Char]
"echo $1")] [Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char]
forall (m :: * -> *) d.
(Monad m, Show d) =>
[Char] -> Maybe Bool -> d -> [Char] -> m [Char]
f CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
"#!/bin/bash\nsource mylib",
        csFilename :: [Char]
csFilename = [Char]
"dir/myscript",
        csCheckSourced :: Bool
csCheckSourced = Bool
True
    }

prop_rcCanLeaveExternalSourcesUnspecified :: Bool
prop_rcCanLeaveExternalSourcesUnspecified = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2086]
  where
    f :: [Char] -> Maybe a -> d -> [Char] -> m [Char]
f [Char]
"dir/myscript" Maybe a
Nothing d
_ [Char]
"mylib" = [Char] -> m [Char]
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
"resolved/mylib"
    f [Char]
a Maybe a
b d
c [Char]
d = [Char] -> m [Char]
forall a. HasCallStack => [Char] -> a
error ([Char] -> m [Char]) -> [Char] -> m [Char]
forall a b. (a -> b) -> a -> b
$ ([Char], [Char], Maybe a, d, [Char]) -> [Char]
forall a. Show a => a -> [Char]
show ([Char]
"Unexpected", [Char]
a, Maybe a
b, d
c, [Char]
d)
    result :: [Integer]
result = [Char]
-> [([Char], [Char])]
-> ([Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char])
-> CheckSpec
-> [Integer]
checkWithRcIncludesAndSourcePath [Char]
"" [([Char]
"resolved/mylib", [Char]
"echo $1")] [Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char]
forall (m :: * -> *) a d.
(Monad m, Show a, Show d) =>
[Char] -> Maybe a -> d -> [Char] -> m [Char]
f CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
"#!/bin/bash\nsource mylib",
        csFilename :: [Char]
csFilename = [Char]
"dir/myscript",
        csCheckSourced :: Bool
csCheckSourced = Bool
True
    }

prop_fileCanDisableExternalSources :: Bool
prop_fileCanDisableExternalSources = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
2006, Integer
2086]
  where
    f :: [Char] -> Maybe Bool -> d -> [Char] -> m [Char]
f [Char]
"dir/myscript" (Just Bool
True) d
_ [Char]
"withExternal" = [Char] -> m [Char]
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
"withExternal"
    f [Char]
"dir/myscript" (Just Bool
False) d
_ [Char]
"withoutExternal" = [Char] -> m [Char]
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
"withoutExternal"
    f [Char]
a Maybe Bool
b d
c [Char]
d = [Char] -> m [Char]
forall a. HasCallStack => [Char] -> a
error ([Char] -> m [Char]) -> [Char] -> m [Char]
forall a b. (a -> b) -> a -> b
$ ([Char], [Char], Maybe Bool, d, [Char]) -> [Char]
forall a. Show a => a -> [Char]
show ([Char]
"Unexpected", [Char]
a, Maybe Bool
b, d
c, [Char]
d)
    result :: [Integer]
result = [Char]
-> [([Char], [Char])]
-> ([Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char])
-> CheckSpec
-> [Integer]
checkWithRcIncludesAndSourcePath [Char]
"external-sources=true" [([Char]
"withExternal", [Char]
"echo $1"), ([Char]
"withoutExternal", [Char]
"_=`foo`")] [Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char]
forall (m :: * -> *) d.
(Monad m, Show d) =>
[Char] -> Maybe Bool -> d -> [Char] -> m [Char]
f CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
"#!/bin/bash\ntrue\nsource withExternal\n# shellcheck external-sources=false\nsource withoutExternal",
        csFilename :: [Char]
csFilename = [Char]
"dir/myscript",
        csCheckSourced :: Bool
csCheckSourced = Bool
True
    }

prop_fileCannotEnableExternalSources :: Bool
prop_fileCannotEnableExternalSources = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
1144]
  where
    f :: [Char] -> Maybe a -> d -> [Char] -> m [Char]
f [Char]
"dir/myscript" Maybe a
Nothing d
_ [Char]
"foo" = [Char] -> m [Char]
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
"foo"
    f [Char]
a Maybe a
b d
c [Char]
d = [Char] -> m [Char]
forall a. HasCallStack => [Char] -> a
error ([Char] -> m [Char]) -> [Char] -> m [Char]
forall a b. (a -> b) -> a -> b
$ ([Char], [Char], Maybe a, d, [Char]) -> [Char]
forall a. Show a => a -> [Char]
show ([Char]
"Unexpected", [Char]
a, Maybe a
b, d
c, [Char]
d)
    result :: [Integer]
result = [Char]
-> [([Char], [Char])]
-> ([Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char])
-> CheckSpec
-> [Integer]
checkWithRcIncludesAndSourcePath [Char]
"" [([Char]
"foo", [Char]
"true")] [Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char]
forall (m :: * -> *) a d.
(Monad m, Show a, Show d) =>
[Char] -> Maybe a -> d -> [Char] -> m [Char]
f CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
"#!/bin/bash\n# shellcheck external-sources=true\nsource foo",
        csFilename :: [Char]
csFilename = [Char]
"dir/myscript",
        csCheckSourced :: Bool
csCheckSourced = Bool
True
    }

prop_fileCannotEnableExternalSources2 :: Bool
prop_fileCannotEnableExternalSources2 = [Integer]
result [Integer] -> [Integer] -> Bool
forall a. Eq a => a -> a -> Bool
== [Integer
1144]
  where
    f :: [Char] -> Maybe Bool -> d -> [Char] -> m [Char]
f [Char]
"dir/myscript" (Just Bool
False) d
_ [Char]
"foo" = [Char] -> m [Char]
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
"foo"
    f [Char]
a Maybe Bool
b d
c [Char]
d = [Char] -> m [Char]
forall a. HasCallStack => [Char] -> a
error ([Char] -> m [Char]) -> [Char] -> m [Char]
forall a b. (a -> b) -> a -> b
$ ([Char], [Char], Maybe Bool, d, [Char]) -> [Char]
forall a. Show a => a -> [Char]
show ([Char]
"Unexpected", [Char]
a, Maybe Bool
b, d
c, [Char]
d)
    result :: [Integer]
result = [Char]
-> [([Char], [Char])]
-> ([Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char])
-> CheckSpec
-> [Integer]
checkWithRcIncludesAndSourcePath [Char]
"external-sources=false" [([Char]
"foo", [Char]
"true")] [Char] -> Maybe Bool -> [[Char]] -> [Char] -> Identity [Char]
forall (m :: * -> *) d.
(Monad m, Show d) =>
[Char] -> Maybe Bool -> d -> [Char] -> m [Char]
f CheckSpec
emptyCheckSpec {
        csScript :: [Char]
csScript = [Char]
"#!/bin/bash\n# shellcheck external-sources=true\nsource foo",
        csFilename :: [Char]
csFilename = [Char]
"dir/myscript",
        csCheckSourced :: Bool
csCheckSourced = Bool
True
    }


return []
runTests :: IO Bool
runTests = Bool
[Char]
[([Char], Property)]
Bool -> Property
[([Char], Property)] -> (Property -> IO Result) -> IO Bool
Property -> IO Result
forall prop. Testable prop => prop -> IO Result
forall prop. Testable prop => prop -> Property
runQuickCheckAll :: [([Char], Property)] -> (Property -> IO Result) -> IO Bool
property :: forall prop. Testable prop => prop -> Property
quickCheckResult :: forall prop. Testable prop => prop -> IO Result
prop_fileCannotEnableExternalSources2 :: Bool
prop_fileCannotEnableExternalSources :: Bool
prop_fileCanDisableExternalSources :: Bool
prop_rcCanLeaveExternalSourcesUnspecified :: Bool
prop_rcCanDenyExternalSources :: Bool
prop_rcCanAllowExternalSources :: Bool
prop_sourcePathRedirectsDirective :: Bool
prop_sourcePathAddsAnnotation :: Bool
prop_sourcePathRedirectsName :: Bool
prop_canEnableOptionalsWithRc :: Bool
prop_brokenRcGetsWarning :: Bool
prop_NoRCWontLookAtFile :: Bool
prop_canUseNoRC :: Bool
prop_readsRcFile :: Bool
prop_optionIncludes4 :: Bool
prop_optionIncludes3 :: Bool
prop_optionIncludes2 :: Bool
prop_optionIncludes1 :: Bool
prop_canEnableOptionalsWithSpec :: Bool
prop_sourcedFileUsesOriginalShellExtension :: Bool
prop_shExtensionDoesntMatter :: Bool
prop_canDisableParseErrors :: Bool
prop_canDisableAllWarnings :: Bool
prop_canDisableShebangWarning :: Bool
prop_deducesTypeFromExtension2 :: Bool
prop_deducesTypeFromExtension :: Bool
prop_spinBug1413 :: Bool
prop_sourcePartOfOriginalScript :: Bool
prop_filewideAnnotation8 :: Bool
prop_filewideAnnotationBase2 :: Bool
prop_filewideAnnotation7 :: Bool
prop_filewideAnnotation6 :: Bool
prop_filewideAnnotation5 :: Bool
prop_filewideAnnotation4 :: Bool
prop_filewideAnnotation3 :: Bool
prop_filewideAnnotation2 :: Bool
prop_filewideAnnotation1 :: Bool
prop_filewideAnnotationBase :: Bool
prop_sourceDirectiveDoesntFollowFile :: Bool
prop_nonRecursiveParsing :: Bool
prop_nonRecursiveAnalysis :: Bool
prop_recursiveParsing :: Bool
prop_recursiveAnalysis :: Bool
prop_canSourceDynamicWhenRedirected :: Bool
prop_canStripPrefixAndSource2 :: Bool
prop_canStripPrefixAndSource :: Bool
prop_cantSourceDynamic2 :: Bool
prop_cantSourceDynamic :: Bool
prop_canSourceBadSyntax :: Bool
prop_noInfiniteSourcing :: Bool
prop_worksWhenDotting :: Bool
prop_worksWhenSourcingWithDashDash :: Bool
prop_worksWhenSourcing :: Bool
prop_failsWhenNotSourcing :: Bool
prop_canParseDevNull :: Bool
prop_annotationDisablesBadShebang :: Bool
prop_optionDisablesBadShebang :: Bool
prop_wontParseBadShell :: Bool
prop_optionDisablesIssue2 :: Bool
prop_optionDisablesIssue1 :: Bool
prop_commentDisablesAnalysisIssue2 :: Bool
prop_commentDisablesAnalysisIssue1 :: Bool
prop_findsAnalysisIssue :: Bool
prop_commentDisablesParseIssue2 :: Bool
prop_commentDisablesParseIssue1 :: Bool
prop_findsParseIssue :: Bool
$quickCheckAll