-
Notifications
You must be signed in to change notification settings - Fork 11
New PR for --print option without printing --actual results #24
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
Changes from 1 commit
95b2675
24cb5e8
940b959
7696a6c
4e2318f
f324b1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ executable shelltest | |
Import | ||
Parse | ||
Preprocessor | ||
Types | ||
Utils | ||
Utils.Debug | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module Print | ||
where | ||
|
||
import Import | ||
import Types | ||
|
||
-- | Print a shell test. See CLI documentation for details. | ||
printShellTest | ||
:: String -- ^ Shelltest format. Value of option @--print[=FORMAT]@. | ||
-> ShellTest -- ^ Test to print | ||
-> IO () | ||
printShellTest format ShellTest{command=c,stdin=i,comments=comments,trailingComments=trailingComments, | ||
stdoutExpected=o_expected,stderrExpected=e_expected,exitCodeExpected=x_expected} | ||
= do | ||
case format of | ||
"v1" -> do | ||
printComments comments | ||
printCommand "" c | ||
printStdin "<<<" i | ||
printStdouterr ">>>" o_expected | ||
printStdouterr ">>>2" e_expected | ||
printExitStatus True ">>>=" x_expected | ||
printComments trailingComments | ||
"v2" -> do | ||
printComments comments | ||
printCommand "$$$ " c | ||
printStdin "<<<" i | ||
printStdouterr ">>>" o_expected | ||
printStdouterr ">>>2" e_expected | ||
printExitStatus False ">>>=" x_expected | ||
printComments trailingComments | ||
"v3" -> do | ||
printComments comments | ||
printCommand "$ " c | ||
printStdin "<" i | ||
printStdouterr ">" o_expected | ||
printStdouterr ">2" e_expected | ||
printExitStatus False ">=" x_expected | ||
printComments trailingComments | ||
_ -> fail $ "Unsupported --print format: " ++ format | ||
|
||
printComments :: [String] -> IO () | ||
printComments = mapM_ putStrLn | ||
|
||
printStdin :: String -> Maybe String -> IO () | ||
printStdin _ (Just "") = return () | ||
printStdin _ Nothing = return () | ||
printStdin prefix (Just s) = printf "%s\n%s" prefix s | ||
|
||
printCommand :: String -> TestCommand -> IO () | ||
printCommand prefix (ReplaceableCommand s) = printf "%s%s\n" prefix s | ||
printCommand prefix (FixedCommand s) = printf "%s %s\n" prefix s | ||
|
||
printStdouterr :: String -> Maybe Matcher -> IO () | ||
printStdouterr _ Nothing = return () | ||
printStdouterr _ (Just (Lines _ "")) = return () | ||
printStdouterr _ (Just (Numeric _)) = fail "FATAL: Cannot handle Matcher (Numeric) for stdout/stderr." | ||
printStdouterr _ (Just (NegativeNumeric _)) = fail "FATAL: Cannot handle Matcher (NegativeNumeric) for stdout/stderr." | ||
printStdouterr prefix (Just (Lines _ s)) = printf "%s\n%s" prefix s | ||
printStdouterr prefix (Just regex) = printf "%s %s\n" prefix (show regex) | ||
|
||
-- | Print exit status. First arg says 'alwaysPrintEvenIfZero'. | ||
printExitStatus :: Bool -> String -> Matcher -> IO () | ||
printExitStatus _ _ (Lines _ _) = fail "FATAL: Cannot handle Matcher (Lines) for exit status." | ||
printExitStatus False _ (Numeric "0") = return () | ||
printExitStatus True prefix (Numeric "0") = printf "%s 0\n" prefix | ||
printExitStatus _ prefix s = printf "%s %s\n" prefix (show s) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ cat | |
foo | ||
>>> | ||
foo | ||
>>>2 | ||
>>>= 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test no longer matches its description. Why remove the >>>2 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought, it doesn't matter to remove the line. But you're right, it is less explicit. I removed the line, to have one more example file for shelltests of --print |
||
|
||
# Test that cat prints an error containing "unrecognized option" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
$$$ false | ||
>>>= 1 | ||
|
||
# no comment at begin of file because they are currently not parsed because of shared input | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should mention this limitation in docs. Where should we document --print ? In the CLI help and readme ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd document it in the CLI help and (not in this commit) in the readme. Because I think it's easier to write the doc when the bigger feature is ready (--actual-results) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's normally better to commit the doc along with the new feature being committed. We might forget, or there might be a delay in the next feature. At least, let's add the option to the --help output in README. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about this: At least it's up to date then and don't have to be fixed manually. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good, thanks for updating that. |
||
|
||
$$$ echo foo | ||
>>> | ||
foo | ||
|
||
$$$ cat --unknown-option | ||
>>>2 /option/ | ||
>>>= 1 | ||
|
||
# comment at end of file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
$ false | ||
>= 1 | ||
|
||
# no comment at begin of file because they are currently not parsed because of shared input | ||
|
||
$ echo foo | ||
> | ||
foo | ||
|
||
$ cat --unknown-option | ||
>2 /option/ | ||
>= 1 | ||
|
||
# comment at end of file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
$ shelltest --print=v1 tests/examples/cat.test | diff -u - tests/examples/cat.test | ||
|
||
$ shelltest --print=v1 tests/examples/echo.test | diff -u - tests/examples/echo.test | ||
|
||
$ shelltest --print=v1 tests/format1/abstract-test-with-macros | diff -u - tests/format1/abstract-test-with-macros |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
$ shelltest --print=v2 tests/format2/ideal.test | diff -u - tests/format2/ideal.test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
$ shelltest --print=v3 tests/format3/ideal.test | diff -u - tests/format3/ideal.test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels non-ideal, but it works. I don't see how exactly the types work - how does assertString become an IO action in the Nothing case ?
Perhaps we could describe it a little more clearly:
Convert this test to an IO action that either runs the test or prints it to stdout, depending on the arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertString
is IO: https://hackage.haskell.org/package/HUnit-1.6.0.0/docs/Test-HUnit-Base.html#t:AssertionOK, I'll change the doc comment.