Skip to content

Commit 531c67f

Browse files
committed
Remove --actual
1 parent d957bb9 commit 531c67f

File tree

2 files changed

+15
-51
lines changed

2 files changed

+15
-51
lines changed

src/Print.hs

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,40 @@ where
44
import Import
55
import Types
66

7-
-- TODO Print output depending on --print=FORMAT (currently only v3)
8-
-- | Print a shell test considering the @--actual=mode@ option. See CLI
9-
-- documentation for details on.
7+
-- | Print a shell test. See CLI documentation for details.
108
printShellTest
119
:: String -- ^ Shelltest format. Value of option @--print[=FORMAT]@.
12-
-> Maybe String -- ^ Value of option @--actual[=MODE]@. @Nothing@ if option is not given.
1310
-> ShellTest -- ^ Test to print
14-
-> Either String String -- ^ Non-matching or matching exit status
15-
-> Either String String -- ^ Non-matching or matching exit status
16-
-> Either Int Int -- ^ Non-matching or matching exit status
1711
-> IO ()
18-
printShellTest format actualMode ShellTest{command=c,stdin=i,comments=comments,trailingComments=trailingComments,
12+
printShellTest format ShellTest{command=c,stdin=i,comments=comments,trailingComments=trailingComments,
1913
stdoutExpected=o_expected,stderrExpected=e_expected,exitCodeExpected=x_expected}
20-
o_actual e_actual x_actual = do
21-
(o,e,x) <- computeResults actualMode
14+
= do
2215
case format of
2316
"v1" -> do
2417
printComments comments
2518
printCommand "" c
2619
printStdin "<<<" i
27-
printStdouterr ">>>" $ justMatcherOutErr o
28-
printStdouterr ">>>2" $ justMatcherOutErr e
29-
printExitStatus True ">>>=" x
20+
printStdouterr ">>>" o_expected
21+
printStdouterr ">>>2" e_expected
22+
printExitStatus True ">>>=" x_expected
3023
printComments trailingComments
3124
"v2" -> do
3225
printComments comments
33-
printCommand "$ " c
26+
printCommand "$$$ " c
3427
printStdin "<<<" i
35-
printStdouterr ">>>" o
36-
printStdouterr ">>>2" e
37-
printExitStatus False ">>>=" x
28+
printStdouterr ">>>" o_expected
29+
printStdouterr ">>>2" e_expected
30+
printExitStatus False ">>>=" x_expected
3831
printComments trailingComments
3932
"v3" -> do
4033
printComments comments
4134
printCommand "$ " c
4235
printStdin "<" i
43-
printStdouterr ">" o
44-
printStdouterr ">2" e
45-
printExitStatus False ">=" x
36+
printStdouterr ">" o_expected
37+
printStdouterr ">2" e_expected
38+
printExitStatus False ">=" x_expected
4639
printComments trailingComments
4740
_ -> fail $ "Unsupported --print format: " ++ format
48-
where
49-
computeResults :: Maybe String -> IO (Maybe Matcher, Maybe Matcher, Matcher)
50-
computeResults Nothing = do
51-
return (o_expected, e_expected, x_expected)
52-
computeResults (Just mode)
53-
| mode `isPrefixOf` "all" = return
54-
(Just $ Lines 0 $ fromEither o_actual -- TODO what about 0? how is it in parser?
55-
,Just $ Lines 0 $ fromEither e_actual
56-
,Numeric $ show $ fromEither x_actual)
57-
| mode `isPrefixOf` "update" = return
58-
(either (Just . Lines 0) (const o_expected) o_actual
59-
,either (Just . Lines 0) (const e_expected) e_actual
60-
,either (Numeric . show) (const x_expected) x_actual)
61-
| otherwise = fail "Unsupported argument for --actual option. Allowed: all, update, or a prefix thereof."
6241

6342
printComments :: [String] -> IO ()
6443
printComments = mapM_ putStrLn
@@ -77,7 +56,7 @@ printStdouterr _ Nothing = return ()
7756
printStdouterr _ (Just (Lines _ "")) = return ()
7857
printStdouterr _ (Just (Numeric _)) = fail "FATAL: Cannot handle Matcher (Numeric) for stdout/stderr."
7958
printStdouterr _ (Just (NegativeNumeric _)) = fail "FATAL: Cannot handle Matcher (NegativeNumeric) for stdout/stderr."
80-
printStdouterr prefix (Just (Lines _ s)) = printf "%s\n%s\n" prefix s -- TODO trailing \n ?
59+
printStdouterr prefix (Just (Lines _ s)) = printf "%s\n%s" prefix s
8160
printStdouterr prefix (Just regex) = printf "%s %s\n" prefix (show regex)
8261

8362
-- | Print exit status. First arg says 'alwaysPrintEvenIfZero'.
@@ -86,14 +65,3 @@ printExitStatus _ _ (Lines _ _) = fail "FATAL: Cannot handle Matcher (Lines) for
8665
printExitStatus False _ (Numeric "0") = return ()
8766
printExitStatus True prefix (Numeric "0") = printf "%s 0\n" prefix
8867
printExitStatus _ prefix s = printf "%s %s\n" prefix (show s)
89-
90-
mkEither :: Bool -> a -> Either a a
91-
mkEither True = Right
92-
mkEither False = Left
93-
94-
fromEither :: Either a a -> a
95-
fromEither = either id id
96-
97-
-- | Make a Matcher out of Nothing.
98-
justMatcherOutErr :: Maybe Matcher -> Maybe Matcher
99-
justMatcherOutErr = Just . fromMaybe (Lines 0 "")

src/shelltest.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ data Args = Args {
6868
,debug_parse :: Bool
6969
,testpaths :: [FilePath]
7070
,print_ :: Maybe String
71-
,actual :: Maybe String
7271
} deriving (Show, Data, Typeable)
7372

7473
argdefs = Args {
@@ -92,7 +91,6 @@ argdefs = Args {
9291
,debug_parse = def &= help "Show test file parsing results and stop"
9392
,testpaths = def &= args &= typ "TESTFILES|TESTDIRS"
9493
,print_ = def &= typ "FORMAT" &= opt "v3" &= groupname "Print test file" &= help "Print test files in specified format (default: v3)."
95-
,actual = def &= typ "MODE" &= opt "all" &= help "Combined with --print, print test files with actual results (stdout, stderr, exit status). This can be used to generate or update tests. Mode 'all' prints all actual results (default). Mode 'update' prints actual results only for non-matching results, i.e. regular expressions in tests are retained."
9694
}
9795
&= helpArg [explicit, name "help", name "h"]
9896
&= program progname
@@ -155,8 +153,6 @@ checkArgs :: Args -> IO Args
155153
checkArgs args = do
156154
when (null $ testpaths args) $
157155
warn $ printf "Please specify at least one test file or directory, eg: %s tests" progname
158-
when (isJust (actual args) && not (isJust (print_ args))) $
159-
warn "Option --actual can only be used with --print."
160156
return args
161157

162158
-- running tests
@@ -187,7 +183,7 @@ prepareShellTest args st@ShellTest{testname=n,command=c,stdin=i,stdoutExpected=o
187183
let errorMatch = maybe True (e_actual `matches`) e_expected
188184
let exitCodeMatch = show x_actual `matches` x_expected
189185
case print_ args of
190-
Just format -> printShellTest format (actual args) st (mkEither outputMatch o_actual) (mkEither errorMatch e_actual) (mkEither exitCodeMatch x_actual)
186+
Just format -> printShellTest format st
191187
Nothing -> if (x_actual == 127) -- catch bad executable - should work on posix systems at least
192188
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
193189
else assertString $ concat $ filter (not . null) [

0 commit comments

Comments
 (0)