Permalink
Browse files

Line number, where test is located, is printed on case of test failure.

  • Loading branch information...
taavi-valjaots committed Mar 9, 2018
1 parent f265e8a commit 0c1d22907dfac8e6f967a0e690f128a1107674f7
Showing with 14 additions and 7 deletions.
  1. +2 −0 CHANGES
  2. +6 −3 src/Parse.hs
  3. +4 −2 src/Types.hs
  4. +2 −2 src/shelltest.hs
@@ -1,3 +1,5 @@
* line number, where test is located, is printed on case of test failure (Taavi Valjaots)

1.9 (2018/1/14)

* two new test file formats have been added, allowing input re-use and lighter syntax
@@ -84,6 +84,7 @@ format1test = do
ptrace_ " format1test 0"
skipMany whitespaceorcommentline
ptrace_ " format1test 1"
ln <- sourceLine <$> getPosition
c <- command1 <?> "command line"
ptrace " format1test c" c
i <- optionMaybe input1 <?> "input"
@@ -96,7 +97,7 @@ format1test = do
ptrace " format1test x" x
when (null (show c) && (isNothing i) && (null $ catMaybes [o,e]) && null (show x)) $ fail ""
f <- sourceName . statePos <$> getParserState
let t = ShellTest{testname=f,command=c,stdin=i,stdoutExpected=o,stderrExpected=e,exitCodeExpected=x}
let t = ShellTest{testname=f,command=c,stdin=i,stdoutExpected=o,stderrExpected=e,exitCodeExpected=x,lineNumber=ln}
ptrace " format1test ." t
return t

@@ -152,6 +153,7 @@ format2test i = do
ptrace_ " format2test 0"
skipMany whitespaceorcommentline
ptrace_ " format2test 1"
ln <- sourceLine <$> getPosition
c <- command2 <?> "command line"
ptrace " format2test c" c
nullstdout <- nullLinesMatcher . sourceLine <$> getPosition
@@ -164,7 +166,7 @@ format2test i = do
ptrace " format2test x" x
when (null (show c) && (isNothing i) && (null $ catMaybes [o,e]) && null (show x)) $ fail ""
f <- sourceName . statePos <$> getParserState
let t = ShellTest{testname=f,command=c,stdin=i,stdoutExpected=o,stderrExpected=e,exitCodeExpected=x}
let t = ShellTest{testname=f,command=c,stdin=i,stdoutExpected=o,stderrExpected=e,exitCodeExpected=x,lineNumber=ln}
ptrace " format2test ." t
return t

@@ -249,6 +251,7 @@ format3test i = do
ptrace_ " format3test 0"
skipMany whitespaceorcommentline
ptrace_ " format3test 1"
ln <- sourceLine <$> getPosition
c <- command3 <?> "command line"
ptrace " format3test c" c
nullstdout <- nullLinesMatcher . sourceLine <$> getPosition
@@ -261,7 +264,7 @@ format3test i = do
ptrace " format3test x" x
when (null (show c) && (isNothing i) && (null $ catMaybes [o,e]) && null (show x)) $ fail ""
f <- sourceName . statePos <$> getParserState
let t = ShellTest{testname=f,command=c,stdin=i,stdoutExpected=o,stderrExpected=e,exitCodeExpected=x}
let t = ShellTest{testname=f,command=c,stdin=i,stdoutExpected=o,stderrExpected=e,exitCodeExpected=x,lineNumber=ln}
ptrace " format3test ." t
return t

@@ -12,17 +12,19 @@ data ShellTest = ShellTest {
,stderrExpected :: Maybe Matcher
,exitCodeExpected :: Matcher
,testname :: String
,lineNumber :: Int
}

instance Show ShellTest where
show ShellTest{testname=n,command=c,stdin=i,stdoutExpected=o,stderrExpected=e,exitCodeExpected=x} =
printf "ShellTest {command = %s, stdin = %s, stdoutExpected = %s, stderrExpected = %s, exitCodeExpected = %s, testname = %s}"
show ShellTest{testname=n,command=c,lineNumber=ln,stdin=i,stdoutExpected=o,stderrExpected=e,exitCodeExpected=x} =
printf "ShellTest {command = %s, stdin = %s, stdoutExpected = %s, stderrExpected = %s, exitCodeExpected = %s, testname = %s, lineNumber = %s}"
(show c)
(maybe "Nothing" (show.trim) i)
(show $ show <$> o)
(show $ show <$> e)
(show x)
(show $ trim n)
(show ln)

data TestCommand = ReplaceableCommand String
| FixedCommand String
@@ -154,7 +154,7 @@ testFileParseToHUnitTest _ (Left e) = ("parse error in " ++ (sourceName $ errorP

shellTestToHUnitTest :: Args -> ShellTest -> Test.HUnit.Test
shellTestToHUnitTest args ShellTest{testname=n,command=c,stdin=i,stdoutExpected=o_expected,
stderrExpected=e_expected,exitCodeExpected=x_expected} =
stderrExpected=e_expected,exitCodeExpected=x_expected,lineNumber=ln} =
n ~: do
let e = with args
cmd = case (e,c) of (_:_, ReplaceableCommand s) -> e ++ " " ++ dropWhile (/=' ') s
@@ -176,7 +176,7 @@ shellTestToHUnitTest args ShellTest{testname=n,command=c,stdin=i,stdoutExpected=
then ioError $ userError $ unwords $ filter (not . null) [e_actual, printf "Command: '%s' Exit code: %i" cmd x_actual] -- XXX still a test failure; should be an error
else assertString $ concat $ filter (not . null) [
if any not [outputMatch, errorMatch, exitCodeMatch]
then printf "Command:\n%s\n" cmd
then printf "Command (at line %s):\n%s\n" (show ln) cmd
else ""
,if outputMatch
then ""

0 comments on commit 0c1d229

Please sign in to comment.