Skip to content

Commit 776a465

Browse files
committed
Do not discard trailing comments after last test
1 parent a60ebc1 commit 776a465

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/Parse.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ shelltestfile = do
6969
<|>
7070
(many $ try format1test)
7171
ptrace_ "shelltestfile 1"
72-
skipMany whitespaceorcommentline
72+
trailingComments <- many whitespaceorcommentline
7373
ptrace_ "shelltestfile 2"
7474
eof
75-
ptrace "shelltestfile ." ts
76-
return ts
75+
let ts' = init ts ++ [(last ts) { trailingComments = trailingComments }]
76+
ptrace "shelltestfile ." ts'
77+
return ts'
7778

7879

7980
----------------------------------------------------------------------
@@ -97,7 +98,7 @@ format1test = do
9798
ptrace " format1test x" x
9899
when (null (show c) && (isNothing i) && (null $ catMaybes [o,e]) && null (show x)) $ fail ""
99100
f <- sourceName . statePos <$> getParserState
100-
let t = ShellTest{testname=f,command=c,stdin=i,stdoutExpected=o,stderrExpected=e,exitCodeExpected=x,lineNumber=ln,comments=comments}
101+
let t = ShellTest{testname=f,command=c,stdin=i,stdoutExpected=o,stderrExpected=e,exitCodeExpected=x,lineNumber=ln,comments=comments,trailingComments=[]}
101102
ptrace " format1test ." t
102103
return t
103104

@@ -166,7 +167,7 @@ format2test i = do
166167
ptrace " format2test x" x
167168
when (null (show c) && (isNothing i) && (null $ catMaybes [o,e]) && null (show x)) $ fail ""
168169
f <- sourceName . statePos <$> getParserState
169-
let t = ShellTest{testname=f,command=c,stdin=i,stdoutExpected=o,stderrExpected=e,exitCodeExpected=x,lineNumber=ln,comments=comments}
170+
let t = ShellTest{testname=f,command=c,stdin=i,stdoutExpected=o,stderrExpected=e,exitCodeExpected=x,lineNumber=ln,comments=comments,trailingComments=[]}
170171
ptrace " format2test ." t
171172
return t
172173

@@ -264,7 +265,7 @@ format3test i = do
264265
ptrace " format3test x" x
265266
when (null (show c) && (isNothing i) && (null $ catMaybes [o,e]) && null (show x)) $ fail ""
266267
f <- sourceName . statePos <$> getParserState
267-
let t = ShellTest{testname=f,command=c,stdin=i,stdoutExpected=o,stderrExpected=e,exitCodeExpected=x,lineNumber=ln,comments=comments}
268+
let t = ShellTest{testname=f,command=c,stdin=i,stdoutExpected=o,stderrExpected=e,exitCodeExpected=x,lineNumber=ln,comments=comments,trailingComments=[]}
268269
ptrace " format3test ." t
269270
return t
270271

src/Print.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ printShellTest
1515
-> Either String String -- ^ Non-matching or matching exit status
1616
-> Either Int Int -- ^ Non-matching or matching exit status
1717
-> IO ()
18-
printShellTest format actualMode ShellTest{command=c,stdin=i,comments=comments,
18+
printShellTest format actualMode ShellTest{command=c,stdin=i,comments=comments,trailingComments=trailingComments,
1919
stdoutExpected=o_expected,stderrExpected=e_expected,exitCodeExpected=x_expected}
2020
o_actual e_actual x_actual = do
2121
(o,e,x) <- computeResults actualMode
@@ -27,20 +27,23 @@ printShellTest format actualMode ShellTest{command=c,stdin=i,comments=comments,
2727
printStdouterr ">>>" $ justMatcherOutErr o
2828
printStdouterr ">>>2" $ justMatcherOutErr e
2929
printExitStatus True ">>>=" x
30+
printComments trailingComments
3031
"v2" -> do
3132
printComments comments
3233
printCommand "$ " c
3334
printStdin "<<<" i
3435
printStdouterr ">>>" o
3536
printStdouterr ">>>2" e
3637
printExitStatus False ">>>=" x
38+
printComments trailingComments
3739
"v3" -> do
3840
printComments comments
3941
printCommand "$ " c
4042
printStdin "<" i
4143
printStdouterr ">" o
4244
printStdouterr ">2" e
4345
printExitStatus False ">=" x
46+
printComments trailingComments
4447
_ -> fail $ "Unsupported --print format: " ++ format
4548
where
4649
computeResults :: Maybe String -> IO (Maybe Matcher, Maybe Matcher, Matcher)

src/Types.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Text.Parsec
77

88
data ShellTest = ShellTest {
99
comments :: [String] -- # COMMENTS OR BLANK LINES before test
10+
,trailingComments :: [String] -- # COMMENTS OR BLANK LINES after the last test
1011
,command :: TestCommand
1112
,stdin :: Maybe String
1213
,stdoutExpected :: Maybe Matcher

0 commit comments

Comments
 (0)