packages feed

tasty 1.3 → 1.3.1

raw patch · 9 files changed

+158/−15 lines, 9 files

Files

CHANGELOG.md view
@@ -1,6 +1,11 @@ Changes ======= +Version 1.3.1+-------------++* Add an ability for a test provider to print colorful/formatted output+ Version 1.3 ----------- 
Test/Tasty/CmdLine.hs view
@@ -33,6 +33,8 @@  -- | Generate a command line parser from a list of option descriptions, -- alongside any related warning messages.+--+-- @since 1.3 optionParser :: [OptionDescription] -> ([String], Parser OptionSet) optionParser = second getApp . foldMap toSet where   toSet :: OptionDescription -> ([String], Ap Parser OptionSet)@@ -132,6 +134,8 @@  -- | The command line parser for the test suite, alongside any related -- warnings.+--+-- @since 1.3 suiteOptionParser :: [Ingredient] -> TestTree -> ([String], Parser OptionSet) suiteOptionParser ins tree = optionParser $ suiteOptions ins tree 
Test/Tasty/Core.hs view
@@ -5,6 +5,7 @@ module Test.Tasty.Core where  import Control.Exception+import Test.Tasty.Providers.ConsoleFormat import Test.Tasty.Options import Test.Tasty.Patterns import Test.Tasty.Patterns.Types@@ -65,6 +66,17 @@     -- @FAIL@.   , resultTime :: Time     -- ^ How long it took to run the test, in seconds.+  , resultDetailsPrinter :: ResultDetailsPrinter+    -- ^ An action that prints additional information about a test.+    --+    -- This is similar to 'resultDescription' except it can produce+    -- colorful/formatted output; see "Test.Tasty.Providers.ConsoleFormat".+    --+    -- This can be used instead of or in addition to 'resultDescription'.+    --+    -- Usually this is set to 'noResultDetails', which does nothing.+    --+    -- @since 1.3.1   }   deriving Show @@ -104,6 +116,7 @@   , resultDescription = "Exception: " ++ show e   , resultShortDescription = "FAIL"   , resultTime = 0+  , resultDetailsPrinter = noResultDetails   }  -- | Test progress information.
Test/Tasty/Ingredients/ConsoleReporter.hs view
@@ -22,6 +22,7 @@   , TestOutput(..)   , buildTestOutput   , foldTestOutput+  , withConsoleFormat   ) where  import Prelude hiding (fail)@@ -30,6 +31,7 @@ import Control.Concurrent.STM import Control.Exception import Test.Tasty.Core+import Test.Tasty.Providers.ConsoleFormat import Test.Tasty.Run import Test.Tasty.Ingredients import Test.Tasty.Options@@ -45,7 +47,7 @@ import Data.Maybe import Data.Monoid (Any(..)) import Data.Typeable-import Options.Applicative hiding (str, Success, Failure)+import Options.Applicative hiding (action, str, Success, Failure) import System.IO import System.Console.ANSI #if !MIN_VERSION_base(4,11,0)@@ -129,6 +131,8 @@           when (not $ null rDesc) $             (if resultSuccessful result then infoOk else infoFail) $               printf "%s%s\n" (indent $ level + 1) (formatDesc (level+1) rDesc)+          case resultDetailsPrinter result of+            ResultDetailsPrinter action -> action level withConsoleFormat        return $ PrintTest name printTestName printTestResult @@ -619,28 +623,38 @@  -- (Potentially) colorful output ok, fail, skipped, infoOk, infoFail :: (?colors :: Bool) => String -> IO ()-fail     = output BoldIntensity   Vivid Red-ok       = output NormalIntensity Dull  Green-skipped  = output NormalIntensity Dull  Magenta-infoOk   = output NormalIntensity Dull  White-infoFail = output NormalIntensity Dull  Red+fail     = output failFormat+ok       = output okFormat+skipped  = output skippedFormat+infoOk   = output infoOkFormat+infoFail = output infoFailFormat  output   :: (?colors :: Bool)-  => ConsoleIntensity-  -> ColorIntensity-  -> Color+  => ConsoleFormat   -> String   -> IO ()-output bold intensity color str+output format = withConsoleFormat format . putStr++-- | Run action with console configured for a specific output format+--+-- This function does not apply any output formats if colors are disabled at command+-- line or console detection.+--+-- Can be used by providers that wish to provider specific result details printing,+-- while re-using the tasty formats and coloring logic.+--+-- @since 1.3.1+withConsoleFormat :: (?colors :: Bool) => ConsoleFormatPrinter+withConsoleFormat format action   | ?colors =     (do       setSGR-        [ SetColor Foreground intensity color-        , SetConsoleIntensity bold+        [ SetColor Foreground (colorIntensity format) (color format)+        , SetConsoleIntensity (consoleIntensity format)         ]-      putStr str+      action     ) `finally` setSGR []-  | otherwise = putStr str+  | otherwise = action  -- }}}
Test/Tasty/Options.hs view
@@ -82,6 +82,8 @@   -- So, when we build the complete parser for OptionSet, we turn a   -- failing parser into an always-succeeding one that may return an empty   -- OptionSet.)+  --+  -- @since 1.3   optionCLParser :: Parser v   optionCLParser = mkOptionCLParser mempty 
Test/Tasty/Providers.hs view
@@ -3,6 +3,7 @@   ( IsTest(..)   , testPassed   , testFailed+  , testFailedDetails   , Result   , Progress(..)   , TestName@@ -12,6 +13,7 @@   where  import Test.Tasty.Core+import Test.Tasty.Providers.ConsoleFormat (ResultDetailsPrinter, noResultDetails)  -- | Convert a test to a leaf of the 'TestTree' singleTest :: IsTest t => TestName -> t -> TestTree@@ -26,6 +28,7 @@   , resultDescription = desc   , resultShortDescription = "OK"   , resultTime = 0+  , resultDetailsPrinter = noResultDetails   }  -- | 'Result' of a failed test@@ -37,4 +40,15 @@   , resultDescription = desc   , resultShortDescription = "FAIL"   , resultTime = 0+  , resultDetailsPrinter = noResultDetails   }++-- | 'Result' of a failed test with custom details printer+--+-- @since 1.3.1+testFailedDetails+  :: String               -- ^ description+  -> ResultDetailsPrinter -- ^ details printer+  -> Result+testFailedDetails desc printer = (testFailed desc)+  { resultDetailsPrinter = printer }
+ Test/Tasty/Providers/ConsoleFormat.hs view
@@ -0,0 +1,87 @@+-- | This module can be used by providers to perform colorful/formatted+-- output and possibly re-use tasty's own output formats.+--+-- @since 1.3.1+module Test.Tasty.Providers.ConsoleFormat+  ( ResultDetailsPrinter(..)+  , ConsoleFormat(..)+  , ConsoleFormatPrinter+  , noResultDetails+  , failFormat+  , infoFailFormat+  , infoOkFormat+  , okFormat+  , skippedFormat+  )+where++import System.Console.ANSI++-- | Console output format+--+-- @since 1.3.1+data ConsoleFormat = ConsoleFormat+  { consoleIntensity :: ConsoleIntensity+  , colorIntensity   :: ColorIntensity+  , color            :: Color+  }++-- | Type of console format printer functions+--+-- @since 1.3.1+type ConsoleFormatPrinter+  =  ConsoleFormat -- ^ selected console format+  -> IO ()         -- ^ action to be executed with active console format+  -> IO ()++-- | Noop result details printer. The default for most providers.+--+-- @since 1.3.1+noResultDetails :: ResultDetailsPrinter+noResultDetails = ResultDetailsPrinter . const . const $ return ()++-- | An action that prints additional information about a test using+-- colors/formatting; see 'Test.Tasty.Providers.testFailedDetails' and+-- 'Test.Tasty.Runners.resultDetailsPrinter'.+--+-- As input, this action is provided with the current indentation level and+-- a 'ConsoleFormatPrinter', which tells it how perform output.+--+-- This is a newtype to allow a 'Show' instance.+--+-- @since 1.3.1+newtype ResultDetailsPrinter = ResultDetailsPrinter+  (Int -> ConsoleFormatPrinter -> IO ())++instance Show ResultDetailsPrinter where+  show _printer = "ResultDetailsPrinter"++-- | Format used to display failures+--+-- @since 1.3.1+failFormat :: ConsoleFormat+failFormat = ConsoleFormat BoldIntensity   Vivid Red++-- | Format used to display additional information on failures+infoFailFormat :: ConsoleFormat+--+-- @since 1.3.1+infoFailFormat = ConsoleFormat NormalIntensity Dull  Red++-- | Format used to display sucesses+--+-- @since 1.3.1+okFormat :: ConsoleFormat+okFormat = ConsoleFormat NormalIntensity Dull  Green++-- | Format used to display additional information on sucesses+--+-- @since 1.3.1+infoOkFormat :: ConsoleFormat+infoOkFormat = ConsoleFormat NormalIntensity Dull  White++-- | Format used to display skipped tests+--+-- @since 1.3.1+skippedFormat :: ConsoleFormat+skippedFormat = ConsoleFormat NormalIntensity Dull  Magenta
Test/Tasty/Run.hs view
@@ -35,6 +35,7 @@ import Test.Tasty.Options.Core import Test.Tasty.Runners.Reducers import Test.Tasty.Runners.Utils (timed)+import Test.Tasty.Providers.ConsoleFormat (noResultDetails)  -- | Current status of a test data Status@@ -157,6 +158,7 @@                 "Timed out after " ++ tstr             , resultShortDescription = "TIMEOUT"             , resultTime = fromIntegral t+            , resultDetailsPrinter = noResultDetails             }       fromMaybe timeoutResult <$> timeout t a @@ -322,6 +324,7 @@           , resultDescription = ""           , resultShortDescription = "SKIP"           , resultTime = 0+          , resultDetailsPrinter = noResultDetails           }       }   return ((action, statusVar), (path0, dep_paths))
tasty.cabal view
@@ -2,7 +2,7 @@ --  see http://haskell.org/cabal/users-guide/  name:                tasty-version:             1.3+version:             1.3.1 synopsis:            Modern and extensible testing framework description:         Tasty is a modern testing framework for Haskell.                      It lets you combine your unit tests, golden@@ -35,6 +35,7 @@     Test.Tasty,     Test.Tasty.Options,     Test.Tasty.Providers,+    Test.Tasty.Providers.ConsoleFormat,     Test.Tasty.Runners     Test.Tasty.Ingredients,     Test.Tasty.Ingredients.Basic