tasty 1.2 → 1.2.1
raw patch · 6 files changed
+95/−71 lines, 6 filesdep ~ansi-terminal
Dependency ranges changed: ansi-terminal
Files
- CHANGELOG.md +6/−0
- README.md +27/−26
- Test/Tasty/CmdLine.hs +1/−40
- Test/Tasty/Ingredients/ConsoleReporter.hs +2/−1
- Test/Tasty/Runners/Utils.hs +55/−0
- tasty.cabal +4/−4
CHANGELOG.md view
@@ -1,6 +1,12 @@ Changes ======= +Version 1.2.1+-------------++* Document and expose installSignalHandlers+* Enable colors in Emacs and other almost-ANSI-capable terminals+ Version 1.2 -----------
README.md view
@@ -85,7 +85,7 @@ [tasty][] is the core package. It contains basic definitions and APIs and a console runner. -[tasty]: http://hackage.haskell.org/package/tasty+[tasty]: https://hackage.haskell.org/package/tasty In order to create a test suite, you also need to install one or more «providers» (see below).@@ -94,26 +94,27 @@ The following providers exist: -* [tasty-hunit](http://hackage.haskell.org/package/tasty-hunit) — for unit tests- (based on [HUnit](http://hackage.haskell.org/package/HUnit))+* [tasty-hunit](https://hackage.haskell.org/package/tasty-hunit) — for unit tests+ (based on [HUnit](https://hackage.haskell.org/package/HUnit)) * [tasty-golden][] — for golden tests, which are unit tests whose results are kept in files-* [tasty-smallcheck](http://hackage.haskell.org/package/tasty-smallcheck) —+* [tasty-smallcheck](https://hackage.haskell.org/package/tasty-smallcheck) — exhaustive property-based testing- (based on [smallcheck](http://hackage.haskell.org/package/smallcheck))-* [tasty-quickcheck](http://hackage.haskell.org/package/tasty-quickcheck) — for randomized+ (based on [smallcheck](https://hackage.haskell.org/package/smallcheck))+* [tasty-quickcheck](https://hackage.haskell.org/package/tasty-quickcheck) — for randomized property-based testing (based on [QuickCheck](http://hackage.haskell.org/package/QuickCheck)) * [tasty-hedgehog](https://github.com/qfpl/tasty-hedgehog) — for randomized- property-based testing (based on [Hedgehog](http://hackage.haskell.org/package/hedgehog))-* [tasty-hspec](http://hackage.haskell.org/package/tasty-hspec) — for- [Hspec](http://hspec.github.io/) tests-* [tasty-leancheck](http://hackage.haskell.org/package/tasty-leancheck) — for+ property-based testing (based on [Hedgehog](https://hackage.haskell.org/package/hedgehog))+* [tasty-hspec](https://hackage.haskell.org/package/tasty-hspec) — for+ [Hspec](https://hspec.github.io/) tests+* [tasty-leancheck](https://hackage.haskell.org/package/tasty-leancheck) — for enumerative property-based testing- (based on [LeanCheck](http://hackage.haskell.org/package/leancheck))-* [tasty-program](http://hackage.haskell.org/package/tasty-program) — run+ (based on [LeanCheck](https://hackage.haskell.org/package/leancheck))+* [tasty-program](https://hackage.haskell.org/package/tasty-program) — run external program and test whether it terminates successfully+* [tasty-wai](https://hackage.haskell.org/package/tasty-wai) - for testing [wai](https://hackage.haskell.org/wai) endpoints. -[tasty-golden]: http://hackage.haskell.org/package/tasty-golden+[tasty-golden]: https://hackage.haskell.org/package/tasty-golden It's easy to create custom providers using the API from `Test.Tasty.Providers`. @@ -129,24 +130,24 @@ Some ingredients that can enhance your test suite are: -* [tasty-ant-xml](http://hackage.haskell.org/package/tasty-ant-xml) adds a+* [tasty-ant-xml](https://hackage.haskell.org/package/tasty-ant-xml) adds a possibility to write the test results in a machine-readable XML format, which is understood by various CI systems and IDEs-* [tasty-rerun](http://hackage.haskell.org/package/tasty-rerun) adds support for+* [tasty-rerun](https://hackage.haskell.org/package/tasty-rerun) adds support for minimal test reruns by recording previous test runs and using this information to filter the test tree. For example, you can use this ingredient to only run failed tests, or only run tests that threw an exception.-* [tasty-html](http://hackage.haskell.org/package/tasty-html) adds the+* [tasty-html](https://hackage.haskell.org/package/tasty-html) adds the possibility to write the test results as a HTML file-* [tasty-stats](http://hackage.haskell.org/package/tasty-stats) adds the+* [tasty-stats](https://hackage.haskell.org/package/tasty-stats) adds the possibility to collect statistics of the test suite in a CSV file. ### Other packages -* [tasty-th](http://hackage.haskell.org/package/tasty-th) automatically+* [tasty-th](https://hackage.haskell.org/package/tasty-th) automatically discovers tests based on the function names and generate the boilerplate code for you-* [tasty-hunit-adapter](http://hackage.haskell.org/package/tasty-hunit-adapter)+* [tasty-hunit-adapter](https://hackage.haskell.org/package/tasty-hunit-adapter) converts existing HUnit test suites into tasty test suites * [tasty-discover](https://github.com/lwm/tasty-discover) automatically discovers your tests.@@ -269,7 +270,7 @@ name, and so on up to `$NF`, which is set to the test's own name. The field `$0` is set to all other fields concatenated using `.` as a separator. -[awk]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html#tag_20_06_13_02+[awk]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html#tag_20_06_13_02 As an example, consider a test inside two test groups: @@ -774,22 +775,22 @@ Blog posts and other publications related to tasty. If you wrote or just found something not mentioned here, send a pull request! -* [Holy Haskell Project Starter](http://yannesposito.com/Scratch/en/blog/Holy-Haskell-Starter/)-* [First time testing, also with FP Complete](http://levischuck.com/posts/2013-11-13-first-testing-and-fpcomplete.html)+* [Holy Haskell Project Starter](https://yannesposito.com/Scratch/en/blog/Holy-Haskell-Starter/)+* [First time testing, also with FP Complete](https://levischuck.com/posts/2013-11-13-first-testing-and-fpcomplete.html) (tasty has been added to stackage since then)-* [24 Days of Hackage: tasty](http://ocharles.org.uk/blog/posts/2013-12-03-24-days-of-hackage-tasty.html)+* [24 Days of Hackage: tasty](https://ocharles.org.uk/blog/posts/2013-12-03-24-days-of-hackage-tasty.html) * [Resources in Tasty](https://ro-che.info/articles/2013-12-10-tasty-resources) * [Custom options in Tasty][custom-options-article] * [Resources in Tasty (update)](https://ro-che.info/articles/2013-12-29-tasty-resources-2)-* [Announcing tasty-rerun](http://ocharles.org.uk/blog/posts/2014-01-20-announcing-tasty-rerun.html)-* [Code testing in Haskell revisited (with Tasty)](http://lambda.jstolarek.com/2014/01/code-testing-in-haskell-revisited-with-tasty/)+* [Announcing tasty-rerun](https://ocharles.org.uk/blog/posts/2014-01-20-announcing-tasty-rerun.html)+* [Code testing in Haskell revisited (with Tasty)](https://lambda.jstolarek.com/2014/01/code-testing-in-haskell-revisited-with-tasty/) * [New patterns in tasty][awk-patterns-article] * [Screencast: Dynamic Test Suites in Haskell using Hspec and Tasty](https://www.youtube.com/watch?v=PGsDvgmZF7A) * [Automatically generated directories for tasty tests][tasty-directories] [custom-options-article]: https://ro-che.info/articles/2013-12-20-tasty-custom-options.html [awk-patterns-article]: https://ro-che.info/articles/2018-01-08-tasty-new-patterns-[tasty-directories]: http://nmattia.com/posts/2018-04-30-tasty-test-names.html+[tasty-directories]: https://nmattia.com/posts/2018-04-30-tasty-test-names.html Maintainers -----------
Test/Tasty/CmdLine.hs view
@@ -1,5 +1,4 @@ -- | Parsing options supplied on the command line-{-# LANGUAGE CPP, ScopedTypeVariables, DeriveDataTypeable #-} module Test.Tasty.CmdLine ( optionParser , suiteOptions@@ -15,25 +14,12 @@ import System.Exit import System.IO --- 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--- there.-#define INSTALL_HANDLERS defined UNIX && MIN_VERSION_base(4,6,0)--#if INSTALL_HANDLERS-import Control.Concurrent (mkWeakThreadId, myThreadId)-import Control.Exception (Exception(..), throwTo)-import Control.Monad (forM_)-import Data.Typeable (Typeable)-import System.Posix.Signals-import System.Mem.Weak (deRefWeak)-#endif #if !MIN_VERSION_base(4,9,0) import Data.Monoid #endif import Test.Tasty.Core+import Test.Tasty.Runners.Utils import Test.Tasty.Ingredients import Test.Tasty.Options import Test.Tasty.Options.Env@@ -78,28 +64,3 @@ Just act -> do ok <- act if ok then exitSuccess else exitFailure---- from https://ro-che.info/articles/2014-07-30-bracket--- Install a signal handler so that e.g. the cursor is restored if the test--- suite is killed by SIGTERM.-installSignalHandlers :: IO ()-installSignalHandlers = do-#if INSTALL_HANDLERS- main_thread_id <- myThreadId- weak_tid <- mkWeakThreadId main_thread_id- forM_ [ sigABRT, sigBUS, sigFPE, sigHUP, sigILL, sigQUIT, sigSEGV,- sigSYS, sigTERM, sigUSR1, sigUSR2, sigXCPU, sigXFSZ ] $ \sig ->- installHandler sig (Catch $ send_exception weak_tid sig) Nothing- where- send_exception weak_tid sig = do- m <- deRefWeak weak_tid- case m of- Nothing -> return ()- Just tid -> throwTo tid (toException $ SignalException sig)--newtype SignalException = SignalException Signal- deriving (Show, Typeable)-instance Exception SignalException-#else- return ()-#endif
Test/Tasty/Ingredients/ConsoleReporter.hs view
@@ -398,6 +398,7 @@ do isTerm <- hSupportsANSI stdout+ isTermColor <- hSupportsANSIColor stdout (\k -> if isTerm then (do hideCursor; k) `finally` showCursor@@ -406,7 +407,7 @@ hSetBuffering stdout LineBuffering let- ?colors = useColor whenColor isTerm+ ?colors = useColor whenColor isTermColor let toutput = buildTestOutput opts tree
Test/Tasty/Runners/Utils.hs view
@@ -3,9 +3,25 @@ import Control.Exception import Control.Applicative+import Data.Typeable (Typeable) import Prelude -- Silence AMP import warnings import Text.Printf+import Foreign.C (CInt) +-- 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+-- there.+#define INSTALL_HANDLERS defined __UNIX__ && MIN_VERSION_base(4,6,0)++#if INSTALL_HANDLERS+import Control.Concurrent (mkWeakThreadId, myThreadId)+import Control.Exception (Exception(..), throwTo)+import Control.Monad (forM_)+import System.Posix.Signals+import System.Mem.Weak (deRefWeak)+#endif+ -- | Catch possible exceptions that may arise when evaluating a string. -- For normal (total) strings, this is a no-op. --@@ -28,3 +44,42 @@ -- https://ro-che.info/articles/2015-05-28-force-list forceElements :: [a] -> () forceElements = foldr seq ()++-- from https://ro-che.info/articles/2014-07-30-bracket+-- | Install signal handlers so that e.g. the cursor is restored if the test+-- suite is killed by SIGTERM. Upon a signal, a 'SignalException' will be+-- thrown to the thread that has executed this action.+--+-- This function is called automatically from the @defaultMain*@ family of+-- functions. You only need to call it explicitly if you call+-- 'tryIngredients' yourself.+--+-- This function does nothing on non-UNIX systems or when compiled with GHC+-- older than 7.6.+installSignalHandlers :: IO ()+installSignalHandlers = do+#if INSTALL_HANDLERS+ main_thread_id <- myThreadId+ weak_tid <- mkWeakThreadId main_thread_id+ forM_ [ sigABRT, sigBUS, sigFPE, sigHUP, sigILL, sigQUIT, sigSEGV,+ sigSYS, sigTERM, sigUSR1, sigUSR2, sigXCPU, sigXFSZ ] $ \sig ->+ installHandler sig (Catch $ send_exception weak_tid sig) Nothing+ where+ send_exception weak_tid sig = do+ m <- deRefWeak weak_tid+ case m of+ Nothing -> return ()+ Just tid -> throwTo tid (toException $ SignalException sig)+#else+ return ()+#endif++-- | This exception is thrown when the program receives a signal, assuming+-- 'installSignalHandlers' was called.+--+-- The 'CInt' field contains the signal number, as in+-- 'System.Posix.Signals.Signal'. We don't use that type synonym, however,+-- because it's not available on non-UNIXes.+newtype SignalException = SignalException CInt+ deriving (Show, Typeable)+instance Exception SignalException
tasty.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/ name: tasty-version: 1.2+version: 1.2.1 synopsis: Modern and extensible testing framework description: Tasty is a modern testing framework for Haskell. It lets you combine your unit tests, golden@@ -66,7 +66,7 @@ optparse-applicative >= 0.14, unbounded-delays >= 0.1, async >= 2.0,- ansi-terminal >= 0.6.2+ ansi-terminal >= 0.9 if flag(clock) build-depends: clock >= 0.4.4.0@@ -80,9 +80,9 @@ if !os(windows) && !impl(ghcjs) build-depends: unix, wcwidth- cpp-options: -DUNIX+ cpp-options: -D__UNIX__ -- hs-source-dirs: default-language: Haskell2010- default-extensions: CPP+ default-extensions: CPP, ScopedTypeVariables, DeriveDataTypeable ghc-options: -Wall