Skip to content

Commit

Permalink
beef
Browse files Browse the repository at this point in the history
  • Loading branch information
phadej committed Apr 2, 2024
1 parent bb84f3f commit 4bda416
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 10 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,18 @@ jobs:
rm -f cabal.project.local
- name: constraint set filepath-1.5
run: |
if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' all --dry-run ; fi
if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' all --dry-run ; fi
if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then cabal-plan topo | sort ; fi
if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' --dependencies-only -j2 all ; fi
if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' all ; fi
if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' --dependencies-only -j2 all ; fi
if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' all ; fi
if [ $((HCNUMVER >= 90200)) -ne 0 ] ; then $CABAL v2-test $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.5.2.0' all ; fi
- name: constraint set filepath-1.4.100.0
run: |
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='filepath ^>=1.4.100.0' all --dry-run
$CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.4.100.0' all --dry-run
cabal-plan topo | sort
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='filepath ^>=1.4.100.0' --dependencies-only -j2 all
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='filepath ^>=1.4.100.0' all
$CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.4.100.0' --dependencies-only -j2 all
$CABAL v2-build $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.4.100.0' all
$CABAL v2-test $ARG_COMPILER --enable-tests --disable-benchmarks --constraint='filepath ^>=1.4.100.0' all
- name: constraint set random-initial-seed
run: |
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='hashable +random-initial-seed' all --dry-run
Expand Down
4 changes: 4 additions & 0 deletions cabal.haskell-ci
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ constraint-set random-initial-seed

constraint-set filepath-1.4.100.0
constraints: filepath ^>=1.4.100.0
tests: True
run-tests: True

constraint-set filepath-1.5
ghc: >=9.2
constraints: filepath ^>=1.5.2.0
tests: True
run-tests: True
3 changes: 2 additions & 1 deletion hashable.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ test-suite hashable-tests
build-depends:
base
, bytestring
, filepath
, ghc-prim
, hashable
, HUnit
Expand All @@ -174,7 +175,7 @@ test-suite hashable-tests
, text >=0.11.0.5

if impl(ghc >=9.2)
build-depends: os-string >=2.0.2
build-depends: os-string

if !os(windows)
build-depends: unix
Expand Down
34 changes: 32 additions & 2 deletions src/Data/Hashable/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE Trustworthy #-}
Expand Down Expand Up @@ -167,7 +168,25 @@ import Data.Tuple (Solo (..))
import GHC.Tuple (Solo (..))
#endif

#if MIN_VERSION_filepath(1,4,100)
-- filepath >=1.4.100 && <1.5 has System.OsString.Internal.Types module
#if MIN_VERSION_filepath(1,4,100) && !(MIN_VERSION_filepath(1,5,0))
#define HAS_OS_STRING_filepath 1
#else
#define HAS_OS_STRING_filepath 0
#endif

-- if we depend on os_string module, then it has System.OsString.Internal.Types
-- module as well
#ifdef MIN_VERSION_os_string
#define HAS_OS_STRING_os_string 1
#else
#define HAS_OS_STRING_os_string 0
#endif

#if HAS_OS_STRING_filepath && HAS_OS_STRING_os_string
import "os-string" System.OsString.Internal.Types (OsString (..), PosixString (..), WindowsString (..))
import qualified "filepath" System.OsString.Internal.Types as FP (OsString (..), PosixString (..), WindowsString (..))
#elif HAS_OS_STRING_filepath || HAS_OS_STRING_os_string
import System.OsString.Internal.Types (OsString (..), PosixString (..), WindowsString (..))
#endif

Expand Down Expand Up @@ -666,7 +685,7 @@ instance Hashable BSI.ShortByteString where
hashWithSalt salt sbs@(BSI.SBS ba) =
hashByteArrayWithSalt ba 0 (BSI.length sbs) (hashWithSalt salt (BSI.length sbs))

#if MIN_VERSION_filepath(1,4,100)
#if HAS_OS_STRING_filepath || HAS_OS_STRING_os_string
-- | @since 1.4.2.0
instance Hashable PosixString where
hashWithSalt salt (PosixString s) = hashWithSalt salt s
Expand All @@ -680,6 +699,17 @@ instance Hashable OsString where
hashWithSalt salt (OsString s) = hashWithSalt salt s
#endif

#if HAS_OS_STRING_filepath && HAS_OS_STRING_os_string
instance Hashable FP.PosixString where
hashWithSalt salt (FP.PosixString s) = hashWithSalt salt s

instance Hashable FP.WindowsString where
hashWithSalt salt (FP.WindowsString s) = hashWithSalt salt s

instance Hashable FP.OsString where
hashWithSalt salt (FP.OsString s) = hashWithSalt salt s
#endif

#if MIN_VERSION_text(2,0,0)

instance Hashable T.Text where
Expand Down
30 changes: 29 additions & 1 deletion tests/Properties.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE BangPatterns, CPP, GeneralizedNewtypeDeriving, MagicHash,
Rank2Types, UnboxedTuples #-}
{-# LANGUAGE DeriveGeneric, ScopedTypeVariables #-}
{-# LANGUAGE DeriveGeneric, ScopedTypeVariables, PackageImports #-}

-- | QuickCheck tests for the 'Data.Hashable' module. We test
-- functions by comparing the C and Haskell implementations.
Expand Down Expand Up @@ -30,6 +30,14 @@ import GHC.Generics

import qualified Data.ByteString.Short as BS

#if MIN_VERSION_filepath(1,4,100) && !(MIN_VERSION_filepath(1,5,0))
import qualified "filepath" System.OsString.Internal.Types as FP
#endif

#ifdef MIN_VERSION_os_string
import qualified "os-string" System.OsString.Internal.Types as OS
#endif

------------------------------------------------------------------------
-- * Properties

Expand Down Expand Up @@ -252,3 +260,23 @@ properties =

fromStrict :: B.ByteString -> BL.ByteString
fromStrict = BL.fromStrict

------------------------------------------------------------------------
-- test that instances exist

instanceExists :: Hashable a => a -> ()
instanceExists _ = ()

Check warning on line 268 in tests/Properties.hs

View workflow job for this annotation

GitHub Actions / Simple: GHC 8.10 on macos-latest

Defined but not used: ‘instanceExists’

Check warning on line 268 in tests/Properties.hs

View workflow job for this annotation

GitHub Actions / Simple: GHC 9.0 on macos-latest

Defined but not used: ‘instanceExists’

Check warning on line 268 in tests/Properties.hs

View workflow job for this annotation

GitHub Actions / Simple: GHC 8.10 on windows-latest

Defined but not used: ‘instanceExists’

Check warning on line 268 in tests/Properties.hs

View workflow job for this annotation

GitHub Actions / Simple: GHC 9.0 on windows-latest

Defined but not used: ‘instanceExists’

#if MIN_VERSION_filepath(1,4,100) && !(MIN_VERSION_filepath(1,5,0))
_fp1, _fp2, _fp3 :: ()
_fp1 = instanceExists (undefined :: FP.OsString)
_fp2 = instanceExists (undefined :: FP.WindowsString)
_fp3 = instanceExists (undefined :: FP.PosixString)
#endif

#ifdef MIN_VERSION_os_string
_os1, _os2, _os3 :: ()
_os1 = instanceExists (undefined :: OS.OsString)
_os2 = instanceExists (undefined :: OS.WindowsString)
_os3 = instanceExists (undefined :: OS.PosixString)
#endif

0 comments on commit 4bda416

Please sign in to comment.