summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRomanCheplyaka <>2018-02-13 16:21:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2018-02-13 16:21:00 (GMT)
commit8e5685143a3a1068e0be8e37a62e13d46d8fb6b4 (patch)
treebc6dd2ca7d54f8fea0dba4be2c1cd3e96d6ab367
parent85c7e88c1cdc2e8c9f3c56fff4e89494d6caa5ce (diff)
version 1.0.1HEAD1.0.1master
-rw-r--r--CHANGELOG.md6
-rw-r--r--README.md48
-rw-r--r--Test/Tasty/Ingredients/ConsoleReporter.hs7
-rw-r--r--Test/Tasty/Ingredients/ListTests.hs2
-rw-r--r--Test/Tasty/Options.hs13
-rw-r--r--Test/Tasty/Runners/Utils.hs9
-rw-r--r--tasty.cabal3
7 files changed, 60 insertions, 28 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 722e1f8..8f21fa6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,12 @@
Changes
=======
+Version 1.0.1
+-------------
+
+* Add a `safeReadBool` function, for case-insensitive parsing of boolean options
+* Convert all tasty's own options to case-insensitive
+
Version 1.0.0.1
---------------
diff --git a/README.md b/README.md
index 6f6c3b6..1de4bb9 100644
--- a/README.md
+++ b/README.md
@@ -176,15 +176,16 @@ your test suite with the `--help` flag. The output will look something like this
Mmm... tasty test suite
Usage: test [-p|--pattern ARG] [-t|--timeout ARG] [-l|--list-tests]
- [-j|--num-threads ARG] [-q|--quiet] [--hide-successes] [--color ARG]
- [--quickcheck-tests ARG] [--quickcheck-replay ARG]
- [--quickcheck-show-replay ARG] [--quickcheck-max-size ARG]
- [--quickcheck-max-ratio ARG] [--quickcheck-verbose]
- [--smallcheck-depth ARG]
+ [-j|--num-threads ARG] [-q|--quiet] [--hide-successes]
+ [--color never|always|auto] [--smallcheck-depth NUMBER]
+ [--quickcheck-tests NUMBER] [--quickcheck-replay SEED]
+ [--quickcheck-show-replay] [--quickcheck-max-size NUMBER]
+ [--quickcheck-max-ratio NUMBER] [--quickcheck-verbose]
Available options:
-h,--help Show this help text
- -p,--pattern ARG Select only tests that match pattern
+ -p,--pattern ARG Select only tests which satisfy a pattern or awk
+ expression
-t,--timeout ARG Timeout for individual tests (suffixes: ms,s,m,h;
default: s)
-l,--list-tests Do not run the tests; just print their names
@@ -192,19 +193,21 @@ Available options:
-q,--quiet Do not produce any output; indicate success only by
the exit code
--hide-successes Do not print tests that passed successfully
- --color ARG When to use colored output. Options are 'never',
- 'always' and 'auto' (default: 'auto')
- --quickcheck-tests ARG Number of test cases for QuickCheck to generate
- --quickcheck-replay ARG Replay token to use for replaying a previous test run
- --quickcheck-show-replay ARG
- Show a replay token for replaying tests
- --quickcheck-max-size ARG
+ --color never|always|auto
+ When to use colored output (default: 'auto')
+ --smallcheck-depth NUMBER
+ Depth to use for smallcheck tests
+ --quickcheck-tests NUMBER
+ Number of test cases for QuickCheck to generate
+ --quickcheck-replay SEED Random seed to use for replaying a previous test run
+ (use same --quickcheck-max-size)
+ --quickcheck-show-replay Show a replay token for replaying tests
+ --quickcheck-max-size NUMBER
Size of the biggest test cases quickcheck generates
- --quickcheck-max-ratio ARG
+ --quickcheck-max-ratio NUMBER
Maximum number of discared tests per successful test
before giving up
--quickcheck-verbose Show the generated test cases
- --smallcheck-depth ARG Depth to use for smallcheck tests
```
Every option can be passed via environment. To obtain the environment variable
@@ -213,6 +216,12 @@ all letters, and prepend `TASTY_`. For example, the environment equivalent of
`--smallcheck-depth` is `TASTY_SMALLCHECK_DEPTH`. To turn on a switch (such as
`TASTY_HIDE_SUCCESSES`), set the variable to `True`.
+Note on boolean options: by convention, boolean ("on/off") options are specified
+using a switch on the command line, for example `--quickcheck-show-replay`
+instead of `--quickcheck-show-replay=true`. However, when
+passed via the environment, the option value needs to be `True` or `False`
+(case-insensitive), e.g. `TASTY_QUICKCHECK_SHOW_REPLAY=true`.
+
If you're using a non-console runner, please refer to its documentation to find
out how to configure options during the run time.
@@ -686,13 +695,16 @@ something not mentioned here, send a pull request!
* [First time testing, also with FP Complete](http://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)
-* [Resources in Tasty](http://ro-che.info/articles/2013-12-10-tasty-resources.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)](http://ro-che.info/articles/2013-12-29-tasty-resources-2.html)
+* [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/)
+* [New patterns in tasty][awk-patterns-article]
+* [Screencast: Dynamic Test Suites in Haskell using Hspec and Tasty](https://www.youtube.com/watch?v=PGsDvgmZF7A)
-[custom-options-article]: http://ro-che.info/articles/2013-12-20-tasty-custom-options.html
+[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
Maintainers
-----------
diff --git a/Test/Tasty/Ingredients/ConsoleReporter.hs b/Test/Tasty/Ingredients/ConsoleReporter.hs
index 0a0f365..4cbb23f 100644
--- a/Test/Tasty/Ingredients/ConsoleReporter.hs
+++ b/Test/Tasty/Ingredients/ConsoleReporter.hs
@@ -423,7 +423,7 @@ newtype Quiet = Quiet Bool
deriving (Eq, Ord, Typeable)
instance IsOption Quiet where
defaultValue = Quiet False
- parseValue = fmap Quiet . safeRead
+ parseValue = fmap Quiet . safeReadBool
optionName = return "quiet"
optionHelp = return "Do not produce any output; indicate success only by the exit code"
optionCLParser = mkFlagCLParser (short 'q') (Quiet True)
@@ -433,7 +433,7 @@ newtype HideSuccesses = HideSuccesses Bool
deriving (Eq, Ord, Typeable)
instance IsOption HideSuccesses where
defaultValue = HideSuccesses False
- parseValue = fmap HideSuccesses . safeRead
+ parseValue = fmap HideSuccesses . safeReadBool
optionName = return "hide-successes"
optionHelp = return "Do not print tests that passed successfully"
optionCLParser = mkFlagCLParser mempty (HideSuccesses True)
@@ -452,7 +452,8 @@ instance IsOption UseColor where
defaultValue = Auto
parseValue = parseUseColor
optionName = return "color"
- optionHelp = return "When to use colored output. Options are 'never', 'always' and 'auto' (default: 'auto')"
+ optionHelp = return "When to use colored output (default: 'auto')"
+ optionCLParser = mkOptionCLParser $ metavar "never|always|auto"
-- | @useColor when isTerm@ decides if colors should be used,
-- where @isTerm@ indicates whether @stdout@ is a terminal device.
diff --git a/Test/Tasty/Ingredients/ListTests.hs b/Test/Tasty/Ingredients/ListTests.hs
index 05d1ecb..d11c9b7 100644
--- a/Test/Tasty/Ingredients/ListTests.hs
+++ b/Test/Tasty/Ingredients/ListTests.hs
@@ -20,7 +20,7 @@ newtype ListTests = ListTests Bool
deriving (Eq, Ord, Typeable)
instance IsOption ListTests where
defaultValue = ListTests False
- parseValue = fmap ListTests . safeRead
+ parseValue = fmap ListTests . safeReadBool
optionName = return "list-tests"
optionHelp = return "Do not run the tests; just print their names"
optionCLParser = mkFlagCLParser (short 'l') (ListTests True)
diff --git a/Test/Tasty/Options.hs b/Test/Tasty/Options.hs
index 7c977d4..72e73eb 100644
--- a/Test/Tasty/Options.hs
+++ b/Test/Tasty/Options.hs
@@ -20,10 +20,12 @@ module Test.Tasty.Options
, mkFlagCLParser
, mkOptionCLParser
, safeRead
+ , safeReadBool
) where
import qualified Data.Map as Map
import Data.Map (Map)
+import Data.Char (toLower)
import Data.Tagged
import Data.Proxy
import Data.Typeable
@@ -40,7 +42,8 @@ import qualified Data.Semigroup (Semigroup((<>)))
class Typeable v => IsOption v where
-- | The value to use if the option was not supplied explicitly
defaultValue :: v
- -- | Try to parse an option value from a string
+ -- | Try to parse an option value from a string. Consider using
+ -- 'safeReadBool' for boolean options and 'safeRead' for numeric options.
parseValue :: String -> Maybe v
-- | The option name. It is used to form the command line option name, for
-- instance. Therefore, it had better not contain spaces or other fancy
@@ -155,3 +158,11 @@ safeRead :: Read a => String -> Maybe a
safeRead s
| [(x, "")] <- reads s = Just x
| otherwise = Nothing
+
+-- | Parse a 'Bool' case-insensitively
+safeReadBool :: String -> Maybe Bool
+safeReadBool s =
+ case (map toLower s) of
+ "true" -> Just True
+ "false" -> Just False
+ _ -> Nothing
diff --git a/Test/Tasty/Runners/Utils.hs b/Test/Tasty/Runners/Utils.hs
index ef04187..6d21dd9 100644
--- a/Test/Tasty/Runners/Utils.hs
+++ b/Test/Tasty/Runners/Utils.hs
@@ -2,7 +2,6 @@
module Test.Tasty.Runners.Utils where
import Control.Exception
-import Control.DeepSeq
import Control.Applicative
import Prelude -- Silence AMP import warnings
import Text.Printf
@@ -21,7 +20,11 @@ formatMessage = go 3
go :: Int -> String -> IO String
go 0 _ = return "exceptions keep throwing other exceptions!"
go recLimit msg = do
- mbStr <- try $ evaluate $ force msg
+ mbStr <- try $ evaluate $ forceElements msg
case mbStr of
- Right str -> return str
+ Right () -> return msg
Left e' -> printf "message threw an exception: %s" <$> go (recLimit-1) (show (e' :: SomeException))
+
+-- https://ro-che.info/articles/2015-05-28-force-list
+forceElements :: [a] -> ()
+forceElements = foldr seq ()
diff --git a/tasty.cabal b/tasty.cabal
index 8b38f40..cc07e69 100644
--- a/tasty.cabal
+++ b/tasty.cabal
@@ -2,7 +2,7 @@
-- see http://haskell.org/cabal/users-guide/
name: tasty
-version: 1.0.0.1
+version: 1.0.1
synopsis: Modern and extensible testing framework
description: Tasty is a modern testing framework for Haskell.
It lets you combine your unit tests, golden
@@ -64,7 +64,6 @@ library
mtl >= 2.1.3.1,
tagged >= 0.5,
optparse-applicative >= 0.14,
- deepseq >= 1.3,
unbounded-delays >= 0.1,
async >= 2.0,
ansi-terminal >= 0.6.2