Skip to content

Commit

Permalink
Add test-hugs script
Browse files Browse the repository at this point in the history
- To make it work properly, I had to move sources away into src/ directory
- `test-hugs` is run as part of CI, to configure that `cabal.haskell-ci`
  I added `cabal.haskell-ci` file
- I also modified `make-hugs` so ShellCheck is happy
  • Loading branch information
phadej committed Apr 16, 2020
1 parent 62e32e0 commit ef96526
Show file tree
Hide file tree
Showing 25 changed files with 266 additions and 143 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
\#*
.\#*
*.swp

quickcheck-hugs/
hugs.output
347 changes: 211 additions & 136 deletions .travis.yml

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion QuickCheck.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Copyright: 2000-2019 Koen Claessen, 2006-2008 Björn Bringert, 2009-2019 Nick Sm
Author: Koen Claessen <[email protected]>
Maintainer: Nick Smallbone <[email protected]>
Bug-reports: https://github.com/nick8325/quickcheck/issues
Tested-with: GHC >= 7.0
Tested-with: GHC ==7.0.4 || ==7.2.2 || >= 7.4
Homepage: https://github.com/nick8325/quickcheck
Category: Testing
Synopsis: Automatic testing of Haskell programs
Expand Down Expand Up @@ -48,6 +48,7 @@ extra-source-files:
examples/Set.hs
examples/Simple.hs
make-hugs
test-hugs

source-repository head
type: git
Expand All @@ -63,6 +64,7 @@ flag templateHaskell
Default: True

library
Hs-source-dirs: src
Build-depends: base >=4.3 && <5, random >=1.0.0.3 && <1.2, containers

-- random is explicitly Trustworthy since 1.0.1.0
Expand Down
8 changes: 8 additions & 0 deletions cabal.haskell-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apt: hugs libhugs-time-bundled
-- fails due: impl(haste)
cabal-check: False

raw-travis:
export CABAL
export HC
(cd ${PKGDIR_QuickCheck} && sh test-hugs)
17 changes: 13 additions & 4 deletions make-hugs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#!/bin/bash
cd $(dirname $0)
for i in $(find Test -name '*.hs'); do
mkdir -p quickcheck-hugs/$(dirname $i)

set -e

TOPDIR=$(dirname "$0")
TARGETDIR=$TOPDIR/quickcheck-hugs

find "$TOPDIR/src" -name '*.hs' | while read -r src; do
tgt="$TARGETDIR/$(echo "$src" | sed "s/^$TOPDIR\/src"'//')"

echo "Processing $src -> $tgt"

mkdir -p "$(dirname "$tgt")"
# If you want to switch on and off other features, look in
# QuickCheck.cabal to see what's available, or submit a patch
# adding a new -DNO_... flag.
Expand All @@ -10,7 +19,7 @@ for i in $(find Test -name '*.hs'); do
-DNO_SAFE_HASKELL -DNO_POLYKINDS -DNO_MONADFAIL -DNO_TIMEOUT \
-DNO_NEWTYPE_DERIVING -DNO_TYPEABLE -DNO_GADTS -DNO_TRANSFORMERS \
-DNO_DEEPSEQ -DNO_EXTRA_METHODS_IN_APPLICATIVE \
$i > quickcheck-hugs/$i
"$src" > "$tgt"
done

echo "A Hugs-compatible version of QuickCheck is now"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions test-hugs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

set -e

CABAL=${CABAL:-cabal}
HC=${HC:-ghc}

# Install cpphs if it is not in path
command -v cpphs || ${CABAL} v2-install --ignore-project --with-compiler "$HC" cpphs

# Regenerate quickcheck-hugs
sh make-hugs
find quickcheck-hugs

die() {
echo "TEST FAILED"
exit 1
}

dotest() {
echo "$2" | hugs -98 -Pquickcheck-hugs: -p'> ' "$1" | tee hugs.output
grep "$3" hugs.output || die
}

# Simple tests
dotest Test.QuickCheck 'quickCheck $ \xs -> reverse (reverse xs) === (xs :: [Int])' "OK, passed 100 tests."
2 changes: 1 addition & 1 deletion tests/GCoArbitraryExample.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Test.QuickCheck.Function
data D a = C1 a | C2 deriving (Eq, Show, Read, Generic)


instance Arbitrary a => Arbitrary (D a)
instance Arbitrary a => Arbitrary (D a) where arbitrary = error "not implemented"
instance CoArbitrary a => CoArbitrary (D a)

instance (Show a, Read a) => Function (D a) where
Expand Down
2 changes: 1 addition & 1 deletion tests/GShrinkExample.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Test.QuickCheck
data Nat = Z | S Nat deriving (Eq, Show, Generic)


instance Arbitrary Nat
instance Arbitrary Nat where arbitrary = error "not implemented"

prop_shrink =
genericShrink (S (S Z)) === [S Z] .&&.
Expand Down

0 comments on commit ef96526

Please sign in to comment.