Skip to content

Commit c68762f

Browse files
committed
Test the case hack against a NAR fixture with case conflicts
1 parent 0092a29 commit c68762f

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

hnix-store-core/tests/NarFormat.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module NarFormat where
55

66
import qualified Control.Concurrent as Concurrent
77
import Control.Exception (try)
8+
import Data.Binary (Binary(..), decodeFile)
89
import Data.Binary.Get (Get, getByteString,
910
getInt64le,
1011
getLazyByteString, runGet)
@@ -100,6 +101,10 @@ spec_narEncoding = do
100101
it "roundtrips directory" $ do
101102
roundTrip "sampleDirectory" (Nar sampleDirectory)
102103

104+
it "roundtrips case conflicts" $ do
105+
nar <- decodeFile "tests/fixtures/case-conflict.nar"
106+
roundTrip "caseConflict" nar
107+
103108
describe "matches-nix-store fixture" $ do
104109
it "matches regular" $ do
105110
encEqualsNixStore (Nar sampleRegular) sampleRegularBaseline
@@ -115,6 +120,7 @@ spec_narEncoding = do
115120

116121
it "matches directory" $ do
117122
encEqualsNixStore (Nar sampleDirectory) sampleDirectoryBaseline
123+
118124
it "matches symlink to directory" $ do
119125
encEqualsNixStore (Nar sampleLinkToDirectory) sampleLinkToDirectoryBaseline
120126

@@ -578,7 +584,7 @@ filePathPart :: BSC.ByteString -> Maybe FilePathPart
578584
filePathPart p = if BSC.any (`elem` ['/', '\NUL']) p then Nothing else Just $ FilePathPart p
579585

580586
newtype Nar = Nar { narFile :: FileSystemObject }
581-
deriving (Eq, Show)
587+
deriving (Eq, Show, Generic)
582588

583589
-- | A FileSystemObject (FSO) is an anonymous entity that can be NAR archived
584590
data FileSystemObject =
@@ -594,6 +600,9 @@ data FileSystemObject =
594600
newtype FilePathPart = FilePathPart { unFilePathPart :: BSC.ByteString }
595601
deriving (Eq, Ord, Show)
596602

603+
instance Binary Nar where
604+
get = getNar
605+
put = putNar
597606

598607
instance Arbitrary Nar where
599608
arbitrary = Nar <$> resize 10 arbitrary
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!*.nar
3+
!*.*
1000 Bytes
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
# Generate a NAR file with case conflicts in the file names.
4+
mkdir -p case-conflict/bar
5+
touch case-conflict/{Foo.txt,foo.txt,Baz.txt,bar/baz.txt}
6+
7+
storePath=$(nix-store --add ./case-conflict)
8+
nix-store --dump $storePath > case-conflict.nar

0 commit comments

Comments
 (0)