tasty 1.2.1 → 1.2.2
raw patch · 8 files changed
+112/−50 lines, 8 files
Files
- CHANGELOG.md +7/−0
- README.md +11/−2
- Test/Tasty/CmdLine.hs +21/−10
- Test/Tasty/Ingredients/ConsoleReporter.hs +31/−2
- Test/Tasty/Run.hs +1/−35
- Test/Tasty/Runners.hs +1/−0
- Test/Tasty/Runners/Utils.hs +39/−0
- tasty.cabal +1/−1
CHANGELOG.md view
@@ -1,6 +1,13 @@ Changes ======= +Version 1.2.2+-------------++* Expose timed and getTime+* Add parseOptions+* Allow to disable ANSI tricks with --ansi-tricks=false+ Version 1.2.1 -------------
README.md view
@@ -756,10 +756,10 @@ ## FAQ -1. When my tests write to stdout/stderr, the output is garbled. Why is that and+1. **Q**: When my tests write to stdout/stderr, the output is garbled. Why is that and what do I do? - It is not recommended that you print anything to the console when using the+ **A**: It is not recommended that you print anything to the console when using the console test reporter (which is the default one). See [#103](https://github.com/feuerbach/tasty/issues/103) for the discussion.@@ -769,6 +769,15 @@ * Use [testCaseSteps](https://hackage.haskell.org/package/tasty-hunit/docs/Test-Tasty-HUnit.html#v:testCaseSteps) (for tasty-hunit only). * Use a test reporter that does not print to the console (like tasty-ant-xml). * Write your output to files instead.++2. **Q**: Why doesn't the `--hide-successes` option work properly? The test headings+ show up and/or the output appears garbled.++ **A**: This can happen sometimes when the terminal is narrower than the+ output. A workaround is to disable ANSI tricks: pass `--ansi-tricks=false`+ on the command line or set `TASTY_ANSI_TRICKS=false` in the environment.++ See [issue #152](https://github.com/feuerbach/tasty/issues/152). ## Press
Test/Tasty/CmdLine.hs view
@@ -3,6 +3,7 @@ ( optionParser , suiteOptions , suiteOptionParser+ , parseOptions , defaultMainWithIngredients ) where @@ -25,7 +26,6 @@ import Test.Tasty.Options.Env import Test.Tasty.Runners.Reducers - -- | Generate a command line parser from a list of option descriptions optionParser :: [OptionDescription] -> Parser OptionSet optionParser = getApp . foldMap toSet where@@ -37,6 +37,25 @@ suiteOptionParser :: [Ingredient] -> TestTree -> Parser OptionSet suiteOptionParser ins tree = optionParser $ suiteOptions ins tree +-- | Parse the command-line and environment options passed to tasty.+--+-- Useful if you need to get the options before 'defaultMain' is called.+--+-- Once within the test tree, 'askOption' should be used instead.+--+-- The arguments to this function should be the same as for+-- 'defaultMainWithIngredients'. If you don't use any custom ingredients,+-- pass 'defaultIngredients'.+parseOptions :: [Ingredient] -> TestTree -> IO OptionSet+parseOptions ins tree = do+ cmdlineOpts <- execParser $+ info (helper <*> suiteOptionParser ins tree)+ ( fullDesc <>+ header "Mmm... tasty test suite"+ )+ envOpts <- suiteEnvOptions ins tree+ return $ envOpts <> cmdlineOpts+ -- | Parse the command line arguments and run the tests using the provided -- ingredient list. --@@ -46,15 +65,7 @@ defaultMainWithIngredients :: [Ingredient] -> TestTree -> IO () defaultMainWithIngredients ins testTree = do installSignalHandlers- cmdlineOpts <- execParser $- info (helper <*> suiteOptionParser ins testTree)- ( fullDesc <>- header "Mmm... tasty test suite"- )-- envOpts <- suiteEnvOptions ins testTree-- let opts = envOpts <> cmdlineOpts+ opts <- parseOptions ins testTree case tryIngredients ins opts testTree of Nothing -> do
Test/Tasty/Ingredients/ConsoleReporter.hs view
@@ -5,6 +5,7 @@ ( consoleTestReporter , Quiet(..) , HideSuccesses(..)+ , AnsiTricks(..) -- * Internals -- | The following functions and datatypes are internals that are exposed to -- simplify the task of rolling your own custom console reporter UI.@@ -381,6 +382,7 @@ [ Option (Proxy :: Proxy Quiet) , Option (Proxy :: Proxy HideSuccesses) , Option (Proxy :: Proxy UseColor)+ , Option (Proxy :: Proxy AnsiTricks) ] $ \opts tree -> Just $ \smap -> do @@ -389,6 +391,7 @@ Quiet quiet = lookupOption opts HideSuccesses hideSuccesses = lookupOption opts NumThreads numThreads = lookupOption opts+ AnsiTricks ansiTricks = lookupOption opts if quiet then do@@ -413,9 +416,9 @@ toutput = buildTestOutput opts tree case () of { _- | hideSuccesses && isTerm ->+ | hideSuccesses && isTerm && ansiTricks -> consoleOutputHidingSuccesses toutput smap- | hideSuccesses && not isTerm ->+ | hideSuccesses -> streamOutputHidingSuccesses toutput smap | otherwise -> consoleOutput toutput smap }@@ -461,6 +464,32 @@ optionName = return "color" optionHelp = return "When to use colored output (default: 'auto')" optionCLParser = mkOptionCLParser $ metavar "never|always|auto"++-- | By default, when the option @--hide-successes@ is given and the output+-- goes to an ANSI-capable terminal, we employ some ANSI terminal tricks to+-- display the name of the currently running test and then erase it if it+-- succeeds.+--+-- These tricks sometimes fail, however—in particular, when the test names+-- happen to be longer than the width of the terminal window. See+--+-- * <https://github.com/feuerbach/tasty/issues/152>+--+-- * <https://github.com/feuerbach/tasty/issues/250>+--+-- When that happens, this option can be used to disable the tricks. In+-- that case, the test name will be printed only once the test fails.+newtype AnsiTricks = AnsiTricks Bool+ deriving Typeable++instance IsOption AnsiTricks where+ defaultValue = AnsiTricks True+ parseValue = fmap AnsiTricks . safeReadBool+ optionName = return "ansi-tricks"+ optionHelp = return $+ -- Multiline literals don't work because of -XCPP.+ "Enable various ANSI terminal tricks. " +++ "Can be set to 'true' (default) or 'false'." -- | @useColor when isTerm@ decides if colors should be used, -- where @isTerm@ indicates whether @stdout@ is a terminal device.
Test/Tasty/Run.hs view
@@ -14,9 +14,6 @@ import Data.Maybe import Data.Graph (SCC(..), stronglyConnComp) import Data.Typeable-#ifndef VERSION_clock-import Data.Time.Clock.POSIX (getPOSIXTime)-#endif import Control.Monad.State import Control.Monad.Writer import Control.Monad.Reader@@ -29,9 +26,6 @@ import Control.Arrow import GHC.Conc (labelThread) import Prelude -- Silence AMP and FTP import warnings-#ifdef VERSION_clock-import qualified System.Clock as Clock-#endif import Test.Tasty.Core import Test.Tasty.Parallel@@ -40,6 +34,7 @@ import Test.Tasty.Options import Test.Tasty.Options.Core import Test.Tasty.Runners.Reducers+import Test.Tasty.Runners.Utils (timed) -- | Current status of a test data Status@@ -465,32 +460,3 @@ r <- restore a `onException` sequel restore _ <- sequel restore return r---- | Measure the time taken by an 'IO' action to run-timed :: IO a -> IO (Time, a)-timed t = do- start <- getTime- !r <- t- end <- getTime- return (end-start, r)--#ifdef VERSION_clock--- | Get monotonic time------ Warning: This is not the system time, but a monotonically increasing time--- that facilitates reliable measurement of time differences.-getTime :: IO Time-getTime = do- t <- Clock.getTime Clock.Monotonic- let ns = realToFrac $-#if MIN_VERSION_clock(0,7,1)- Clock.toNanoSecs t-#else- Clock.timeSpecAsNanoSecs t-#endif- return $ ns / 10 ^ (9 :: Int)-#else--- | Get system time-getTime :: IO Time-getTime = realToFrac <$> getPOSIXTime-#endif
Test/Tasty/Runners.hs view
@@ -26,6 +26,7 @@ , ListTests(..) , testsNames -- * Command line handling+ , parseOptions , optionParser , suiteOptionParser , defaultMainWithIngredients
Test/Tasty/Runners/Utils.hs view
@@ -1,13 +1,23 @@+{-# LANGUAGE BangPatterns #-}+ -- | Note: this module is re-exported as a whole from "Test.Tasty.Runners" module Test.Tasty.Runners.Utils where import Control.Exception import Control.Applicative+#ifndef VERSION_clock+import Data.Time.Clock.POSIX (getPOSIXTime)+#endif import Data.Typeable (Typeable) import Prelude -- Silence AMP import warnings import Text.Printf import Foreign.C (CInt)+#ifdef VERSION_clock+import qualified System.Clock as Clock+#endif +import Test.Tasty.Core (Time)+ -- We install handlers only on UNIX (obviously) and on GHC >= 7.6. -- GHC 7.4 lacks mkWeakThreadId (see #181), and this is not important -- enough to look for an alternative implementation, so we just disable it@@ -83,3 +93,32 @@ newtype SignalException = SignalException CInt deriving (Show, Typeable) instance Exception SignalException++-- | Measure the time taken by an 'IO' action to run+timed :: IO a -> IO (Time, a)+timed t = do+ start <- getTime+ !r <- t+ end <- getTime+ return (end-start, r)++#ifdef VERSION_clock+-- | Get monotonic time+--+-- Warning: This is not the system time, but a monotonically increasing time+-- that facilitates reliable measurement of time differences.+getTime :: IO Time+getTime = do+ t <- Clock.getTime Clock.Monotonic+ let ns = realToFrac $+#if MIN_VERSION_clock(0,7,1)+ Clock.toNanoSecs t+#else+ Clock.timeSpecAsNanoSecs t+#endif+ return $ ns / 10 ^ (9 :: Int)+#else+-- | Get system time+getTime :: IO Time+getTime = realToFrac <$> getPOSIXTime+#endif
tasty.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/ name: tasty-version: 1.2.1+version: 1.2.2 synopsis: Modern and extensible testing framework description: Tasty is a modern testing framework for Haskell. It lets you combine your unit tests, golden