Skip to content

Commit 8508b9f

Browse files
committed
Merge branch 'fix-encoding' into dev
2 parents 272cc6f + ffc0cc4 commit 8508b9f

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

hnix-store-remote/hnix-store-remote.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ test-suite hnix-store-remote-tests
6262
main-is: Driver.hs
6363
other-modules: Derivation
6464
, NixDaemon
65+
, Spec
66+
, Util
6567
hs-source-dirs: tests
6668
build-depends:
6769
attoparsec
@@ -76,6 +78,7 @@ test-suite hnix-store-remote-tests
7678
, process
7779
, filepath
7880
, hspec-expectations-lifted
81+
, quickcheck-text
7982
, tasty
8083
, tasty-discover
8184
, tasty-hspec

hnix-store-remote/src/System/Nix/Store/Remote/Util.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import Data.Binary.Get
1111
import Data.Binary.Put
1212
import Data.Text (Text)
1313
import qualified Data.Text as T
14+
import qualified Data.Text.Encoding as T
15+
import qualified Data.Text.Lazy as TL
16+
import qualified Data.Text.Lazy.Encoding as TL
1417
import Data.Time
1518
import Data.Time.Clock.POSIX
1619
import Data.ByteString (ByteString)
@@ -91,13 +94,16 @@ sockGetPaths = do
9194
getSocketIncremental (getPaths sd)
9295

9396
bsToText :: ByteString -> Text
94-
bsToText = T.pack . BSC.unpack
97+
bsToText = T.decodeUtf8
98+
99+
textToBS :: Text -> ByteString
100+
textToBS = T.encodeUtf8
95101

96102
bslToText :: BSL.ByteString -> Text
97-
bslToText = T.pack . BSC.unpack . BSL.toStrict
103+
bslToText = TL.toStrict . TL.decodeUtf8
98104

99105
textToBSL :: Text -> BSL.ByteString
100-
textToBSL = BSL.fromStrict . BSC.pack . T.unpack
106+
textToBSL = TL.encodeUtf8 . TL.fromStrict
101107

102108
putText :: Text -> Put
103109
putText = putByteStringLen . textToBSL

hnix-store-remote/tests/Driver.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import Test.Tasty.Hspec
22
import NixDaemon
3+
import qualified Spec
34

45
-- we run remote tests in
56
-- Linux namespaces to avoid interacting with systems store
67
main = do
78
enterNamespaces
8-
hspec spec_protocol
9+
Spec.main

hnix-store-remote/tests/Spec.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{-# OPTIONS_GHC -F -pgmF tasty-discover -optF --generated-module=Spec #-}

hnix-store-remote/tests/Util.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
module Util where
3+
4+
import Test.Tasty.QuickCheck
5+
import Data.Text.Arbitrary
6+
7+
import System.Nix.Store.Remote.Util
8+
9+
prop_TextToBSLRoundtrip x =
10+
bslToText (textToBSL x) === x
11+
12+
prop_TextToBSRoundtrip x =
13+
bsToText (textToBS x) === x

0 commit comments

Comments
 (0)