Skip to content

Commit

Permalink
Strictness tests for left and right folds
Browse files Browse the repository at this point in the history
* Add new tests and update existing tests to check against lists.
  This covers all left and right folds on Set, Map, IntSet, IntMap.
* Remove the now unnecessary nothunks dependency.
  • Loading branch information
meooow25 committed Nov 28, 2024
1 parent b24068b commit 149be4f
Show file tree
Hide file tree
Showing 11 changed files with 432 additions and 216 deletions.
49 changes: 34 additions & 15 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#
# For more information, see https://github.com/haskell-CI/haskell-ci
#
# version: 0.19.20240708
# version: 0.19.20241121
#
# REGENDATA ("0.19.20240708",["github","--config=cabal.haskell-ci","--ghc-head","cabal.project"])
# REGENDATA ("0.19.20241121",["github","--config=cabal.haskell-ci","--ghc-head","cabal.project"])
#
name: Haskell-CI
on:
Expand Down Expand Up @@ -89,41 +89,60 @@ jobs:
allow-failure: false
fail-fast: false
steps:
- name: apt
- name: apt-get install
run: |
apt-get update
apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5 libnuma-dev
- name: Install GHCup
run: |
mkdir -p "$HOME/.ghcup/bin"
curl -sL https://downloads.haskell.org/ghcup/0.1.30.0/x86_64-linux-ghcup-0.1.30.0 > "$HOME/.ghcup/bin/ghcup"
chmod a+x "$HOME/.ghcup/bin/ghcup"
"$HOME/.ghcup/bin/ghcup" config add-release-channel https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.8.yaml;
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
- name: Install cabal-install
run: |
"$HOME/.ghcup/bin/ghcup" install cabal 3.12.1.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
echo "CABAL=$HOME/.ghcup/bin/cabal-3.12.1.0 -vnormal+nowrap" >> "$GITHUB_ENV"
- name: Install GHC (GHCup)
if: matrix.setup-method == 'ghcup'
run: |
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
HC=$("$HOME/.ghcup/bin/ghcup" whereis ghc "$HCVER")
HCPKG=$(echo "$HC" | sed 's#ghc$#ghc-pkg#')
HADDOCK=$(echo "$HC" | sed 's#ghc$#haddock#')
echo "HC=$HC" >> "$GITHUB_ENV"
echo "HCPKG=$HCPKG" >> "$GITHUB_ENV"
echo "HADDOCK=$HADDOCK" >> "$GITHUB_ENV"
env:
HCKIND: ${{ matrix.compilerKind }}
HCNAME: ${{ matrix.compiler }}
HCVER: ${{ matrix.compilerVersion }}
- name: Set PATH and environment variables
- name: Install GHC (GHCup prerelease)
if: matrix.setup-method == 'ghcup-prerelease'
run: |
echo "$HOME/.cabal/bin" >> $GITHUB_PATH
echo "LANG=C.UTF-8" >> "$GITHUB_ENV"
echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV"
echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV"
HCDIR=/opt/$HCKIND/$HCVER
"$HOME/.ghcup/bin/ghcup" config add-release-channel https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.8.yaml;
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
HC=$("$HOME/.ghcup/bin/ghcup" whereis ghc "$HCVER")
HCPKG=$(echo "$HC" | sed 's#ghc$#ghc-pkg#')
HADDOCK=$(echo "$HC" | sed 's#ghc$#haddock#')
echo "HC=$HC" >> "$GITHUB_ENV"
echo "HCPKG=$HCPKG" >> "$GITHUB_ENV"
echo "HADDOCK=$HADDOCK" >> "$GITHUB_ENV"
echo "CABAL=$HOME/.ghcup/bin/cabal-3.12.1.0 -vnormal+nowrap" >> "$GITHUB_ENV"
env:
HCKIND: ${{ matrix.compilerKind }}
HCNAME: ${{ matrix.compiler }}
HCVER: ${{ matrix.compilerVersion }}
- name: Set PATH and environment variables
run: |
echo "$HOME/.cabal/bin" >> $GITHUB_PATH
echo "LANG=C.UTF-8" >> "$GITHUB_ENV"
echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV"
echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV"
HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')
echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV"
echo "ARG_TESTS=--enable-tests" >> "$GITHUB_ENV"
echo "ARG_BENCH=--enable-benchmarks" >> "$GITHUB_ENV"
if [ $((HCNUMVER > 91001)) -ne 0 ] ; then echo "HEADHACKAGE=true" >> "$GITHUB_ENV" ; else echo "HEADHACKAGE=false" >> "$GITHUB_ENV" ; fi
echo "ARG_COMPILER=--$HCKIND --with-compiler=$HC" >> "$GITHUB_ENV"
echo "GHCJSARITH=0" >> "$GITHUB_ENV"
env:
HCKIND: ${{ matrix.compilerKind }}
HCNAME: ${{ matrix.compiler }}
Expand Down Expand Up @@ -222,7 +241,7 @@ jobs:
if $HEADHACKAGE; then
echo "allow-newer: $($HCPKG list --simple-output | sed -E 's/([a-zA-Z-]+)-[0-9.]+/*:\1,/g')" >> cabal.project
fi
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: any.$_ installed\n" unless /^(binary|containers|containers-tests|ghc-heap|text)$/; }' >> cabal.project.local
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: any.$_ installed\n" unless /^(binary|containers|containers-tests|text)$/; }' >> cabal.project.local
cat cabal.project
cat cabal.project.local
- name: dump install plan
Expand Down Expand Up @@ -252,8 +271,8 @@ jobs:
rm -f cabal.project.local
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all
- name: save cache
uses: actions/cache/save@v4
if: always()
uses: actions/cache/save@v4
with:
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }}
path: ~/.cabal/store
4 changes: 1 addition & 3 deletions cabal.haskell-ci
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ install-dependencies: False

-- text depends on binary, and binary depends on containers, so we need to
-- reinstall these boot libraries
-- ghc-heap is depended on by nothunks which we use in the tests, and also
-- depends on containers
installed: +all -binary -text -ghc-heap
installed: +all -binary -text

cabal-check: False
56 changes: 25 additions & 31 deletions containers-tests/containers-tests.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,9 @@ library
default-language: Haskell2010
-- this is important for testing; may it affect benchmarks?
cpp-options: -DTESTING
if impl(ghc >= 8.6)
build-depends:
nothunks
, QuickCheck

include-dirs: include
hs-source-dirs: src, tests
hs-source-dirs: src

ghc-options: -O2 -Wall
if impl(ghc >= 8.6)
Expand Down Expand Up @@ -117,9 +113,6 @@ library
Utils.Containers.Internal.BitQueue
Utils.Containers.Internal.BitUtil
Utils.Containers.Internal.StrictPair
if impl(ghc >= 8.6.0)
exposed-modules:
Utils.NoThunks

other-modules:
Utils.Containers.Internal.Prelude
Expand Down Expand Up @@ -320,12 +313,6 @@ test-suite set-properties
BangPatterns
CPP

if impl(ghc >= 8.6)
build-depends:
nothunks
other-modules:
Utils.NoThunks

test-suite intmap-lazy-properties
import: test-deps, warnings
default-language: Haskell2010
Expand Down Expand Up @@ -415,14 +402,9 @@ test-suite map-strictness-properties
other-modules:
Utils.ArbitrarySetMap
Utils.MergeFunc
Utils.NubSorted
Utils.Strictness

if impl(ghc >= 8.6)
build-depends:
nothunks
other-modules:
Utils.NoThunks

test-suite intmap-strictness-properties
import: test-deps, warnings
default-language: Haskell2010
Expand All @@ -439,15 +421,29 @@ test-suite intmap-strictness-properties
ghc-options: -Wall

other-modules:
Utils.IsUnit
Utils.MergeFunc
Utils.NubSorted
Utils.Strictness

if impl(ghc >= 8.6)
build-depends:
nothunks
other-modules:
Utils.NoThunks
test-suite set-strictness-properties
import: test-deps, warnings
default-language: Haskell2010
hs-source-dirs: tests
main-is: set-strictness.hs
type: exitcode-stdio-1.0
other-extensions:
BangPatterns
CPP

build-depends:
ChasingBottoms

ghc-options: -Wall

other-modules:
Utils.ArbitrarySetMap
Utils.NubSorted
Utils.Strictness

test-suite intset-strictness-properties
import: test-deps, warnings
Expand All @@ -464,11 +460,9 @@ test-suite intset-strictness-properties

ghc-options: -Wall

if impl(ghc >= 8.6)
build-depends:
nothunks
other-modules:
Utils.NoThunks
other-modules:
Utils.NubSorted
Utils.Strictness

test-suite listutils-properties
import: test-deps, warnings
Expand Down
42 changes: 0 additions & 42 deletions containers-tests/tests/Utils/IsUnit.hs

This file was deleted.

12 changes: 0 additions & 12 deletions containers-tests/tests/Utils/NoThunks.hs

This file was deleted.

33 changes: 33 additions & 0 deletions containers-tests/tests/Utils/NubSorted.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Utils.NubSorted
( NubSorted(..)
, NubSortedOnFst(..)
) where

import qualified Data.List as List
import qualified Data.List.NonEmpty as NonEmpty
import Data.Ord (comparing)
import Test.QuickCheck

newtype NubSorted a = NubSorted { getNubSorted :: [a] }
deriving Show

instance (Ord a, Arbitrary a) => Arbitrary (NubSorted a) where
arbitrary = NubSorted . nubSortBy compare <$> arbitrary
shrink = map (NubSorted . nubSortBy compare) . shrink . getNubSorted

newtype NubSortedOnFst a b = NubSortedOnFst { getNubSortedOnFst :: [(a, b)] }
deriving Show

instance (Ord a, Arbitrary a, Arbitrary b)
=> Arbitrary (NubSortedOnFst a b) where
arbitrary = NubSortedOnFst . nubSortBy (comparing fst) <$> arbitrary
shrink =
map (NubSortedOnFst . nubSortBy (comparing fst)) .
shrink .
getNubSortedOnFst

nubSortBy :: (a -> a -> Ordering) -> [a] -> [a]
nubSortBy cmp =
map NonEmpty.head .
NonEmpty.groupBy (\x y -> cmp x y == EQ) .
List.sortBy cmp
Loading

0 comments on commit 149be4f

Please sign in to comment.