From 7dc5c596aac604a3c3da598d3fc2f3cccb128755 Mon Sep 17 00:00:00 2001 From: sorki Date: Thu, 7 Dec 2023 07:12:27 +0100 Subject: [PATCH] tests: add/move Test.Hspec.Nix.forceRight from json --- hnix-store-core/tests/Fingerprint.hs | 2 +- hnix-store-json/tests/JSONSpec.hs | 10 +--------- hnix-store-tests/src/Test/Hspec/Nix.hs | 11 ++++++++++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/hnix-store-core/tests/Fingerprint.hs b/hnix-store-core/tests/Fingerprint.hs index 8874ffc..77c890d 100644 --- a/hnix-store-core/tests/Fingerprint.hs +++ b/hnix-store-core/tests/Fingerprint.hs @@ -69,5 +69,5 @@ forceDecodeB64Pubkey b64EncodedPubkey = let forceRight :: Either a b -> b forceRight = \case Right x -> x - _ -> error "fromRight failed" + _ -> error "forceRight failed" diff --git a/hnix-store-json/tests/JSONSpec.hs b/hnix-store-json/tests/JSONSpec.hs index df26ae4..6aad8a8 100644 --- a/hnix-store-json/tests/JSONSpec.hs +++ b/hnix-store-json/tests/JSONSpec.hs @@ -5,7 +5,7 @@ import Data.Aeson (ToJSON, FromJSON, decode, encode) import Data.Default.Class (Default(def)) import Test.Hspec (Expectation, Spec, describe, it, shouldBe) import Test.Hspec.QuickCheck (prop) -import Test.Hspec.Nix (roundtrips) +import Test.Hspec.Nix (forceRight, roundtrips) import System.Nix.Arbitrary () import System.Nix.JSON () @@ -99,11 +99,3 @@ spec = do it "sampleRealisation1 matches preimage" $ encode sampleRealisation1 `shouldBe` "{\"outPath\":\"5rwxzi7pal3qhpsyfc16gzkh939q1np6-curl-7.82.0.drv\",\"signatures\":[\"SMjnB3mPgXYjXacU+xN24BdzXlAgGAuFnYwPddU3bhjfHBeQus/OimdIPMgR/JMKFPHXORrk7pbjv68vecTEBA==\",\"fW3iEMfyx6IZzGNswD54BjclfkXiYzh0xRXddrXfJ1rp1l8p1xTi9/0g2EibbwLFb6p83cwIJv5KtTGksC54CQ==\"],\"dependentRealisations\":{\"sha256:1b4sb93wp679q4zx9k1ignby1yna3z7c4c2ri3wphylbc2dwsys0!foo\":\"9472ijanf79nlkb5n1yh57s7867p1930-testFixed\"}}" - -forceRight - :: Show a - => Either a b - -> b -forceRight = \case - Right x -> x - Left e -> error $ "fromRight failed: " ++ show e diff --git a/hnix-store-tests/src/Test/Hspec/Nix.hs b/hnix-store-tests/src/Test/Hspec/Nix.hs index 01416d9..814ca8f 100644 --- a/hnix-store-tests/src/Test/Hspec/Nix.hs +++ b/hnix-store-tests/src/Test/Hspec/Nix.hs @@ -1,5 +1,6 @@ module Test.Hspec.Nix - ( roundtrips + ( forceRight + , roundtrips ) where import Test.Hspec (Expectation, shouldBe) @@ -18,3 +19,11 @@ roundtrips -> Expectation roundtrips encode decode x = decode (encode x) `shouldBe` pure x + +forceRight + :: Show a + => Either a b + -> b +forceRight = \case + Right x -> x + Left e -> error $ "forceRight failed: " ++ show e