shelltestrunner 1.0 → 1.1
raw patch · 2 files changed
+42/−30 lines, 2 filesdep ~process
Dependency ranges changed: process
Files
- shelltest.hs +38/−26
- shelltestrunner.cabal +4/−4
shelltest.hs view
@@ -23,9 +23,6 @@ import Data.List import Data.Maybe (isNothing,isJust,fromJust,catMaybes) import qualified Test.HUnit (Test)--- cmdargs: the impure method of writing annotations is susceptible to--- over-optimisation by GHC - sometimes {-# OPTIONS_GHC -fno-cse #-} will be--- required. import System.Console.CmdArgs import System.Exit import System.Info (os)@@ -49,15 +46,15 @@ strace a = trace (show a) a version, progname, progversion :: String-version = "1.0" -- keep synced with shelltestrunner.cabal+version = "1.1" -- keep synced with shelltestrunner.cabal and README progname = "shelltest" progversion = progname ++ " " ++ version proghelpsuffix :: [String] proghelpsuffix = [ -- keep this bit synced with options width " -- TFOPTIONS Set extra test-framework options like -j/--threads,"- ," -t/--select-tests, -o/--timeout (use -- --help for"- ," a list.) Avoid spaces."+ ," -t/--select-tests, -o/--timeout, --hide-successes."+ ," Use -- --help for a list. Avoid spaces." ,"" ] formathelp :: String@@ -77,7 +74,8 @@ ] data Args = Args {- color :: Bool+ all_ :: Bool+ ,color :: Bool ,diff :: Bool ,exclude :: [String] ,execdir :: Bool@@ -90,8 +88,9 @@ } deriving (Show, Data, Typeable) argdefs = Args {- color = def &= help "Show colored output if your terminal supports it"- ,diff = def &= name "d" &= help "Show diff of expected vs. actual when tests fail"+ all_ = def &= name "a" &= help "Show all output on failures, even if large"+ ,color = def &= help "Show colored output if your terminal supports it"+ ,diff = def &= name "d" &= help "Show expected vs. actual in diff format (implies -a)" ,exclude = def &= name "x" &= typ "STR" &= help "Exclude test files whose path contains STR" ,execdir = def &= help "Run tests from within the test file's directory" ,extension = ".test" &= typ "EXT" &= help "Filename suffix of test files (default: .test)"@@ -144,7 +143,7 @@ when (debug args) $ printf "processing %d test files: %s\n" (length testfiles) (intercalate ", " $ map fromPlatformString $ testfiles) parseresults <- mapM (parseShellTestFile args) testfiles unless (debug_parse args) $ defaultMainWithArgs- (concatMap (hUnitTestToTests.testFileParseToHUnitTest args) parseresults)+ (concatMap (hUnitTestToTests . testFileParseToHUnitTest args) parseresults) (passthroughopts ++ if color args then [] else ["--plain"]) -- | Additional argument checking.@@ -288,24 +287,25 @@ (_, ReplaceableCommand s) -> s (_, FixedCommand s) -> s dir = if execdir args then Just $ takeDirectory n else Nothing+ trim' = if all_ args then id else trim when (debug args) $ printf "command was: %s\n" (show cmd) (o_actual, e_actual, x_actual) <- runCommandWithInput dir (toPlatformString cmd) i when (debug args) $ do- printf "stdout was : %s\n" (show $ trim o_actual)- printf "stderr was : %s\n" (show $ trim e_actual)- printf "exit was : %s\n" (show $ trim $ show x_actual)+ printf "stdout was : %s\n" (show $ trim' o_actual)+ printf "stderr was : %s\n" (show $ trim' e_actual)+ printf "exit was : %s\n" (show $ trim' $ show x_actual) if (x_actual == 127) -- catch bad executable - should work on posix systems at least then ioError $ userError e_actual -- XXX still a test failure; should be an error else assertString $ addnewline $ intercalate "\n" $ filter (not . null) [ if (maybe True (o_actual `matches`) o_expected) then ""- else showExpectedActual (diff args) "stdout" (fromJust o_expected) o_actual+ else showExpectedActual args "stdout" (fromJust o_expected) o_actual ,if (maybe True (e_actual `matches`) e_expected) then ""- else showExpectedActual (diff args) "stderr" (fromJust e_expected) e_actual+ else showExpectedActual args "stderr" (fromJust e_expected) e_actual ,if (show x_actual `matches` x_expected) then ""- else showExpectedActual False "exit code" x_expected (show x_actual)+ else showExpectedActual args{diff=False} "exit code" x_expected (show x_actual) ] where addnewline "" = "" addnewline s = "\n"++s@@ -347,11 +347,14 @@ matches s (NegativeNumeric p) = not $ s == p matches s (Lines _ p) = s == p -showExpectedActual :: Bool -> String -> Matcher -> String -> String-showExpectedActual True _ (Lines ln e) a =+showExpectedActual :: Args -> String -> Matcher -> String -> String+showExpectedActual Args{diff=True} _ (Lines ln e) a = printf "--- Expected\n+++ Got\n" ++ showDiff (1,ln) (getDiff (lines a) (lines e))-showExpectedActual _ field e a =- printf "**Expected %s: %s\n**Got %s: %s" field (show e) field (show $ trim a)+showExpectedActual args field e a =+ printf "Expected %s: %s\nGot %s: %s" field (show' e) field (show $ trim' a)+ where+ trim' = if all_ args then id else trim+ show' = if all_ args then showMatcherAll else showMatcherTrimmed showDiff :: (Int,Int) -> [(DI, String)] -> String showDiff _ [] = ""@@ -362,12 +365,21 @@ showDiff (l,r) ((B, _ ) : ds) = showDiff (l+1,r+1) ds -instance Show Matcher where- show (PositiveRegex r) = "/"++(trim r)++"/"- show (NegativeRegex r) = "!/"++(trim r)++"/"- show (Numeric s) = show $ trim s- show (NegativeNumeric s) = "!"++ show (trim s)- show (Lines _ s) = show $ trim s+instance Show Matcher where show = showMatcherTrimmed++showMatcherTrimmed :: Matcher -> String+showMatcherTrimmed (PositiveRegex r) = "/"++(trim r)++"/"+showMatcherTrimmed (NegativeRegex r) = "!/"++(trim r)++"/"+showMatcherTrimmed (Numeric s) = show $ trim s+showMatcherTrimmed (NegativeNumeric s) = "!"++ show (trim s)+showMatcherTrimmed (Lines _ s) = show $ trim s++showMatcherAll :: Matcher -> String+showMatcherAll (PositiveRegex r) = "/"++r++"/"+showMatcherAll (NegativeRegex r) = "!/"++r++"/"+showMatcherAll (Numeric s) = show s+showMatcherAll (NegativeNumeric s) = "!"++ show s+showMatcherAll (Lines _ s) = show s instance Show ShellTest where show ShellTest{testname=n,command=c,stdin=i,stdoutExpected=o,stderrExpected=e,exitCodeExpected=x} =
shelltestrunner.cabal view
@@ -1,6 +1,6 @@ name: shelltestrunner--- keep synced with shelltest.hs:-version: 1.0+-- keep synced with shelltest.hs and README:+version: 1.1 category: Testing synopsis: A tool for testing command-line programs. description:@@ -16,7 +16,7 @@ homepage: http://joyful.com/repos/shelltestrunner bug-reports: mailto:simon@joyful.com stability: beta-tested-with: GHC==6.12, GHC==7.0+tested-with: GHC==6.12.3, GHC==7.0.2, GHC==7.2.1 cabal-version: >= 1.6 build-type: Simple @@ -35,7 +35,7 @@ ,filepath >= 1.0 ,parsec < 3.2 ,regex-tdfa >= 1.1 && < 1.2- ,process < 1.1+ ,process < 1.2 ,test-framework >= 0.3.2 && < 0.5 ,test-framework-hunit >= 0.2 && < 0.3 ,utf8-string >= 0.3.5 && < 0.4