Skip to content

Commit 118f689

Browse files
authored
Strictness tests for left and right folds (#1071)
* 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.
1 parent ed1f052 commit 118f689

11 files changed

+432
-216
lines changed

.github/workflows/haskell-ci.yml

+34-15
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#
99
# For more information, see https://github.com/haskell-CI/haskell-ci
1010
#
11-
# version: 0.19.20240708
11+
# version: 0.19.20241121
1212
#
13-
# REGENDATA ("0.19.20240708",["github","--config=cabal.haskell-ci","--ghc-head","cabal.project"])
13+
# REGENDATA ("0.19.20241121",["github","--config=cabal.haskell-ci","--ghc-head","cabal.project"])
1414
#
1515
name: Haskell-CI
1616
on:
@@ -89,41 +89,60 @@ jobs:
8989
allow-failure: false
9090
fail-fast: false
9191
steps:
92-
- name: apt
92+
- name: apt-get install
9393
run: |
9494
apt-get update
9595
apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5 libnuma-dev
96+
- name: Install GHCup
97+
run: |
9698
mkdir -p "$HOME/.ghcup/bin"
9799
curl -sL https://downloads.haskell.org/ghcup/0.1.30.0/x86_64-linux-ghcup-0.1.30.0 > "$HOME/.ghcup/bin/ghcup"
98100
chmod a+x "$HOME/.ghcup/bin/ghcup"
99-
"$HOME/.ghcup/bin/ghcup" config add-release-channel https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.8.yaml;
100-
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
101+
- name: Install cabal-install
102+
run: |
101103
"$HOME/.ghcup/bin/ghcup" install cabal 3.12.1.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
104+
echo "CABAL=$HOME/.ghcup/bin/cabal-3.12.1.0 -vnormal+nowrap" >> "$GITHUB_ENV"
105+
- name: Install GHC (GHCup)
106+
if: matrix.setup-method == 'ghcup'
107+
run: |
108+
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
109+
HC=$("$HOME/.ghcup/bin/ghcup" whereis ghc "$HCVER")
110+
HCPKG=$(echo "$HC" | sed 's#ghc$#ghc-pkg#')
111+
HADDOCK=$(echo "$HC" | sed 's#ghc$#haddock#')
112+
echo "HC=$HC" >> "$GITHUB_ENV"
113+
echo "HCPKG=$HCPKG" >> "$GITHUB_ENV"
114+
echo "HADDOCK=$HADDOCK" >> "$GITHUB_ENV"
102115
env:
103116
HCKIND: ${{ matrix.compilerKind }}
104117
HCNAME: ${{ matrix.compiler }}
105118
HCVER: ${{ matrix.compilerVersion }}
106-
- name: Set PATH and environment variables
119+
- name: Install GHC (GHCup prerelease)
120+
if: matrix.setup-method == 'ghcup-prerelease'
107121
run: |
108-
echo "$HOME/.cabal/bin" >> $GITHUB_PATH
109-
echo "LANG=C.UTF-8" >> "$GITHUB_ENV"
110-
echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV"
111-
echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV"
112-
HCDIR=/opt/$HCKIND/$HCVER
122+
"$HOME/.ghcup/bin/ghcup" config add-release-channel https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.8.yaml;
123+
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
113124
HC=$("$HOME/.ghcup/bin/ghcup" whereis ghc "$HCVER")
114125
HCPKG=$(echo "$HC" | sed 's#ghc$#ghc-pkg#')
115126
HADDOCK=$(echo "$HC" | sed 's#ghc$#haddock#')
116127
echo "HC=$HC" >> "$GITHUB_ENV"
117128
echo "HCPKG=$HCPKG" >> "$GITHUB_ENV"
118129
echo "HADDOCK=$HADDOCK" >> "$GITHUB_ENV"
119-
echo "CABAL=$HOME/.ghcup/bin/cabal-3.12.1.0 -vnormal+nowrap" >> "$GITHUB_ENV"
130+
env:
131+
HCKIND: ${{ matrix.compilerKind }}
132+
HCNAME: ${{ matrix.compiler }}
133+
HCVER: ${{ matrix.compilerVersion }}
134+
- name: Set PATH and environment variables
135+
run: |
136+
echo "$HOME/.cabal/bin" >> $GITHUB_PATH
137+
echo "LANG=C.UTF-8" >> "$GITHUB_ENV"
138+
echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV"
139+
echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV"
120140
HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')
121141
echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV"
122142
echo "ARG_TESTS=--enable-tests" >> "$GITHUB_ENV"
123143
echo "ARG_BENCH=--enable-benchmarks" >> "$GITHUB_ENV"
124144
if [ $((HCNUMVER > 91001)) -ne 0 ] ; then echo "HEADHACKAGE=true" >> "$GITHUB_ENV" ; else echo "HEADHACKAGE=false" >> "$GITHUB_ENV" ; fi
125145
echo "ARG_COMPILER=--$HCKIND --with-compiler=$HC" >> "$GITHUB_ENV"
126-
echo "GHCJSARITH=0" >> "$GITHUB_ENV"
127146
env:
128147
HCKIND: ${{ matrix.compilerKind }}
129148
HCNAME: ${{ matrix.compiler }}
@@ -222,7 +241,7 @@ jobs:
222241
if $HEADHACKAGE; then
223242
echo "allow-newer: $($HCPKG list --simple-output | sed -E 's/([a-zA-Z-]+)-[0-9.]+/*:\1,/g')" >> cabal.project
224243
fi
225-
$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
244+
$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
226245
cat cabal.project
227246
cat cabal.project.local
228247
- name: dump install plan
@@ -252,8 +271,8 @@ jobs:
252271
rm -f cabal.project.local
253272
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all
254273
- name: save cache
255-
uses: actions/cache/save@v4
256274
if: always()
275+
uses: actions/cache/save@v4
257276
with:
258277
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }}
259278
path: ~/.cabal/store

cabal.haskell-ci

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ install-dependencies: False
99

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

1614
cabal-check: False

containers-tests/containers-tests.cabal

+25-31
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,9 @@ library
7070
default-language: Haskell2010
7171
-- this is important for testing; may it affect benchmarks?
7272
cpp-options: -DTESTING
73-
if impl(ghc >= 8.6)
74-
build-depends:
75-
nothunks
76-
, QuickCheck
7773

7874
include-dirs: include
79-
hs-source-dirs: src, tests
75+
hs-source-dirs: src
8076

8177
ghc-options: -O2 -Wall
8278
if impl(ghc >= 8.6)
@@ -117,9 +113,6 @@ library
117113
Utils.Containers.Internal.BitQueue
118114
Utils.Containers.Internal.BitUtil
119115
Utils.Containers.Internal.StrictPair
120-
if impl(ghc >= 8.6.0)
121-
exposed-modules:
122-
Utils.NoThunks
123116

124117
other-modules:
125118
Utils.Containers.Internal.Prelude
@@ -356,12 +349,6 @@ test-suite set-properties
356349
BangPatterns
357350
CPP
358351

359-
if impl(ghc >= 8.6)
360-
build-depends:
361-
nothunks
362-
other-modules:
363-
Utils.NoThunks
364-
365352
test-suite intmap-lazy-properties
366353
import: test-deps, warnings
367354
default-language: Haskell2010
@@ -451,14 +438,9 @@ test-suite map-strictness-properties
451438
other-modules:
452439
Utils.ArbitrarySetMap
453440
Utils.MergeFunc
441+
Utils.NubSorted
454442
Utils.Strictness
455443

456-
if impl(ghc >= 8.6)
457-
build-depends:
458-
nothunks
459-
other-modules:
460-
Utils.NoThunks
461-
462444
test-suite intmap-strictness-properties
463445
import: test-deps, warnings
464446
default-language: Haskell2010
@@ -475,15 +457,29 @@ test-suite intmap-strictness-properties
475457
ghc-options: -Wall
476458

477459
other-modules:
478-
Utils.IsUnit
479460
Utils.MergeFunc
461+
Utils.NubSorted
480462
Utils.Strictness
481463

482-
if impl(ghc >= 8.6)
483-
build-depends:
484-
nothunks
485-
other-modules:
486-
Utils.NoThunks
464+
test-suite set-strictness-properties
465+
import: test-deps, warnings
466+
default-language: Haskell2010
467+
hs-source-dirs: tests
468+
main-is: set-strictness.hs
469+
type: exitcode-stdio-1.0
470+
other-extensions:
471+
BangPatterns
472+
CPP
473+
474+
build-depends:
475+
ChasingBottoms
476+
477+
ghc-options: -Wall
478+
479+
other-modules:
480+
Utils.ArbitrarySetMap
481+
Utils.NubSorted
482+
Utils.Strictness
487483

488484
test-suite intset-strictness-properties
489485
import: test-deps, warnings
@@ -500,11 +496,9 @@ test-suite intset-strictness-properties
500496

501497
ghc-options: -Wall
502498

503-
if impl(ghc >= 8.6)
504-
build-depends:
505-
nothunks
506-
other-modules:
507-
Utils.NoThunks
499+
other-modules:
500+
Utils.NubSorted
501+
Utils.Strictness
508502

509503
test-suite listutils-properties
510504
import: test-deps, warnings

containers-tests/tests/Utils/IsUnit.hs

-42
This file was deleted.

containers-tests/tests/Utils/NoThunks.hs

-12
This file was deleted.
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module Utils.NubSorted
2+
( NubSorted(..)
3+
, NubSortedOnFst(..)
4+
) where
5+
6+
import qualified Data.List as List
7+
import qualified Data.List.NonEmpty as NonEmpty
8+
import Data.Ord (comparing)
9+
import Test.QuickCheck
10+
11+
newtype NubSorted a = NubSorted { getNubSorted :: [a] }
12+
deriving Show
13+
14+
instance (Ord a, Arbitrary a) => Arbitrary (NubSorted a) where
15+
arbitrary = NubSorted . nubSortBy compare <$> arbitrary
16+
shrink = map (NubSorted . nubSortBy compare) . shrink . getNubSorted
17+
18+
newtype NubSortedOnFst a b = NubSortedOnFst { getNubSortedOnFst :: [(a, b)] }
19+
deriving Show
20+
21+
instance (Ord a, Arbitrary a, Arbitrary b)
22+
=> Arbitrary (NubSortedOnFst a b) where
23+
arbitrary = NubSortedOnFst . nubSortBy (comparing fst) <$> arbitrary
24+
shrink =
25+
map (NubSortedOnFst . nubSortBy (comparing fst)) .
26+
shrink .
27+
getNubSortedOnFst
28+
29+
nubSortBy :: (a -> a -> Ordering) -> [a] -> [a]
30+
nubSortBy cmp =
31+
map NonEmpty.head .
32+
NonEmpty.groupBy (\x y -> cmp x y == EQ) .
33+
List.sortBy cmp

0 commit comments

Comments
 (0)