Skip to content

Show line nr #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 6 additions & 3 deletions src/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
6 changes: 4 additions & 2 deletions src/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/shelltest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ""
Expand Down
9 changes: 9 additions & 0 deletions tests/format1/failure-line.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 1. Test if macros are replaced and tests are successful.
shelltest tests/format1/one-failing-test
>>> /.*Command [(]at line 8[)].*
.*plahh.*
.*Expected stdout.*
.*slahh.*
.*Got stdout.*
.*plahh.*/
>>>= 1
15 changes: 15 additions & 0 deletions tests/format1/one-failing-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Note that this file is called from 'failure-line.test'
# This should be fine.
echo "plahh"
>>> /plahh/
>>>= 0

# This should be broken.
echo "plahh"
>>> /slahh/
>>>= 0

# This should be fine.
echo "plahh"
>>> /plahh/
>>>= 0
9 changes: 9 additions & 0 deletions tests/format2/failure-line.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 1. Test if macros are replaced and tests are successful.
shelltest tests/format1/one-failing-test
>>> /.*Command [(]at line 8[)].*
.*plahh.*
.*Expected stdout.*
.*slahh.*
.*Got stdout.*
.*plahh.*/
>>>= 1
15 changes: 15 additions & 0 deletions tests/format2/one-failing-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Note that this file is called from 'failure-line.test'
# This should be fine.
$$$ echo "plahh"
>>> /plahh/
>>>= 0

# This should be broken.
$$$ echo "plahh"
>>> /slahh/
>>>= 0

# This should be fine.
$$$ echo "plahh"
>>> /plahh/
>>>= 0
9 changes: 9 additions & 0 deletions tests/format3/failure-line.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 1. Test if macros are replaced and tests are successful.
shelltest tests/format1/one-failing-test
>>> /.*Command [(]at line 8[)].*
.*plahh.*
.*Expected stdout.*
.*slahh.*
.*Got stdout.*
.*plahh.*/
>>>= 1
15 changes: 15 additions & 0 deletions tests/format3/one-failing-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Note that this file is called from 'failure-line.test'
# This should be fine.
$ echo "plahh"
> /plahh/
>= 0

# This should be broken.
$ echo "plahh"
> /slahh/
>= 0

# This should be fine.
$ echo "plahh"
> /plahh/
>= 0