test-framework-leancheck 0.0.1 → 0.0.2
raw patch · 16 files changed
+312/−152 lines, 16 files
Files
- .github/workflows/build.yml +122/−0
- .gitignore +2/−0
- .travis.yml +0/−65
- Makefile +8/−6
- README.md +3/−3
- mk/depend.mk +5/−8
- mk/ghcdeps +2/−1
- mk/haddock-i +20/−8
- mk/haskell.mk +35/−6
- mk/install-on +33/−0
- src/Test/Framework/Providers/LeanCheck.hs +13/−3
- test-framework-leancheck.cabal +11/−6
- test/sdist +40/−0
- test/test.hs +18/−0
- tests/test-sdist +0/−28
- tests/test.hs +0/−18
+ .github/workflows/build.yml view
@@ -0,0 +1,122 @@+# Builds and tests this Haskell project on "GitHub Actions"+#+# 2021 Rudy Matela+#+# some docs: https://github.com/haskell/actions/tree/main/setup+name: build+on: [push]+jobs:+ build-and-test:+ runs-on: ubuntu-latest+ steps:++ - name: Cache ~/.cabal/packages+ uses: actions/cache@v2+ with:+ path: ~/.cabal/packages+ key: v1-${{ runner.os }}-cabal-packages-${{ hashFiles('hello.cabal') }}+ restore-keys: v1-${{ runner.os }}-cabal-packages-++ - name: Cache ~/.cabal and ~/.ghc+ uses: actions/cache@v2+ with:+ path: |+ ~/.cabal+ !~/.cabal/packages+ ~/.ghc+ key: v1-${{ runner.os }}-cabal-ghc-latest-${{ hashFiles('hello.cabal') }}+ restore-keys: v1-${{ runner.os }}-cabal-ghc-latest-++ - run: du -hd3 ~/.cabal ~/.ghc || true++ - run: haddock --version || sudo apt-get install ghc-haddock+ - run: ghc --version+ - run: cabal --version++ - name: Check out repository+ uses: actions/checkout@v2++ - run: cabal update+ - run: make install-dependencies++ - run: make+ - run: make test+ - run: make haddock+ - run: make test-sdist+ - run: make test-via-cabal+++ test-with-ghc:+ strategy:+ matrix:+ ghc:+ - '9.0'+ - '8.10'+ - '8.8'+ - '8.6'+ - '8.4'+ - '8.2'+ - '8.0'+ - '7.10'+ - '7.8'+ runs-on: ubuntu-latest+ needs: build-and-test+ container: haskell:${{ matrix.ghc }}+ steps:+ - name: Cache ~/.cabal/packages+ uses: actions/cache@v2+ with:+ path: ~/.cabal/packages+ key: v1-${{ runner.os }}-cabal-packages-${{ hashFiles('hello.cabal') }}+ restore-keys: v1-${{ runner.os }}-cabal-packages-++ - name: Cache ~/.cabal and ~/.ghc+ uses: actions/cache@v2+ with:+ path: |+ ~/.cabal+ !~/.cabal/packages+ ~/.ghc+ key: v1-${{ runner.os }}-cabal-ghc-${{ matrix.ghc }}-${{ hashFiles('hello.cabal') }}+ restore-keys: v1-${{ runner.os }}-cabal-ghc-${{ matrix.ghc }}-++ - run: du -hd3 ~/.cabal ~/.ghc || true++ - run: make --version || rm /etc/apt/sources.list.d/*.list # faster update+ - run: make --version || apt-get update+ - run: make --version || apt-get install make++ - run: ghc --version+ - run: cabal --version++ - name: Check out repository+ uses: actions/checkout@v2++ - run: cabal update+ - run: make install-dependencies++ - run: make+ - run: make test+ - run: make haddock+ - run: make test-sdist+ - run: make test-via-cabal++ test-with-stack:+ runs-on: ubuntu-latest+ needs: build-and-test+ steps:+ - name: Setup Haskell's GHC and Cabal as required by current Stackage LTS+ uses: haskell/actions/setup@v1+ with: # lts-17.9+ ghc-version: '8.10.4'+ cabal-version: '3.2'++ - uses: actions/cache@v2+ with:+ path: ~/.stack+ key: v1-${{ runner.os }}-stack-${{ hashFiles('stack.yaml') }}+ restore-keys: v1-${{ runner.os }}-stack-++ - name: Check out repository+ uses: actions/checkout@v2+ - run: make test-via-stack
.gitignore view
@@ -3,6 +3,7 @@ .stack-work idx/ dist/+dist-newstyle/ log/ doc/ *.swp@@ -21,4 +22,5 @@ doc/*.gif mk/toplibs eg/minimal+test/test README.html
− .travis.yml
@@ -1,65 +0,0 @@-# .travis.yml file for test-framework-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 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
Makefile view
@@ -4,13 +4,13 @@ # License: 3-Clause BSD (see the file LICENSE) # Maintainer: Rudy Matela <rudy@matela.com.br> TESTS = \- tests/test+ test/test EGS = \ eg/minimal BENCHS = GHCIMPORTDIRS = src GHCFLAGS = -O2 $(shell grep -q "Arch Linux" /etc/lsb-release && echo -dynamic)-HADDOCKFLAGS = --no-print-missing-docs \+HADDOCKFLAGS = \ $(shell grep -q "Arch Linux" /etc/lsb-release && echo --optghc=-dynamic) all: mk/toplibs@@ -31,13 +31,15 @@ @echo "use \`cabal install' instead" test-sdist:- ./tests/test-sdist+ ./test/sdist test-via-cabal:- cabal test+ cabal configure --enable-tests --enable-benchmarks --ghc-options="$(GHCFLAGS) -O0"+ cabal build+ cabal test test test-via-stack:- stack test+ stack test test-framework-leancheck:test:test --ghc-options="$(GHCFLAGS) -O0" --system-ghc --no-install-ghc --no-terminal test-via-everything: test test-via-cabal test-via-stack @@ -72,7 +74,7 @@ # 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+# in src/ and test/. Runnable binaries should depend on mk/toplibs instead of # actual Haskell source files mk/toplibs: mk/Toplibs.o touch mk/toplibs
README.md view
@@ -71,7 +71,7 @@ ``` Since LeanCheck is enumerative,-you may want to increate the default number of tests (100).+you may want to increase the default number of tests (100). Arbitrary rule of thumb: * between 200 to 500 on a developer machine;@@ -100,8 +100,8 @@ [test-framework]: https://github.com/haskell/test-framework [LeanCheck]: https://github.com/rudymatela/leancheck -[build-status]: https://travis-ci.org/rudymatela/test-framework-leancheck.svg?branch=master-[build-log]: https://travis-ci.org/rudymatela/test-framework-leancheck+[build-log]: https://github.com/rudymatela/test-framework-leancheck/actions/workflows/build.yml+[build-status]: https://github.com/rudymatela/test-framework-leancheck/actions/workflows/build.yml/badge.svg [hackage-version]: https://img.shields.io/hackage/v/test-framework-leancheck.svg [test-framework-leancheck-on-hackage]: https://hackage.haskell.org/package/test-framework-leancheck [stackage-lts-badge]: http://stackage.org/package/test-framework-leancheck/badge/lts
mk/depend.mk view
@@ -10,16 +10,13 @@ mk/Toplibs.o: \ src/Test/Framework/Providers/LeanCheck.hs \ mk/Toplibs.hs-Setup.o: \- Setup.hs-Setup: \- Setup.hs \+src/Test/Framework/Providers/LeanCheck: \ mk/toplibs src/Test/Framework/Providers/LeanCheck.o: \ src/Test/Framework/Providers/LeanCheck.hs-tests/test.o: \- tests/test.hs \+test/test.o: \+ test/test.hs \ src/Test/Framework/Providers/LeanCheck.hs-tests/test: \- tests/test.hs \+test/test: \+ test/test.hs \ mk/toplibs
mk/ghcdeps view
@@ -2,7 +2,7 @@ # # ghcdeps: generate Haskell make dependencies for compiling with GHC. #-# Copyright (c) 2015-2018 Rudy Matela.+# Copyright (c) 2015-2021 Rudy Matela. # Distributed under the 3-Clause BSD licence. # # From a list of files provided on standard input,@@ -46,4 +46,5 @@ rm -f tmp.mk done | sort |+grep -v "^Loaded package environment from " | sed -e 's, *, \\\n ,g'
mk/haddock-i view
@@ -2,7 +2,7 @@ # # haddock-i: list haddock's -i parameters. #-# Copyright (c) 2015-2018 Rudy Matela.+# Copyright (c) 2015-2021 Rudy Matela. # Distributed under the 3-Clause BSD licence. # # $ haddock-i <package1> <package2> ... <packageN>@@ -11,14 +11,26 @@ # documentation installed on your system, so you can: # # $ haddock-i base template-haskell | xargs haddock <files>-errxit() {+err() { echo "$@" > /dev/stderr+}++errxit() {+ err "$@" 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/"+iface-for() {+ ghc-pkg field $1 haddock-interfaces | sort -rV | head -1 | sed "s/.*: //"+}++html-for() {+ ghc-pkg field $1 haddock-html | sort -rV | head -1 | sed "s/.*: //"+}++for pkg in "$@"+do+ iface=$(iface-for $pkg)+ html=$(html-for $pkg)+ [ -d "$html" -a -f "$iface" ] && echo "-i$html,$iface" || err "haddock-i: warning: could not find interface file for $pkg"+done
mk/haskell.mk view
@@ -1,6 +1,6 @@ # Implicit rules for compiling Haskell code. #-# Copyright (c) 2015-2018 Rudy Matela.+# Copyright (c) 2015-2021 Rudy Matela. # Distributed under the 3-Clause BSD licence. # # You can optionally configure the "Configuration variables" below in your main@@ -20,6 +20,8 @@ GHCFLAGS ?= GHC ?= ghc GHCCMD = $(GHC) -i$(GHCIMPORTDIRS) $(GHCFLAGS)+HADDOCK ?= haddock+CABAL_INSTALL = $(shell cabal --version | grep -q "version [0-2]\." && echo 'cabal install' || echo 'cabal v1-install') # Hugs Parameters HUGSIMPORTDIRS ?= "/usr/lib/hugs/packages/*"@@ -38,14 +40,20 @@ # 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 \+LIST_ALL_HSS ?= find \( -path "./dist*" -o -path "./.stack-work" -o -path "./Setup.hs" \) -prune \ -o -name "*.*hs" -print LIB_HSS ?= $(shell $(LIST_LIB_HSS)) ALL_HSS ?= $(shell $(LIST_ALL_HSS)) +LIB_DEPS ?= base+ALL_DEPS ?= $(LIB_DEPS)+INSTALL_DEPS ?=+ PKGNAME = $(shell cat *.cabal | grep "^name:" | sed -e "s/name: *//") +HADDOCK_HAS = haddock --help | grep -q -- + # Implicit rules %.hi %.o: %.hs $(GHCCMD) $< && touch $@@@ -67,7 +75,8 @@ # Cleaning rule (add as a clean dependency)-.PHONY: clean-hi-o+clean-hs: clean-hi-o clean-haddock clean-cabal clean-stack+ 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@@ -80,11 +89,14 @@ depend: find $(ALL_HSS) | ./mk/ghcdeps -i$(GHCIMPORTDIRS) $(GHCFLAGS) > $(DEPMK) +install-dependencies:+ $(CABAL_INSTALL) $(INSTALL_DEPS)+ # haddock rules haddock: doc/index.html clean-haddock:- rm -f doc/*.{html,css,js,png,gif,json} README.html+ rm -f doc/*.{html,css,js,png,gif,json} doc/src/* README.html upload-haddock: @echo "use \`cabal upload -d' instead"@@ -93,9 +105,20 @@ @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)+ ./mk/haddock-i $(LIB_DEPS) | xargs \+ $(HADDOCK) --html -odoc $(LIB_HSS) \+ --title=$(PKGNAME) \+ $(shell $(HADDOCK_HAS) --package-name && echo "--package-name=$(PKGNAME)" ) \+ $(shell $(HADDOCK_HAS) --hyperlinked-source && echo "--hyperlinked-source" ) \+ $(shell $(HADDOCK_HAS) --no-print-missing-docs && echo --no-print-missing-docs ) \+ $(HADDOCKFLAGS) +clean-cabal:+ rm -rf dist/ dist-newstyle/ cabal.project.local cabal.project.local~++clean-stack:+ rm -rf .stack-work/ stack.yaml.lock+ # lists all Haskell source files list-all-hss: @find $(ALL_HSS)@@ -103,6 +126,12 @@ # lists library Haskell source files list-lib-hss: @find $(LIB_HSS)++bootstrap-haskell-mk:+ @[ -d "$(DEST)" ] || (echo -e "error: no destination found\nusage: \`make bootstrap-haskell-mk DEST=path/to/prj'"; exit 1)+ mkdir -p mk+ cp mk/{haskell.mk,ghcdeps,haddock-i} $(DEST)/mk+ touch $(DEST)/mk/depend.mk show-pkgname: @echo $(PKGNAME)
+ mk/install-on view
@@ -0,0 +1,33 @@+#!/bin/bash+#+# mk/install-on: install or updates the mk folder on a Haskell project+#+# Copyright (c) 2019-2021 Rudy Matela.+# Distributed under the 3-Clause BSD licence.+#+# usage: ./mk/install-on path/to/project+#+# This script assumes that:+#+# * tests are stored in a "test/" folder+# * sources are stored in a "src/" folder+set -e++errxit() {+ echo "$@" > /dev/stderr+ exit 1+}++src=`dirname $0`/..+dst="$1"++[ -n "$dst" ] || errxit "destination folder not provided"++mkdir -p $dst/mk+mkdir -p $dst/test++cp $src/mk/ghcdeps $dst/mk/ghcdeps+cp $src/mk/haddock-i $dst/mk/haddock-i+cp $src/mk/haskell.mk $dst/mk/haskell.mk+cp $src/mk/install-on $dst/mk/install-on+cp $src/test/sdist $dst/test/sdist
src/Test/Framework/Providers/LeanCheck.hs view
@@ -1,4 +1,7 @@-{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE MultiParamTypeClasses, CPP #-}+#if __GLASGOW_HASKELL__ == 708+{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}+#endif -- | -- Module : Test.Framework.Providers.LeanCheck -- Copyright : (c) 2018 Rudy Matela@@ -50,7 +53,7 @@ -- > Total 2 2 -- -- Since LeanCheck is enumerative,--- you may want to increate the default number of tests (100).+-- you may want to increase the default number of tests (100). -- Arbitrary rule of thumb: -- -- * between 200 to 500 on a developer machine;@@ -59,7 +62,7 @@ -- Your mileage may vary. -- -- Please see the documentation of--- "Test.LeanCheck" and "Framework.Providers"+-- "Test.LeanCheck" and "Test.Framework.Providers" -- for more details. module Test.Framework.Providers.LeanCheck ( testProperty@@ -69,9 +72,16 @@ import Test.Framework.Providers.API import Test.LeanCheck import Control.Exception (SomeException, catch, evaluate)+#if __GLASGOW_HASKELL__ == 708+import Data.Typeable (Typeable)+#endif -- | List of test results for a given property newtype Results = Results [([String],Bool)]++#if __GLASGOW_HASKELL__ == 708+deriving instance Typeable Results+#endif -- | The ultimate test result for a given property data Result = OK Int
test-framework-leancheck.cabal view
@@ -1,6 +1,6 @@ -- Cabal file for test-framework-leancheck name: test-framework-leancheck-version: 0.0.1+version: 0.0.2 synopsis: LeanCheck support for test-framework. description: LeanCheck support for test-framework.@@ -31,10 +31,15 @@ , mk/haddock-i , mk/All.hs , mk/Toplibs.hs+ , mk/install-on , stack.yaml- , tests/test-sdist- , .travis.yml-tested-with: GHC==8.4+ , test/sdist+ , .github/workflows/build.yml+tested-with: GHC==9.0+ , GHC==8.10+ , GHC==8.8+ , GHC==8.6+ , GHC==8.4 , GHC==8.2 , GHC==8.0 , GHC==7.10@@ -47,7 +52,7 @@ source-repository this type: git location: https://github.com/rudymatela/test-framework-leancheck- tag: v0.0.1+ tag: v0.0.2 library exposed-modules: Test.Framework.Providers.LeanCheck@@ -58,6 +63,6 @@ test-suite test type: exitcode-stdio-1.0 main-is: test.hs- hs-source-dirs: tests+ hs-source-dirs: test build-depends: base >= 4 && < 5, test-framework, leancheck, test-framework-leancheck default-language: Haskell2010
+ test/sdist view
@@ -0,0 +1,40 @@+#!/bin/bash+#+# test/sdist: tests the package generated by "cabal sdist".+#+# Copyright (c) 2015-2021 Rudy Matela.+# Distributed under the 3-Clause BSD licence.++set -xe++export LC_ALL=C # consistent sort++pkgver=` cat *.cabal | grep "^version:" | sed -e "s/version: *//"`+pkgname=`cat *.cabal | grep "^name:" | sed -e "s/name: *//"`+pkgbase=$pkgname-$pkgver++cabal sdist++# Try to find the package generated by cabal.+pkg=`find dist* -name $pkgbase.tar.gz`+[ -f "$pkg" ]+# If the script fails here, either:+# * no package was generated+# * there are packages in both dist and dist-newstyle folders.++tmp=`mktemp -d /tmp/test-sdist-XXXXXXXXXX`++# Test if our file is compatible with case-insensitive filesystems.+tar -tf $pkg | sort --ignore-case > $tmp/ls-cabal-i+tar -tf $pkg | sort --ignore-case --unique > $tmp/ls-cabal-iu+diff -rud $tmp/ls-cabal-i $tmp/ls-cabal-iu++if [ -d .git ]+then+ # Test if files included by cabal are the same as files tracked in git.+ git ls-files | sort > $tmp/ls-git+ tar -tf $pkg | grep -v "/$" | sed -e "s,$pkgbase/,," | sort > $tmp/ls-cabal+ diff -rud $tmp/ls-git $tmp/ls-cabal+fi++rm -r $tmp
+ test/test.hs view
@@ -0,0 +1,18 @@+-- Copyright (c) 2018 Rudy Matela.+-- Distributed under the 3-Clause BSD licence (see the file LICENSE).+{-# LANGUAGE CPP #-}+import Test.Framework+import Test.Framework.Providers.LeanCheck as LC++import Data.List (sort)++main :: IO ()+main = defaultMain tests++tests :: [Test]+tests =+ [ testProperty "sort . sort == sort"+ $ \xs -> sort (sort xs :: [Int]) == sort xs+ , testProperty "x + x == 2 * x"+ $ \x -> x + x == 2 * (x :: Int)+ ]
− tests/test-sdist
@@ -1,28 +0,0 @@-#!/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
@@ -1,18 +0,0 @@--- Copyright (c) 2018 Rudy Matela.--- Distributed under the 3-Clause BSD licence (see the file LICENSE).-{-# LANGUAGE CPP #-}-import Test.Framework-import Test.Framework.Providers.LeanCheck as LC--import Data.List (sort)--main :: IO ()-main = defaultMain tests--tests :: [Test]-tests =- [ testProperty "sort . sort == sort"- $ \xs -> sort (sort xs :: [Int]) == sort xs- , testProperty "x + x == 2 * x"- $ \x -> x + x == 2 * (x :: Int)- ]