hspec-leancheck (empty) → 0.0.1
raw patch · 22 files changed
+844/−0 lines, 22 filesdep +HUnitdep +basedep +hspecsetup-changed
Dependencies added: HUnit, base, hspec, hspec-core, hspec-leancheck, leancheck
Files
- .gitignore +26/−0
- .travis.yml +65/−0
- LICENSE +30/−0
- Makefile +84/−0
- README.md +99/−0
- Setup.hs +2/−0
- TODO.md +7/−0
- eg/minimal.hs +20/−0
- eg/should.hs +20/−0
- hspec-leancheck.cabal +71/−0
- mk/All.hs +6/−0
- mk/Toplibs.hs +4/−0
- mk/depend.mk +39/−0
- mk/ghcdeps +49/−0
- mk/haddock-i +24/−0
- mk/haskell.mk +110/−0
- src/Test/Hspec/LeanCheck.hs +90/−0
- stack-lts-11.yaml +15/−0
- stack.yaml +15/−0
- tests/should.hs +20/−0
- tests/test-sdist +28/−0
- tests/test.hs +20/−0
+ .gitignore view
@@ -0,0 +1,26 @@+.cabal-sandbox+cabal.sandbox.config+.stack-work+idx/+dist/+log/+doc/+*.swp+*.swo+*.swn+*.swm+*.o+*.hi+*.dyn_hi+*.dyn_o+tests/test+tests/should+doc/*.html+doc/*.css+doc/*.js+doc/*.png+doc/*.gif+mk/toplibs+eg/minimal+eg/should+README.html
+ .travis.yml view
@@ -0,0 +1,65 @@+# .travis.yml file for hspec-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 --only-dependencies++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 STACK_YAML=stack-lts-11.yaml+ 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 STACK_YAML=stack-lts-11.yaml+ 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,84 @@+# Makefile for hspec-leancheck+#+# Copyright: (c) 2015-2018 Rudy Matela+# License: 3-Clause BSD (see the file LICENSE)+# Maintainer: Rudy Matela <rudy@matela.com.br>+TESTS = \+ tests/should \+ tests/test+EGS = \+ eg/minimal \+ eg/should+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 $(TESTS) $(EGS)++test: $(patsubst %,%.test,$(TESTS))++%.test: %+ ./$<++eg: $(EGS)++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,99 @@+hspec-leancheck: LeanCheck support for Hspec+============================================++[![hspec-leancheck's Build Status][build-status]][build-log]+[![hspec-leancheck on Hackage][hackage-version]][hspec-leancheck-on-hackage]+[![hspec-leancheck on Stackage LTS][stackage-lts-badge]][hspec-leancheck-on-stackage-lts]+[![hspec-leancheck on Stackage Nightly][stackage-nightly-badge]][hspec-leancheck-on-stackage-nightly]++[LeanCheck] support for the [Hspec] test framework.+++Installing+----------++ $ cabal install hspec-leancheck+++Example+-------++Here's how your `spec.hs` might look like:++```haskell+import Test.Hspec+import Test.Hspec.LeanCheck as LC++import Data.List (sort)++main :: IO ()+main = hspec spec++spec :: Spec+spec = do+ describe "sort" $ do+ it "is idempotent" $+ LC.property $ \xs -> sort (sort xs :: [Int]) == sort xs+ it "is identity" $ -- not really+ LC.property $ \xs -> sort (xs :: [Int]) == xs+```++And here is the output for the above program:++```+$ ./eg/minimal++sort+ is idempotent+ is identity FAILED [1]++Failures:++ eg/minimal.hs:17:5: + 1) sort is identity+ [1,0]++ To rerun use: --match "/sort/is identity/"++Randomized with seed 44182769++Finished in 0.0008 seconds+2 examples, 1 failure+```+++Options+-------++Use `propertyWith` to configure the number of tests.+++Further reading+---------------++* [hspec-leancheck's Haddock documentation];+* [LeanCheck's Haddock documentation];+* [Hspec's Haddock documentation];+* [LeanCheck's README];+* [Hspec's README];+* [Tutorial on property-based testing with LeanCheck].++[hspec-leancheck's Haddock documentation]: https://hackage.haskell.org/package/hspec-leancheck/docs/Test-Hspec-LeanCheck.html+[LeanCheck's Haddock documentation]: https://hackage.haskell.org/package/leancheck/docs/Test-LeanCheck.html+[Hspec's Haddock documentation]: https://hackage.haskell.org/package/hspec/docs/Test-Hspec.html+[LeanCheck's README]: https://github.com/rudymatela/leancheck#readme+[Hspec's README]: https://github.com/hspec/hspec#readme+[tutorial on property-based testing with LeanCheck]: https://github.com/rudymatela/leancheck/blob/master/doc/tutorial.md++[Hspec]: https://hspec.github.io/+[LeanCheck]: https://github.com/rudymatela/leancheck++[build-status]: https://travis-ci.org/rudymatela/hspec-leancheck.svg?branch=master+[build-log]: https://travis-ci.org/rudymatela/hspec-leancheck+[hackage-version]: https://img.shields.io/hackage/v/hspec-leancheck.svg+[hspec-leancheck-on-hackage]: https://hackage.haskell.org/package/hspec-leancheck+[stackage-lts-badge]: http://stackage.org/package/hspec-leancheck/badge/lts+[stackage-nightly-badge]: http://stackage.org/package/hspec-leancheck/badge/nightly+[hspec-leancheck-on-stackage]: http://stackage.org/package/hspec-leancheck+[hspec-leancheck-on-stackage-lts]: http://stackage.org/lts/package/hspec-leancheck+[hspec-leancheck-on-stackage-nightly]: http://stackage.org/nightly/package/hspec-leancheck
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ TODO.md view
@@ -0,0 +1,7 @@+TO DO list for hspec-leancheck+==============================++For now, the following should suffice:++ $ alias lstodo='grep --color -nREi "TODO(:|\{)" *'+ $ lstodo
+ eg/minimal.hs view
@@ -0,0 +1,20 @@+-- Copyright (c) 2018 Rudy Matela.+-- Distributed under the 3-Clause BSD licence (see the file LICENSE).+{-# LANGUAGE CPP #-}+import Test.Hspec+import Test.Hspec.LeanCheck as LC++import Data.List (sort)++main :: IO ()+main = hspec spec++spec :: Spec+spec = do+ describe "sort" $ do+ it "is idempotent" $+ LC.property $ \xs -> sort (sort xs :: [Int]) == sort xs+ it "is identity" $ -- not really+ LC.property $ \xs -> sort (xs :: [Int]) == xs+ it "head is minimum" $ -- not really, error+ LC.property $ \xs -> head (sort xs :: [Int]) == minimum xs
+ eg/should.hs view
@@ -0,0 +1,20 @@+-- Copyright (c) 2018 Rudy Matela.+-- Distributed under the 3-Clause BSD licence (see the file LICENSE).+{-# LANGUAGE CPP #-}+import Test.Hspec+import Test.Hspec.LeanCheck as LC++import Data.List (sort)++main :: IO ()+main = hspec spec++spec :: Spec+spec = do+ describe "sort" $ do+ it "is idempotent" $+ LC.property $ \xs -> sort (sort xs :: [Int]) `shouldBe` sort xs+ it "is identity" $ -- not really+ LC.property $ \xs -> sort (xs :: [Int]) `shouldBe` xs+ it "head is minimum" $ -- not really, error+ LC.property $ \xs -> head (sort xs :: [Int]) `shouldBe` minimum xs
+ hspec-leancheck.cabal view
@@ -0,0 +1,71 @@+-- Cabal file for hspec-leancheck+name: hspec-leancheck+version: 0.0.1+synopsis: LeanCheck support for the Hspec test framework.+description:+ LeanCheck support for the Hspec test framework.+ .+ This package can be used to incorporate LeanCheck tests into Hspec test+ suites by means of the @Test.Hspec.LeanCheck.testProperty@ function.+ .+ Please see the Haddock documentation and README for more details.++homepage: https://github.com/rudymatela/hspec-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+ , eg/should.hs+ , Makefile+ , mk/depend.mk+ , mk/haskell.mk+ , mk/ghcdeps+ , mk/haddock-i+ , mk/All.hs+ , mk/Toplibs.hs+ , stack.yaml+ , stack-lts-11.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/hspec-leancheck++source-repository this+ type: git+ location: https://github.com/rudymatela/hspec-leancheck+ tag: v0.0.1++library+ exposed-modules: Test.Hspec.LeanCheck+ hs-source-dirs: src+ build-depends: base >= 4 && < 5, hspec >= 2.5, hspec-core, leancheck, HUnit+ default-language: Haskell2010++test-suite test+ type: exitcode-stdio-1.0+ main-is: test.hs+ hs-source-dirs: tests+ build-depends: base >= 4 && < 5, hspec, leancheck, hspec-leancheck+ default-language: Haskell2010++test-suite should+ type: exitcode-stdio-1.0+ main-is: should.hs+ hs-source-dirs: tests+ build-depends: base >= 4 && < 5, hspec, leancheck, hspec-leancheck+ default-language: Haskell2010
+ mk/All.hs view
@@ -0,0 +1,6 @@+module All+ ( module Test.Hspec.LeanCheck+ )+where++import Test.Hspec.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.Hspec.LeanCheck ()
+ mk/depend.mk view
@@ -0,0 +1,39 @@+eg/minimal: \+ eg/minimal.hs \+ mk/toplibs+eg/minimal.o: \+ src/Test/Hspec/LeanCheck.hs \+ eg/minimal.hs+eg/should: \+ eg/should.hs \+ mk/toplibs+eg/should.o: \+ src/Test/Hspec/LeanCheck.hs \+ eg/should.hs+mk/All.o: \+ src/Test/Hspec/LeanCheck.hs \+ mk/All.hs+mk/Toplibs.o: \+ src/Test/Hspec/LeanCheck.hs \+ mk/Toplibs.hs+Setup.o: \+ Setup.hs+Setup: \+ Setup.hs \+ mk/toplibs+src/Test/Hspec/LeanCheck: \+ mk/toplibs+src/Test/Hspec/LeanCheck.o: \+ src/Test/Hspec/LeanCheck.hs+tests/should.o: \+ tests/should.hs \+ src/Test/Hspec/LeanCheck.hs+tests/should: \+ tests/should.hs \+ mk/toplibs+tests/test.o: \+ tests/test.hs \+ src/Test/Hspec/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/Hspec/LeanCheck.hs view
@@ -0,0 +1,90 @@+-- |+-- Module : Test.Hspec.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 Hspec test framework.+--+-- Here's how your @spec.hs@ might look like:+--+-- > import Test.Hspec+-- > import Test.Hspec.LeanCheck as LC+-- >+-- > import Data.List (sort)+-- >+-- > main :: IO ()+-- > main = hspec spec+-- >+-- > spec :: Spec+-- > spec = do+-- > describe "sort" $ do+-- > it "is idempotent" $+-- > LC.property $ \xs -> sort (sort xs :: [Int]) == sort xs+-- > it "is identity" $ -- not really+-- > LC.property $ \xs -> sort (xs :: [Int]) == xs+--+-- The output for the above program is:+--+-- > $ ./eg/minimal+-- >+-- > sort+-- > is idempotent+-- > is identity FAILED [1]+-- >+-- > Failures:+-- >+-- > eg/minimal.hs:17:5:+-- > 1) sort is identity+-- > [1,0]+-- >+-- > To rerun use: --match "/sort/is identity/"+-- >+-- > 2 examples, 1 failure+--+-- Please see the documentation of+-- "Test.LeanCheck" and Hspec+-- for more details.+module Test.Hspec.LeanCheck+ ( property+ , propertyWith+ , module Test.LeanCheck+ )+where++import Test.Hspec.Core.Spec+import Test.LeanCheck+import Test.LeanCheck.Core (resultiers)+import Control.Exception (try)+import System.IO.Unsafe (unsafePerformIO) -- LeanCheck is pure+import qualified Test.HUnit.Lang as HUnit+import Data.Maybe (fromMaybe)++data Property = Ok+ | Failed String++-- TODO: catch errors+propertyWith :: Testable a => Int -> a -> Property+propertyWith m p = case counterExample m p of+ Nothing -> Ok+ Just ce -> Failed $ unwords ce++property :: Testable a => a -> Property+property = propertyWith 200++instance Example Property where+ evaluateExample p _ _ _ = return . Result ""+ $ case p of+ Ok -> Success+ Failed s -> Failure Nothing (Reason s)++instance Testable (IO a) where+ resultiers action = unsafePerformIO $ do+ r <- try action+ return . (:[]) . (:[]) $ case r of+ Right _ -> ([],True)+ Left (HUnit.HUnitFailure loc reason) ->+ case reason of+ HUnit.Reason s -> (["--", s],False)+ HUnit.ExpectedButGot prefix expected actual ->+ ([fromMaybe "" prefix, "--", "expected", expected, "but got", actual], False)
+ stack-lts-11.yaml view
@@ -0,0 +1,15 @@+# stack.yaml for hspec-leancheck+resolver: lts-11.22++packages:+- .++extra-deps:+- hspec-2.5.6+- hspec-core-2.5.6+- hspec-discover-2.5.6+- QuickCheck-2.12.1++flags: {}++extra-package-dbs: []
+ 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: []
+ tests/should.hs view
@@ -0,0 +1,20 @@+-- Copyright (c) 2018 Rudy Matela.+-- Distributed under the 3-Clause BSD licence (see the file LICENSE).+{-# LANGUAGE CPP #-}+import Test.Hspec+import Test.Hspec.LeanCheck as LC++import Data.List (sort)++main :: IO ()+main = hspec spec++spec :: Spec+spec = do+ describe "sort" $ do+ it "is idempotent" $+ LC.property $ \xs -> sort (sort xs :: [Int]) `shouldBe` sort xs+ it "preserves length" $+ LC.property $ \xs -> length (sort xs :: [Int]) `shouldBe` length xs+ it "preserves membership" $+ LC.property $ \x xs -> (x `elem` (sort xs :: [Int])) `shouldBe` (x `elem` xs)
+ 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,20 @@+-- Copyright (c) 2018 Rudy Matela.+-- Distributed under the 3-Clause BSD licence (see the file LICENSE).+{-# LANGUAGE CPP #-}+import Test.Hspec+import Test.Hspec.LeanCheck as LC++import Data.List (sort)++main :: IO ()+main = hspec spec++spec :: Spec+spec = do+ describe "sort" $ do+ it "is idempotent" $+ LC.property $ \xs -> sort (sort xs :: [Int]) == sort xs+ it "preserves length" $+ LC.property $ \xs -> length (sort xs :: [Int]) == length xs+ it "preserves membership" $+ LC.property $ \x xs -> (x `elem` (sort xs :: [Int])) == (x `elem` xs)