mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-15 09:33:09 -07:00
Allow arbitrary bats @test names (fixes #2587)
This commit is contained in:
parent
14056a7f3a
commit
d9c9e60fb0
2 changed files with 17 additions and 4 deletions
|
@ -142,7 +142,7 @@ data InnerToken t =
|
||||||
| Inner_T_CoProcBody t
|
| Inner_T_CoProcBody t
|
||||||
| Inner_T_Include t
|
| Inner_T_Include t
|
||||||
| Inner_T_SourceCommand t t
|
| Inner_T_SourceCommand t t
|
||||||
| Inner_T_BatsTest t t
|
| Inner_T_BatsTest String t
|
||||||
deriving (Show, Eq, Functor, Foldable, Traversable)
|
deriving (Show, Eq, Functor, Foldable, Traversable)
|
||||||
|
|
||||||
data Annotation =
|
data Annotation =
|
||||||
|
|
|
@ -2500,16 +2500,29 @@ readBraceGroup = called "brace group" $ do
|
||||||
spacing
|
spacing
|
||||||
return $ T_BraceGroup id list
|
return $ T_BraceGroup id list
|
||||||
|
|
||||||
prop_readBatsTest = isOk readBatsTest "@test 'can parse' {\n true\n}"
|
prop_readBatsTest1 = isOk readBatsTest "@test 'can parse' {\n true\n}"
|
||||||
|
prop_readBatsTest2 = isOk readBatsTest "@test random text !(@*$Y&! {\n true\n}"
|
||||||
|
prop_readBatsTest3 = isOk readBatsTest "@test foo { bar { baz {\n true\n}"
|
||||||
|
prop_readBatsTest4 = isNotOk readBatsTest "@test foo \n{\n true\n}"
|
||||||
readBatsTest = called "bats @test" $ do
|
readBatsTest = called "bats @test" $ do
|
||||||
start <- startSpan
|
start <- startSpan
|
||||||
try $ string "@test"
|
try $ string "@test "
|
||||||
spacing
|
spacing
|
||||||
name <- readNormalWord
|
name <- readBatsName
|
||||||
spacing
|
spacing
|
||||||
test <- readBraceGroup
|
test <- readBraceGroup
|
||||||
id <- endSpan start
|
id <- endSpan start
|
||||||
return $ T_BatsTest id name test
|
return $ T_BatsTest id name test
|
||||||
|
where
|
||||||
|
readBatsName = do
|
||||||
|
line <- try . lookAhead $ many1 $ noneOf "\n"
|
||||||
|
let name = reverse $ f $ reverse line
|
||||||
|
string name
|
||||||
|
|
||||||
|
-- We want everything before the last " {" in a string, so we find everything after "{ " in its reverse
|
||||||
|
f ('{':' ':rest) = dropWhile isSpace rest
|
||||||
|
f (a:rest) = f rest
|
||||||
|
f [] = ""
|
||||||
|
|
||||||
prop_readWhileClause = isOk readWhileClause "while [[ -e foo ]]; do sleep 1; done"
|
prop_readWhileClause = isOk readWhileClause "while [[ -e foo ]]; do sleep 1; done"
|
||||||
readWhileClause = called "while loop" $ do
|
readWhileClause = called "while loop" $ do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue