File tree Expand file tree Collapse file tree 5 files changed +28
-4
lines changed
src/System/Nix/Store/Remote Expand file tree Collapse file tree 5 files changed +28
-4
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ import Data.Binary.Get
1111import Data.Binary.Put
1212import Data.Text (Text )
1313import 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
1417import Data.Time
1518import Data.Time.Clock.POSIX
1619import Data.ByteString (ByteString )
@@ -91,13 +94,16 @@ sockGetPaths = do
9194 getSocketIncremental (getPaths sd)
9295
9396bsToText :: ByteString -> Text
94- bsToText = T. pack . BSC. unpack
97+ bsToText = T. decodeUtf8
98+
99+ textToBS :: Text -> ByteString
100+ textToBS = T. encodeUtf8
95101
96102bslToText :: BSL. ByteString -> Text
97- bslToText = T. pack . BSC. unpack . BSL. toStrict
103+ bslToText = TL. toStrict . TL. decodeUtf8
98104
99105textToBSL :: Text -> BSL. ByteString
100- textToBSL = BSL. fromStrict . BSC. pack . T. unpack
106+ textToBSL = TL. encodeUtf8 . TL. fromStrict
101107
102108putText :: Text -> Put
103109putText = putByteStringLen . textToBSL
Original file line number Diff line number Diff line change 11import Test.Tasty.Hspec
22import NixDaemon
3+ import qualified Spec
34
45-- we run remote tests in
56-- Linux namespaces to avoid interacting with systems store
67main = do
78 enterNamespaces
8- hspec spec_protocol
9+ Spec. main
Original file line number Diff line number Diff line change 1+ {-# OPTIONS_GHC -F -pgmF tasty-discover -optF --generated -module=Spec #-}
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments