Skip to content

Commit 4f50de3

Browse files
authored
Merge pull request #10270 from haskell/wip/structured-hash-fix
tests: Make structured hash tests invariant to GHC version
2 parents 9b3ce92 + b90ccb3 commit 4f50de3

File tree

3 files changed

+43
-27
lines changed

3 files changed

+43
-27
lines changed

Cabal-syntax/src/Distribution/Utils/Structured.hs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{-# LANGUAGE PatternSynonyms #-}
66
{-# LANGUAGE PolyKinds #-}
77
{-# LANGUAGE ScopedTypeVariables #-}
8+
{-# LANGUAGE TypeApplications #-}
89
{-# LANGUAGE TypeFamilies #-}
910
{-# LANGUAGE TypeOperators #-}
1011

@@ -418,12 +419,42 @@ instance Structured a => Structured (Ratio a) where structure = containerStructu
418419
instance Structured a => Structured [a] where structure = containerStructure
419420
instance Structured a => Structured (NonEmpty a) where structure = containerStructure
420421

421-
instance (Structured a1, Structured a2) => Structured (a1, a2)
422-
instance (Structured a1, Structured a2, Structured a3) => Structured (a1, a2, a3)
423-
instance (Structured a1, Structured a2, Structured a3, Structured a4) => Structured (a1, a2, a3, a4)
424-
instance (Structured a1, Structured a2, Structured a3, Structured a4, Structured a5) => Structured (a1, a2, a3, a4, a5)
425-
instance (Structured a1, Structured a2, Structured a3, Structured a4, Structured a5, Structured a6) => Structured (a1, a2, a3, a4, a5, a6)
426-
instance (Structured a1, Structured a2, Structured a3, Structured a4, Structured a5, Structured a6, Structured a7) => Structured (a1, a2, a3, a4, a5, a6, a7)
422+
-- These instances are defined directly because the generic names for tuples changed
423+
-- in 9.6 (https://gitlab.haskell.org/ghc/ghc/-/issues/24291).
424+
--
425+
-- By defining our own instances the STuple2 identifier will be used in the hash and
426+
-- hence the same on all GHC versions.
427+
428+
data STuple2 a b = STuple2 a b deriving (Generic)
429+
data STuple3 a b c = STuple3 a b c deriving (Generic)
430+
data STuple4 a b c d = STuple4 a b c d deriving (Generic)
431+
data STuple5 a b c d e = STuple5 a b c d e deriving (Generic)
432+
data STuple6 a b c d e f = STuple6 a b c d e f deriving (Generic)
433+
data STuple7 a b c d e f g = STuple7 a b c d e f g deriving (Generic)
434+
435+
instance (Structured a1, Structured a2) => Structured (STuple2 a1 a2)
436+
instance (Structured a1, Structured a2) => Structured (a1, a2) where
437+
structure Proxy = structure @(STuple2 a1 a2) Proxy
438+
439+
instance (Structured a1, Structured a2, Structured a3) => Structured (STuple3 a1 a2 a3)
440+
instance (Structured a1, Structured a2, Structured a3) => Structured (a1, a2, a3) where
441+
structure Proxy = structure @(STuple3 a1 a2 a3) Proxy
442+
443+
instance (Structured a1, Structured a2, Structured a3, Structured a4) => Structured (STuple4 a1 a2 a3 a4)
444+
instance (Structured a1, Structured a2, Structured a3, Structured a4) => Structured (a1, a2, a3, a4) where
445+
structure Proxy = structure @(STuple4 a1 a2 a3 a4) Proxy
446+
447+
instance (Structured a1, Structured a2, Structured a3, Structured a4, Structured a5) => Structured (STuple5 a1 a2 a3 a4 a5)
448+
instance (Structured a1, Structured a2, Structured a3, Structured a4, Structured a5) => Structured (a1, a2, a3, a4, a5) where
449+
structure Proxy = structure @(STuple5 a1 a2 a3 a4 a5) Proxy
450+
451+
instance (Structured a1, Structured a2, Structured a3, Structured a4, Structured a5, Structured a6) => Structured (STuple6 a1 a2 a3 a4 a5 a6)
452+
instance (Structured a1, Structured a2, Structured a3, Structured a4, Structured a5, Structured a6) => Structured (a1, a2, a3, a4, a5, a6) where
453+
structure Proxy = structure @(STuple6 a1 a2 a3 a4 a5 a6) Proxy
454+
455+
instance (Structured a1, Structured a2, Structured a3, Structured a4, Structured a5, Structured a6, Structured a7) => Structured (STuple7 a1 a2 a3 a4 a5 a6 a7)
456+
instance (Structured a1, Structured a2, Structured a3, Structured a4, Structured a5, Structured a6, Structured a7) => Structured (a1, a2, a3, a4, a5, a6, a7) where
457+
structure Proxy = structure @(STuple7 a1 a2 a3 a4 a5 a6 a7) Proxy
427458

428459
instance Structured BS.ByteString where structure = nominalStructure
429460
instance Structured LBS.ByteString where structure = nominalStructure

Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,8 @@ md5Check proxy md5Int = structureHash proxy @?= md5FromInteger md5Int
3030

3131
md5CheckGenericPackageDescription :: Proxy GenericPackageDescription -> Assertion
3232
md5CheckGenericPackageDescription proxy = md5Check proxy
33-
#if MIN_VERSION_base(4,19,0)
34-
0x62ad178a75f041af29947c9b3d83e6ed
35-
#else
36-
0xba8f0baa8074fd238ad36a309399349e
37-
#endif
33+
0xe40d8d67b85712f245354657d7a80165
3834

3935
md5CheckLocalBuildInfo :: Proxy LocalBuildInfo -> Assertion
4036
md5CheckLocalBuildInfo proxy = md5Check proxy
41-
#if MIN_VERSION_base(4,19,0)
42-
0xc68e9c0758c4bf2d72fe82b3d55cee34
43-
#else
44-
0xcf7e7bbcaec504d745fe086eec1786ff
45-
#endif
37+
0xb0a61f1d93717a92b2b4ecbe0bc3abd4

cabal-install/tests/UnitTests/Distribution/Client/FileMonitor.hs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,10 @@ tests mtimeChange =
8888
Windows -> expectFailBecause msg
8989
_ -> id
9090
fingerprintStateGlob1, fingerprintStateGlob2, fingerprintStateFileSet1, fingerprintStateFileSet2 :: Word64
91-
#if MIN_VERSION_base(4,19,0)
92-
fingerprintStateGlob1 = 0x4ebc6a7d12bb2132
93-
fingerprintStateGlob2 = 0x2c2292eeda0a9319
94-
fingerprintStateFileSet1 = 0x01df5796f9030851
95-
fingerprintStateFileSet2 = 0x2f5c472be17bee98
96-
#else
97-
fingerprintStateGlob1 = 0xf32c0d1644dd9ee5
98-
fingerprintStateGlob2 = 0x0f2494f7b6031fb6
99-
fingerprintStateFileSet1 = 0x06d4a13275c24282
100-
fingerprintStateFileSet2 = 0x791b2a88684b5f37
101-
#endif
91+
fingerprintStateGlob1 = 0x8d6292a27f48ab78
92+
fingerprintStateGlob2 = 0xa69393cf17cb6c71
93+
fingerprintStateFileSet1 = 0x441fcb5eaf403013
94+
fingerprintStateFileSet2 = 0x129db82bba47f56f
10295

10396
-- Check the file system behaves the way we expect it to
10497

0 commit comments

Comments
 (0)