Skip to content

Commit

Permalink
Copy test/main from time-1.14
Browse files Browse the repository at this point in the history
Add GHC-9.12 to CI
  • Loading branch information
phadej committed Dec 22, 2024
1 parent 8d29802 commit c1ceab8
Show file tree
Hide file tree
Showing 33 changed files with 2,356 additions and 1,654 deletions.
57 changes: 37 additions & 20 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.20240513
# version: 0.19.20241222
#
# REGENDATA ("0.19.20240513",["github","cabal.project"])
# REGENDATA ("0.19.20241222",["github","cabal.project"])
#
name: Haskell-CI
on:
Expand All @@ -32,19 +32,24 @@ jobs:
strategy:
matrix:
include:
- compiler: ghc-9.12.1
compilerKind: ghc
compilerVersion: 9.12.1
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.10.1
compilerKind: ghc
compilerVersion: 9.10.1
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.8.2
- compiler: ghc-9.8.4
compilerKind: ghc
compilerVersion: 9.8.2
compilerVersion: 9.8.4
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.6.5
- compiler: ghc-9.6.6
compilerKind: ghc
compilerVersion: 9.6.5
compilerVersion: 9.6.6
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.4.8
Expand Down Expand Up @@ -79,15 +84,30 @@ 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
- name: Install GHCup
run: |
mkdir -p "$HOME/.ghcup/bin"
curl -sL https://downloads.haskell.org/ghcup/0.1.20.0/x86_64-linux-ghcup-0.1.20.0 > "$HOME/.ghcup/bin/ghcup"
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"
- name: Install cabal-install (prerelease)
run: |
"$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 cabal 3.15.0.0.2024.10.3 || (cat "$HOME"/.ghcup/logs/*.* && false)
echo "CABAL=$HOME/.ghcup/bin/cabal-3.15.0.0.2024.10.3 -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)
"$HOME/.ghcup/bin/ghcup" install cabal 3.10.2.0 || (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 }}
Expand All @@ -98,21 +118,12 @@ jobs:
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
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.10.2.0 -vnormal+nowrap" >> "$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"
echo "HEADHACKAGE=false" >> "$GITHUB_ENV"
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 @@ -191,7 +202,7 @@ jobs:
cat >> cabal.project <<EOF
allow-newer: time
EOF
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: $_ installed\n" unless /^(time-compat)$/; }' >> cabal.project.local
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: any.$_ installed\n" unless /^(time-compat)$/; }' >> cabal.project.local
cat cabal.project
cat cabal.project.local
- name: dump install plan
Expand Down Expand Up @@ -273,9 +284,15 @@ jobs:
if [ $((HCNUMVER >= 80800 && HCNUMVER < 90400)) -ne 0 ] ; then cabal-plan topo | sort ; fi
if [ $((HCNUMVER >= 80800 && HCNUMVER < 90400)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='time ==1.12' --dependencies-only -j2 all ; fi
if [ $((HCNUMVER >= 80800 && HCNUMVER < 90400)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='time ==1.12' all ; fi
- name: constraint set time-1.14
run: |
if [ $((HCNUMVER >= 80800)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='time ==1.12' all --dry-run ; fi
if [ $((HCNUMVER >= 80800)) -ne 0 ] ; then cabal-plan topo | sort ; fi
if [ $((HCNUMVER >= 80800)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='time ==1.12' --dependencies-only -j2 all ; fi
if [ $((HCNUMVER >= 80800)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='time ==1.12' all ; fi
- 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: 4 additions & 0 deletions cabal.haskell-ci
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ distribution: jammy
branches: master
head-hackage: False

constraint-set time-1.14
ghc: >= 8.8
constraints: time ==1.12

constraint-set time-1.12
ghc: >= 8.8 && <9.3
constraints: time ==1.12
Expand Down
39 changes: 23 additions & 16 deletions test/main/Main.hs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
module Main where

import Test.Types()
import Test.Calendar.AddDays
import Test.Calendar.CalendarProps
import Test.Calendar.Calendars
import Test.Calendar.ClipDates
import Test.Calendar.ConvertBack
import Test.Calendar.DayPeriod
import Test.Calendar.Duration
import Test.Calendar.Easter
import Test.Calendar.LongWeekYears
import Test.Calendar.MonthDay
import Test.Calendar.MonthOfYear
import Test.Calendar.Valid
import Test.Calendar.Week
import Test.Calendar.Year
import Test.Clock.Conversion
import Test.Clock.Lift (testLift)
import Test.Clock.Resolution
import Test.Clock.TAI
import Test.Format.Compile ()
Expand All @@ -23,27 +26,31 @@ import Test.LocalTime.CalendarDiffTime
import Test.LocalTime.Time
import Test.LocalTime.TimeOfDay
import Test.Tasty
import Test.Types ()

tests :: TestTree
tests =
testGroup
"Time"
[ testGroup
"Calendar"
[ addDaysTest
, testCalendarProps
, testCalendars
, clipDates
, convertBack
, longWeekYears
, testMonthDay
, testEaster
, testValid
, testWeek
, testDuration
]
, testGroup "Clock" [testClockConversion, testResolutions, testTAI]
, testGroup "Format" [testFormat, {- testParseTime, -} testISO8601]
"Calendar"
[ addDaysTest
, testCalendarProps
, testCalendars
, clipDates
, convertBack
, longWeekYears
, testDayPeriod
, testMonthDay
, testMonthOfYear
, testEaster
, testValid
, testWeek
, testYear
, testDuration
]
, testGroup "Clock" [testClockConversion, testResolutions, testTAI, testLift]
, testGroup "Format" [testFormat, testParseTime, testISO8601]
, testGroup "LocalTime" [testTime, testTimeOfDay, testCalendarDiffTime]
]

Expand Down
93 changes: 53 additions & 40 deletions test/main/Test/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ module Test.Arbitrary where
import Control.Monad
import Data.Fixed
import Data.Ratio
import Data.Time.Compat
import Data.Time.Calendar.WeekDate.Compat
import Data.Time.Calendar.Month.Compat
import Data.Time.Calendar.Quarter.Compat
import Data.Time.Clock.POSIX.Compat
import Data.Time
import Data.Time.Calendar.Month
import Data.Time.Calendar.Quarter
import Data.Time.Calendar.WeekDate
import Data.Time.Clock.POSIX
import System.Random
import Test.Tasty.QuickCheck hiding (reason)

instance Arbitrary DayOfWeek where
Expand All @@ -31,25 +32,33 @@ instance Arbitrary Quarter where
instance Arbitrary QuarterOfYear where
arbitrary = liftM toEnum $ choose (1, 4)

deriving instance Random Day

supportedDayRange :: (Day, Day)
supportedDayRange = (fromGregorian (-9899) 1 1, fromGregorian 9999 12 31)

instance Arbitrary Day where
arbitrary = liftM ModifiedJulianDay $ choose (-313698, 2973483) -- 1000-01-1 to 9999-12-31
shrink day = let
(y, m, d) = toGregorian day
dayShrink =
if d > 1
then [fromGregorian y m (d - 1)]
else []
monthShrink =
if m > 1
then [fromGregorian y (m - 1) d]
else []
yearShrink =
if y > 2000
then [fromGregorian (y - 1) m d]
else if y < 2000
then [fromGregorian (y + 1) m d]
else []
in dayShrink ++ monthShrink ++ yearShrink
arbitrary = choose supportedDayRange
shrink day =
let
(y, m, d) = toGregorian day
dayShrink =
if d > 1
then [fromGregorian y m (d - 1)]
else []
monthShrink =
if m > 1
then [fromGregorian y (m - 1) d]
else []
yearShrink =
if y > 2000
then [fromGregorian (y - 1) m d]
else
if y < 2000
then [fromGregorian (y + 1) m d]
else []
in
dayShrink ++ monthShrink ++ yearShrink

instance CoArbitrary Day where
coarbitrary (ModifiedJulianDay d) = coarbitrary d
Expand Down Expand Up @@ -90,28 +99,32 @@ instance Arbitrary CalendarDiffTime where

reduceDigits :: Int -> Pico -> Maybe Pico
reduceDigits (-1) _ = Nothing
reduceDigits n x = let
d :: Pico
d = 10 ^^ (negate n)
r = mod' x d
in case r of
0 -> reduceDigits (n - 1) x
_ -> Just $ x - r
reduceDigits n x =
let
d :: Pico
d = 10 ^^ (negate n)
r = mod' x d
in
case r of
0 -> reduceDigits (n - 1) x
_ -> Just $ x - r

instance Arbitrary TimeOfDay where
arbitrary = liftM timeToTimeOfDay arbitrary
shrink (TimeOfDay h m s) = let
shrinkInt 0 = []
shrinkInt 1 = [0]
shrinkInt _ = [0, 1]
shrinkPico 0 = []
shrinkPico 1 = [0]
shrinkPico p =
case reduceDigits 12 p of
shrink (TimeOfDay h m s) =
let
shrinkInt 0 = []
shrinkInt 1 = [0]
shrinkInt _ = [0, 1]
shrinkPico 0 = []
shrinkPico 1 = [0]
shrinkPico p = case reduceDigits 12 p of
Just p' -> [0, 1, p']
Nothing -> [0, 1]
in [TimeOfDay h' m s | h' <- shrinkInt h] ++
[TimeOfDay h m' s | m' <- shrinkInt m] ++ [TimeOfDay h m s' | s' <- shrinkPico s]
in
[TimeOfDay h' m s | h' <- shrinkInt h]
++ [TimeOfDay h m' s | m' <- shrinkInt m]
++ [TimeOfDay h m s' | s' <- shrinkPico s]

instance CoArbitrary TimeOfDay where
coarbitrary t = coarbitrary (timeOfDayToTime t)
Expand Down
16 changes: 11 additions & 5 deletions test/main/Test/Calendar/AddDays.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Test.Calendar.AddDays
( addDaysTest
) where
module Test.Calendar.AddDays (
addDaysTest,
) where

import Data.Time.Calendar
import Test.Calendar.AddDaysRef
Expand Down Expand Up @@ -36,8 +36,14 @@ resultDays = do
increment <- increments
day <- days
return
((showGregorian day) ++
" + " ++ (show increment) ++ " * " ++ aname ++ " = " ++ showGregorian (adder increment day))
( (showGregorian day)
++ " + "
++ (show increment)
++ " * "
++ aname
++ " = "
++ showGregorian (adder increment day)
)

addDaysTest :: TestTree
addDaysTest = testCase "addDays" $ assertEqual "" addDaysRef $ unlines resultDays
17 changes: 8 additions & 9 deletions test/main/Test/Calendar/CalendarProps.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{-# LANGUAGE CPP #-}
module Test.Calendar.CalendarProps
( testCalendarProps
) where
module Test.Calendar.CalendarProps (
testCalendarProps,
) where

import Data.Time.Calendar.Month.Compat
import Data.Time.Calendar.Quarter.Compat
import Test.TestUtil
import Test.Tasty
import Data.Time.Calendar.Month
import Data.Time.Calendar.Quarter
import Test.Arbitrary ()
import Test.Tasty
import Test.TestUtil

testYearMonth :: TestTree
testYearMonth = nameTest "YearMonth" $ \m -> case m of
Expand All @@ -22,4 +21,4 @@ testYearQuarter = nameTest "YearQuarter" $ \q -> case q of
YearQuarter y qy -> q == YearQuarter y qy

testCalendarProps :: TestTree
testCalendarProps = nameTest "calender-props" [testYearMonth,testMonthDay,testYearQuarter]
testCalendarProps = nameTest "calender-props" [testYearMonth, testMonthDay, testYearQuarter]
6 changes: 3 additions & 3 deletions test/main/Test/Calendar/Calendars.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Test.Calendar.Calendars
( testCalendars
) where
module Test.Calendar.Calendars (
testCalendars,
) where

import Data.Time.Calendar
import Data.Time.Calendar.Julian
Expand Down
Loading

0 comments on commit c1ceab8

Please sign in to comment.