tasty-leancheck (empty) → 0.0.1
raw patch · 19 files changed
+829/−0 lines, 19 filesdep +basedep +leancheckdep +tastysetup-changed
Dependencies added: base, leancheck, tasty, tasty-leancheck
Files
- .gitignore +24/−0
- .travis.yml +65/−0
- LICENSE +30/−0
- Makefile +80/−0
- README.md +112/−0
- Setup.hs +2/−0
- TODO.md +7/−0
- eg/minimal.hs +24/−0
- mk/All.hs +6/−0
- mk/Toplibs.hs +4/−0
- mk/depend.mk +19/−0
- mk/ghcdeps +49/−0
- mk/haddock-i +24/−0
- mk/haskell.mk +110/−0
- src/Test/Tasty/LeanCheck.hs +129/−0
- stack.yaml +15/−0
- tasty-leancheck.cabal +62/−0
- tests/test-sdist +28/−0
- tests/test.hs +39/−0
+ .gitignore view
@@ -0,0 +1,24 @@+.cabal-sandbox+cabal.sandbox.config+.stack-work+idx/+dist/+log/+doc/+*.swp+*.swo+*.swn+*.swm+*.o+*.hi+*.dyn_hi+*.dyn_o+tests/test+doc/*.html+doc/*.css+doc/*.js+doc/*.png+doc/*.gif+mk/toplibs+eg/minimal+README.html
+ .travis.yml view
@@ -0,0 +1,65 @@+# .travis.yml file for tasty-leancheck+#+# Copyright: (c) 2017-2018 Rudy Matela+# License: 3-Clause BSD (see the file LICENSE)+# Maintainer: Rudy Matela <rudy@matela.com.br>++language: c # not really++notifications:+ email:+ on_failure: change++sudo: false++cache:+ directories:+ - $HOME/.ghc+ - $HOME/.cabal+ - $HOME/.stack++before_install:+- export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH+- ghc --version+- cabal --version+- haddock --version+- rm -f ~/.cabal/config && cabal update+# Download and unpack the stack executable+# "Once Travis whitelists the stack.dev files," simply include stack in the+# addons section. -- https://docs.haskellstack.org/en/stable/travis_ci/+- mkdir -p ~/.local/bin+- export PATH=$HOME/.local/bin:$PATH+- travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'+- stack config set system-ghc --global true+- stack --version+- cabal install tasty leancheck++script:+- make && make test && make haddock+- make test-sdist+- cabal test --ghc-option=-O0+- stack $STACKR --no-terminal --skip-ghc-check test --ghc-options=-O0++matrix:+ allow_failures:+ - ghc: 'head'+ include:+ - ghc: 'head'+ env: GHCVER=head CABALVER=head+ addons: {apt: {packages: [ghc-head, cabal-install-head], sources: hvr-ghc}}+ - ghc: '8.4'+ env: GHCVER=8.4.3 CABALVER=2.2+ addons: {apt: {packages: [ghc-8.4.3, cabal-install-2.2], sources: hvr-ghc}}+ - ghc: '8.2'+ env: GHCVER=8.2.2 CABALVER=2.0 STACKR=--resolver=lts-11+ addons: {apt: {packages: [ghc-8.2.2, cabal-install-2.0], sources: hvr-ghc}}+ - ghc: '8.0'+ env: GHCVER=8.0.2 CABALVER=1.24 STACKR=--resolver=lts-11+ addons: {apt: {packages: [ghc-8.0.2, cabal-install-1.24], sources: hvr-ghc}}+ - ghc: '7.10'+ env: GHCVER=7.10.3 CABALVER=1.22+ addons: {apt: {packages: [ghc-7.10.3, cabal-install-1.22], sources: hvr-ghc}}+ script:+ - make && make test && make haddock+ - make test-sdist+ - cabal test --ghc-option=-O0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2018, Rudy Matela++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Rudy Matela nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Makefile view
@@ -0,0 +1,80 @@+# Makefile for tasty-leancheck+#+# Copyright: (c) 2015-2018 Rudy Matela+# License: 3-Clause BSD (see the file LICENSE)+# Maintainer: Rudy Matela <rudy@matela.com.br>+TESTS = \+ tests/test+EGS = \+ eg/minimal+BENCHS =+GHCIMPORTDIRS = src+GHCFLAGS = -O2 $(shell grep -q "Arch Linux" /etc/lsb-release && echo -dynamic)+HADDOCKFLAGS = --no-print-missing-docs \+ $(shell grep -q "Arch Linux" /etc/lsb-release && echo --optghc=-dynamic)++all: mk/toplibs++all-all: mk/All.o++test: $(patsubst %,%.test,$(TESTS))++%.test: %+ ./$<++clean: clean-hi-o clean-haddock+ rm -f $(TESTS) $(BENCHS) $(EGS) mk/toplibs++ghci: mk/All.ghci++install:+ @echo "use \`cabal install' instead"++test-sdist:+ ./tests/test-sdist++test-via-cabal:+ cabal test++test-via-stack:+ stack test++test-via-everything: test test-via-cabal test-via-stack++legacy-test: # needs ghc-8.0 .. ghc-7.8 installed as such+ make clean && make test GHC=ghc-8.2 GHCFLAGS="-Werror -dynamic"+ make clean && make test GHC=ghc-8.0 GHCFLAGS="-Werror -dynamic"+ make clean && make test GHC=ghc-7.10 GHCFLAGS="-Werror -dynamic"+ make clean && make test GHC=ghc-7.8 GHCFLAGS="-Werror -dynamic"+ make clean && make test++legacy-test-via-cabal: # needs similarly named cabal wrappers+ cabal clean && cabal-ghc-8.2 configure && cabal-ghc-8.2 test+ cabal clean && cabal-ghc-8.0 configure && cabal-ghc-8.0 test+ cabal clean && cabal-ghc-7.10 configure && cabal-ghc-7.10 test+ cabal clean && cabal-ghc-7.8 configure && cabal-ghc-7.8 test+ cabal clean && cabal test++prepare:+ cabal update && cabal install --only-dependencies++prepare-legacy-test:+ cabal-ghc-8.2 update && cabal-ghc-8.2 install --only-dependencies+ cabal-ghc-8.0 update && cabal-ghc-8.0 install --only-dependencies+ cabal-ghc-7.10 update && cabal-ghc-7.10 install --only-dependencies+ cabal-ghc-7.8 update && cabal-ghc-7.8 install --only-dependencies++hlint:+ hlint \+ --ignore "Use import/export shortcut" \+ --ignore "Redundant bracket" \+ .++# NOTE: (very hacky!) the following target allows parallel compilation (-jN) of+# eg and tests programs so long as they don't share dependencies _not_ stored+# in src/ and tests/. Runnable binaries should depend on mk/toplibs instead of+# actual Haskell source files+mk/toplibs: mk/Toplibs.o+ touch mk/toplibs++include mk/haskell.mk
+ README.md view
@@ -0,0 +1,112 @@+tasty-leancheck: LeanCheck support for Tasty+============================================++[![tasty-leancheck's Build Status][build-status]][build-log]+[![tasty-leancheck on Hackage][hackage-version]][tasty-leancheck-on-hackage]+[![tasty-leancheck on Stackage LTS][stackage-lts-badge]][tasty-leancheck-on-stackage-lts]+[![tasty-leancheck on Stackage Nightly][stackage-nightly-badge]][tasty-leancheck-on-stackage-nightly]++[LeanCheck] support for the [Tasty] test framework.+Tasty and healthy tests.+++Installing+----------++ $ cabal install tasty-leancheck+++Example+-------++(This example is intentionally similar to [Tasty's official example].)++Here's how your `test.hs` might look like:++```haskell+import Test.Tasty+import Test.Tasty.LeanCheck as LC+import Data.List++main :: IO ()+main = defaultMain tests++tests :: TestTree+tests = testGroup "Test properties checked by LeanCheck"+ [ LC.testProperty "sort == sort . reverse" $+ \list -> sort (list :: [Int]) == sort (reverse list)+ , LC.testProperty "Fermat's little theorem" $+ \x -> ((x :: Integer)^7 - x) `mod` 7 == 0+ -- the following property do not hold+ , LC.testProperty "Fermat's last theorem" $+ \x y z n ->+ (n :: Integer) >= 3 LC.==> x^n + y^n /= (z^n :: Integer)+ ]+```++And here is the output for the above program:++```+$ ./test+Test properties checked by LeanCheck+ sort == sort . reverse: OK+ +++ OK, passed 200 tests.+ Fermat's little theorem: OK+ +++ OK, passed 200 tests.+ Fermat's last theorem: FAIL+ *** Failed! Falsifiable (after 71 tests):+ 0 0 0 3++1 out of 3 tests failed (0.00s)+```+++Options+-------++The tasty-leancheck provider has only one option, `--leancheck-tests`:++```+$ ./test --leancheck-tests 10+Test properties checked by LeanCheck+ sort == sort . reverse: OK+ +++ OK, passed 10 tests.+ Fermat's little theorem: OK+ +++ OK, passed 10 tests.+ Fermat's last theorem: OK+ +++ OK, passed 10 tests.++All 3 tests passed (0.00s)+```+++Further reading+---------------++* [tasty-leancheck's Haddock documentation];+* [LeanCheck's Haddock documentation];+* [Tasty's Haddock documentation];+* [LeanCheck's README];+* [Tasty's README];+* [Tutorial on property-based testing with LeanCheck].++[tasty-leancheck's Haddock documentation]: https://hackage.haskell.org/package/tasty-leancheck/docs/Test-Tasty-LeanCheck.html+[LeanCheck's Haddock documentation]: https://hackage.haskell.org/package/leancheck/docs/Test-LeanCheck.html+[Tasty's Haddock documentation]: https://hackage.haskell.org/package/tasty/docs/Test-Tasty.html+[LeanCheck's README]: https://github.com/rudymatela/leancheck#readme+[Tasty's README]: https://github.com/rudymatela/tasty#readme+[tutorial on property-based testing with LeanCheck]: https://github.com/rudymatela/leancheck/blob/master/doc/tutorial.md++[Tasty's official example]: https://github.com/feuerbach/tasty#example+[Tasty]: https://github.com/feuerbach/tasty+[LeanCheck]: https://github.com/rudymatela/leancheck++[build-status]: https://travis-ci.org/rudymatela/tasty-leancheck.svg?branch=master+[build-log]: https://travis-ci.org/rudymatela/tasty-leancheck+[hackage-version]: https://img.shields.io/hackage/v/tasty-leancheck.svg+[tasty-leancheck-on-hackage]: https://hackage.haskell.org/package/tasty-leancheck+[stackage-lts-badge]: http://stackage.org/package/tasty-leancheck/badge/lts+[stackage-nightly-badge]: http://stackage.org/package/tasty-leancheck/badge/nightly+[tasty-leancheck-on-stackage]: http://stackage.org/package/tasty-leancheck+[tasty-leancheck-on-stackage-lts]: http://stackage.org/lts/package/tasty-leancheck+[tasty-leancheck-on-stackage-nightly]: http://stackage.org/nightly/package/tasty-leancheck
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ TODO.md view
@@ -0,0 +1,7 @@+TO DO list for tasty-leancheck+==============================++For now, the following should suffice:++ $ alias lstodo='grep --color -nREi "TODO(:|\{)" *'+ $ lstodo
+ eg/minimal.hs view
@@ -0,0 +1,24 @@+-- Copyright (c) 2018 Rudy Matela.+-- Distributed under the 3-Clause BSD licence (see the file LICENSE).+--+-- Minimal example of using LeanCheck with Tasty.+import Test.Tasty+import Test.Tasty.LeanCheck as LC+import Data.List++main :: IO ()+main = defaultMain tests++tests :: TestTree+tests = testGroup "Test properties checked by LeanCheck"+ [ LC.testProperty "sort == sort . reverse" $+ \list -> sort (list :: [Int]) == sort (reverse list)+ , LC.testProperty "Fermat's little theorem" $+ \x -> ((x :: Integer)^7 - x) `mod` 7 == 0+ -- the following two properties do not hold+ , LC.testProperty "Fermat's last theorem" $+ \x y z n ->+ (n :: Integer) >= 3 LC.==> x^n + y^n /= (z^n :: Integer)+ , LC.testProperty "divMod" $+ \x y -> y * (x `div` y) + x `mod` y == (x :: Int)+ ]
+ mk/All.hs view
@@ -0,0 +1,6 @@+module All+ ( module Test.Tasty.LeanCheck+ )+where++import Test.Tasty.LeanCheck
+ mk/Toplibs.hs view
@@ -0,0 +1,4 @@+-- Using ghc --make in this module triggers compilation of every library.+module Toplibs () where++import Test.Tasty.LeanCheck ()
+ mk/depend.mk view
@@ -0,0 +1,19 @@+mk/All.o: \+ src/Test/Tasty/LeanCheck.hs \+ mk/All.hs+mk/Toplibs.o: \+ src/Test/Tasty/LeanCheck.hs \+ mk/Toplibs.hs+Setup.o: \+ Setup.hs+Setup: \+ Setup.hs \+ mk/toplibs+src/Test/Tasty/LeanCheck.o: \+ src/Test/Tasty/LeanCheck.hs+tests/test.o: \+ tests/test.hs \+ src/Test/Tasty/LeanCheck.hs+tests/test: \+ tests/test.hs \+ mk/toplibs
+ mk/ghcdeps view
@@ -0,0 +1,49 @@+#!/bin/bash+#+# ghcdeps: generate Haskell make dependencies for compiling with GHC.+#+# Copyright (c) 2015-2018 Rudy Matela.+# Distributed under the 3-Clause BSD licence.+#+# From a list of files provided on standard input,+# generate flat make dependencies.+#+# Transitive relations are repeated.+#+# Usage:+# $ ghcdeps -isomedir:someother <<LIST+# program.hs+# Library.hs+# Path/To/Library.hs+# LIST+# program: ...+# Library.o: ...+# Path/To/Library.o: ...+#+# Or:+# $ find -name \*.hs -o -name \*.lhs | ghcdeps [GHCFLAGS]+# ...+#+# Note that when using find, you have to remember to exclude unecessary files,+# e.g.: dist, Setup.hs+#+# Yes, this is hacky. But hey, it works.+while read fn+do+ ghc "$@" -dep-suffix=. -dep-makefile=tmp.mk -M "$fn" ||+ exit 1+ deps="`cat tmp.mk |+ grep "hs$" |+ sort |+ sed -e "s/.*: //" |+ tac |+ tr '\n' ' ' |+ sed -e "s/ $//"`"+ obj=`echo $fn | sed -e 's,^\./,,;s/\.hs$/.o/'`+ bin=`echo $fn | sed -e 's,^\./,,;s/\.hs$//'`+ echo "$obj: $deps"+ grep -q "main" "$fn" && echo "$bin: `echo $deps | sed -e 's|[^ ]*src[^ ]*||g'` mk/toplibs"+ rm -f tmp.mk+done |+sort |+sed -e 's, *, \\\n ,g'
+ mk/haddock-i view
@@ -0,0 +1,24 @@+#!/bin/bash+#+# haddock-i: list haddock's -i parameters.+#+# Copyright (c) 2015-2018 Rudy Matela.+# Distributed under the 3-Clause BSD licence.+#+# $ haddock-i <package1> <package2> ... <packageN>+#+# will print -i parameters necessary for haddock to link to Haddock+# documentation installed on your system, so you can:+#+# $ haddock-i base template-haskell | xargs haddock <files>+errxit() {+ echo "$@" > /dev/stderr+ exit 1+}++for pkg in "$@"; do+ ghc-pkg field $pkg haddock-html,haddock-interfaces ||+ errxit "error: haddock-i: cannot find package $pkg (ghc-pkg)"+done |+sed "s/.*: //" |+sed "N;s/\n/,/;s/^/-i/"
+ mk/haskell.mk view
@@ -0,0 +1,110 @@+# Implicit rules for compiling Haskell code.+#+# Copyright (c) 2015-2018 Rudy Matela.+# Distributed under the 3-Clause BSD licence.+#+# You can optionally configure the "Configuration variables" below in your main+# makefile, e.g.:+#+# GHCIMPORTDIRS = path/to/dir:path/to/another/dir+# GHCFLAGS = -O2 -dynamic+# GHC = ghc-7.6+# include haskell.mk++++# Configuration variables++# GHC Parameters+GHCIMPORTDIRS ?=+GHCFLAGS ?=+GHC ?= ghc+GHCCMD = $(GHC) -i$(GHCIMPORTDIRS) $(GHCFLAGS)++# Hugs Parameters+HUGSIMPORTDIRS ?= "/usr/lib/hugs/packages/*"+HUGSFLAGS ?=+CPPHS_HUGS ?= cpphs-hugs --noline -D__HUGS__+HUGS ?= hugs+RUNHUGS ?= runhugs+HUGSCMD = $(HUGS) -F"$(CPPHS_HUGS)" -P$(HUGSIMPORTDIRS) $(HUGSFLAGS)+RUNHUGSCMD = $(RUNHUGS) -F"$(CPPHS_HUGS)" -P$(HUGSIMPORTDIRS) $(HUGSFLAGS)+++# Makefile where to keep the dependencies+DEPMK ?= mk/depend.mk++# LIB_HSS: all library Haskell files+# ALL_HSS: all Haskell files+# You can override ALL/LIB_HSS in your main Makefile+LIST_LIB_HSS ?= find src -name "*.hs"+LIST_ALL_HSS ?= find \( -path "./dist" -o -path "./.stack-work" \) -prune \+ -o -name "*.*hs" -print+LIB_HSS ?= $(shell $(LIST_LIB_HSS))+ALL_HSS ?= $(shell $(LIST_ALL_HSS))++PKGNAME = $(shell cat *.cabal | grep "^name:" | sed -e "s/name: *//")+++# Implicit rules+%.hi %.o: %.hs+ $(GHCCMD) $< && touch $@++%: %.hs+ $(GHCCMD) $< && touch $@++.PHONY: %.ghci+%.ghci: %.hs+ $(GHCCMD) -O0 --interactive $<++.PHONY: %.hugs+%.hugs: %.hs+ $(HUGSCMD) $<++.PHONY: %.runhugs+%.runhugs: %.hs+ $(RUNHUGSCMD) $<+++# Cleaning rule (add as a clean dependency)+.PHONY: clean-hi-o+clean-hi-o:+ find $(ALL_HSS) | sed -e 's/hs$$/o/' | xargs rm -f+ find $(ALL_HSS) | sed -e 's/hs$$/hi/' | xargs rm -f+ find $(ALL_HSS) | sed -e 's/hs$$/dyn_o/' | xargs rm -f+ find $(ALL_HSS) | sed -e 's/hs$$/dyn_hi/' | xargs rm -f+++# Update dependency file+.PHONY: depend+depend:+ find $(ALL_HSS) | ./mk/ghcdeps -i$(GHCIMPORTDIRS) $(GHCFLAGS) > $(DEPMK)++# haddock rules+haddock: doc/index.html++clean-haddock:+ rm -f doc/*.{html,css,js,png,gif,json} README.html++upload-haddock:+ @echo "use \`cabal upload -d' instead"+ @echo "(but 1st: cabal install --only-dependencies --enable-documentation)"+ @echo "(to just compile docs: cabal haddock --for-hackage)"+ @echo "(on Arch Linux, use: cabal haddock --for-hackage --haddock-options=--optghc=-dynamic)"++doc/index.html: $(LIB_HSS)+ ./mk/haddock-i base template-haskell | xargs \+ haddock --html -odoc $(LIB_HSS) $(HADDOCKFLAGS) --title=$(PKGNAME)++# lists all Haskell source files+list-all-hss:+ @find $(ALL_HSS)++# lists library Haskell source files+list-lib-hss:+ @find $(LIB_HSS)++show-pkgname:+ @echo $(PKGNAME)++include $(DEPMK)
+ src/Test/Tasty/LeanCheck.hs view
@@ -0,0 +1,129 @@+-- |+-- Module : Test.Tasty.LeanCheck+-- Copyright : (c) 2018 Rudy Matela+-- License : 3-Clause BSD (see the file LICENSE)+-- Maintainer : Rudy Matela <rudy@matela.com.br>+--+-- LeanCheck support for the Tasty test framework.+--+-- Here's how your @test.hs@ might look like:+--+-- > import Test.Tasty+-- > import Test.Tasty.LeanCheck as LC+-- > import Data.List+-- >+-- > main :: IO ()+-- > main = defaultMain tests+-- >+-- > tests :: TestTree+-- > tests = testGroup "Test properties checked by LeanCheck"+-- > [ LC.testProperty "sort == sort . reverse" $+-- > \list -> sort (list :: [Int]) == sort (reverse list)+-- > , LC.testProperty "Fermat's little theorem" $+-- > \x -> ((x :: Integer)^7 - x) `mod` 7 == 0+-- > -- the following property do not hold+-- > , LC.testProperty "Fermat's last theorem" $+-- > \x y z n ->+-- > (n :: Integer) >= 3 LC.==> x^n + y^n /= (z^n :: Integer)+-- > ]+--+-- The output for the above program is:+--+-- > $ ./test+-- > Test properties checked by LeanCheck+-- > sort == sort . reverse: OK+-- > +++ OK, passed 200 tests.+-- > Fermat's little theorem: OK+-- > +++ OK, passed 200 tests.+-- > Fermat's last theorem: FAIL+-- > *** Failed! Falsifiable (after 71 tests):+-- > 0 0 0 3+-- >+-- > 1 out of 3 tests failed (0.00s)+--+-- Use @--leancheck-tests@ to configure the maximum number of tests for each+-- property.+--+-- Please see the documentation of+-- "Test.LeanCheck" and Tasty+-- for more details.+module Test.Tasty.LeanCheck+ ( testProperty+ , LeanCheckTests (..)+ , module Test.LeanCheck+ )+where++import Test.Tasty.Providers hiding (Result)+import Test.Tasty.Options+import Test.LeanCheck+import Data.Proxy+import Control.Exception (SomeException, catch, evaluate)++newtype Results = Results [([String],Bool)]++data Result = OK Int+ | Falsified Int [String]+ | Exception Int [String] String+ deriving (Eq, Show)++-- | Create a 'Test' for a LeanCheck 'Testable' property.+-- Example:+--+-- > LC.testProperty "sort is idempotent" $ \xs -> sort (sort xs :: [Int]) == sort xs+testProperty :: Testable a => TestName -> a -> TestTree+testProperty name = singleTest name . Results . results++-- | Number of test cases for LeanCheck to generate.+newtype LeanCheckTests = LeanCheckTests Int+ deriving (Show, Eq, Ord)++instance IsOption LeanCheckTests where+ defaultValue = LeanCheckTests 200+ parseValue = fmap LeanCheckTests . safeRead+ optionName = return "leancheck-tests"+ optionHelp = return "Depth to use for leancheck tests"++instance IsTest Results where+ testOptions = return [Option (Proxy :: Proxy LeanCheckTests)]+ run opts results _ = resultIO m results >>= \r -> pure $+ case r of+ OK n -> testPassed $ "+++ OK, passed " ++ show n ++ " tests"+ ++ takeWhile (\_ -> n < m) " (exhausted)"+ ++ "."+ Falsified i ce -> testFailed $ "*** Failed! Falsifiable (after "+ ++ show i ++ " tests):\n" ++ joinArgs ce+ Exception i ce e -> testFailed $ "*** Failed! Exception '" ++ e+ ++ "' (after " ++ show i ++ " tests):\n"+ ++ joinArgs ce+ where+ LeanCheckTests m = lookupOption opts++resultsIO :: Int -> Results -> [IO Result]+resultsIO n (Results results) = zipWith torio [1..] $ take n results+ where+ tor i (_,True) = OK i+ tor i (as,False) = Falsified i as+ torio i r@(as,_) = evaluate (tor i r)+ `catch` \e -> let _ = e :: SomeException+ in return (Exception i as (show e))++resultIO :: Int -> Results -> IO Result+resultIO n = computeResult . resultsIO n+ where+ computeResult [] = error "resultIO: no results, empty Listable enumeration?"+ computeResult [r] = r+ computeResult (r:rs) = r >>= \r -> case r of+ (OK _) -> computeResult rs+ _ -> return r++-- joins the counter-example arguments+joinArgs :: [String] -> String+joinArgs ce | any ('\n' `elem`) ce = unlines $ map chopBreak ce+ | otherwise = unwords ce++-- chops a line break at the end if there is any+chopBreak :: String -> String+chopBreak [] = []+chopBreak ['\n'] = []+chopBreak (x:xs) = x:chopBreak xs
+ stack.yaml view
@@ -0,0 +1,15 @@+# stack.yaml docs:+# https://docs.haskellstack.org/en/stable/yaml_configuration/++# resolver: nightly-2015-09-21+# resolver: ghc-7.10.2+resolver: lts-12.7++packages:+- .++extra-deps: []++flags: {}++extra-package-dbs: []
+ tasty-leancheck.cabal view
@@ -0,0 +1,62 @@+-- Cabal file for tasty-leancheck+name: tasty-leancheck+version: 0.0.1+synopsis: LeanCheck support for the Tasty test framework.+description:+ LeanCheck support for the Tasty test framework.+ .+ This package can be used to incorporate LeanCheck tests into Tasty test+ suites by means of the @Test.Tasty.LeanCheck.testProperty@ function.+ .+ Please see the Haddock documentation and README for more details.++homepage: https://github.com/rudymatela/tasty-leancheck#readme+license: BSD3+license-file: LICENSE+author: Rudy Matela <rudy@matela.com.br>+maintainer: Rudy Matela <rudy@matela.com.br>+category: Testing+build-type: Simple+cabal-version: 1.18++extra-doc-files: README.md+ , TODO.md+extra-source-files: .gitignore+ , eg/minimal.hs+ , Makefile+ , mk/depend.mk+ , mk/haskell.mk+ , mk/ghcdeps+ , mk/haddock-i+ , mk/All.hs+ , mk/Toplibs.hs+ , stack.yaml+ , tests/test-sdist+ , .travis.yml+tested-with: GHC==8.4+ , GHC==8.2+ , GHC==8.0+ , GHC==7.10+++source-repository head+ type: git+ location: https://github.com/rudymatela/tasty-leancheck++source-repository this+ type: git+ location: https://github.com/rudymatela/tasty-leancheck+ tag: v0.0.1++library+ exposed-modules: Test.Tasty.LeanCheck+ hs-source-dirs: src+ build-depends: base >= 4 && < 5, tasty, leancheck+ default-language: Haskell2010++test-suite test+ type: exitcode-stdio-1.0+ main-is: test.hs+ hs-source-dirs: tests+ build-depends: base >= 4 && < 5, tasty, leancheck, tasty-leancheck+ default-language: Haskell2010
+ tests/test-sdist view
@@ -0,0 +1,28 @@+#!/bin/bash+#+# test-sdist: tests the package generated by "cabal sdist".+#+# Copyright (c) 2015-2018 Rudy Matela.+# Distributed under the 3-Clause BSD licence.+pkgver=` cat *.cabal | grep "^version:" | sed -e "s/version: *//"`+pkgname=`cat *.cabal | grep "^name:" | sed -e "s/name: *//"`+pkg=$pkgname-$pkgver+set -x+cabal sdist &&+cd dist &&+if [ -d ../.git ]+then+ # on git repo, test if files are the same+ git -C .. ls-files | sort > ls-git &&+ tar -tf $pkg.tar.gz | grep -v "/$" | sed -e "s,$pkg/,," | sort > ls-cabal &&+ diff -rud ls-git ls-cabal &&+ rm -f ls-git ls-cabal+else+ # outside of git repo, test build+ rm -rf $pkg/ &&+ tar -xzf $pkg.tar.gz &&+ cd $pkg/ &&+ cabal configure --enable-tests --enable-benchmarks &&+ cabal build &&+ cabal test+fi
+ tests/test.hs view
@@ -0,0 +1,39 @@+-- Copyright (c) 2018 Rudy Matela.+-- Distributed under the 3-Clause BSD licence (see the file LICENSE).+{-# LANGUAGE CPP #-}+import Test.Tasty+import Test.Tasty.LeanCheck as LC++import Data.List (sort)++main :: IO ()+main = defaultMain tests++tests :: TestTree+tests = testGroup "Tests (checked by LeanCheck)" [passing]+-- tests = testGroup "Tests (checked by LeanCheck)" [passing,failing,erroring]++-- tests that pass+passing :: TestTree+passing = testGroup "Passing tests"+ [ LC.testProperty "sort . sort == sort" $+ \xs -> sort (sort xs :: [Int]) == sort xs+ , LC.testProperty "Fermat's little theorem" $+ \x -> ((x :: Integer)^7 - x) `mod` 7 == 0+ , LC.testProperty "divMod" $+ \x y -> y /= 0 ==> y * (x `div` y) + x `mod` y == (x :: Int)+ ]++-- tests that fail (and should)+failing :: TestTree+failing = testGroup "Failing tests"+ [ LC.testProperty "Fermat's last theorem" $+ \x y z n -> (n :: Integer) >= 3 ==> x^n + y^n /= (z^n :: Integer)+ ]++-- tests that err (and should)+erroring :: TestTree+erroring = testGroup "Erroring tests"+ [ LC.testProperty "divMod (unguarded)" $+ \x y -> y * (x `div` y) + x `mod` y == (x :: Int)+ ]