mirror of
https://github.com/haskell-nix/hnix-store.git
synced 2024-11-23 20:56:20 +03:00
tests: custom Arbitrary Trace and Arbitrary ErrorInfo w/o (Just 0)
This commit is contained in:
parent
c815068e60
commit
9fb7854541
@ -7,7 +7,7 @@ import Data.Some (Some(Some))
|
||||
import System.Nix.Arbitrary ()
|
||||
import System.Nix.Store.Remote.Types
|
||||
|
||||
import Test.QuickCheck (Arbitrary(..), oneof)
|
||||
import Test.QuickCheck (Arbitrary(..), oneof, suchThat)
|
||||
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..))
|
||||
|
||||
deriving via GenericArbitrary CheckMode
|
||||
@ -39,14 +39,26 @@ deriving via GenericArbitrary ActivityResult
|
||||
deriving via GenericArbitrary Field
|
||||
instance Arbitrary Field
|
||||
|
||||
deriving via GenericArbitrary Trace
|
||||
instance Arbitrary Trace
|
||||
instance Arbitrary Trace where
|
||||
arbitrary = do
|
||||
-- we encode 0 position as Nothing
|
||||
tracePosition <- arbitrary `suchThat` (/= Just 0)
|
||||
traceHint <- arbitrary
|
||||
|
||||
pure Trace{..}
|
||||
|
||||
deriving via GenericArbitrary BasicError
|
||||
instance Arbitrary BasicError
|
||||
|
||||
deriving via GenericArbitrary ErrorInfo
|
||||
instance Arbitrary ErrorInfo
|
||||
instance Arbitrary ErrorInfo where
|
||||
arbitrary = do
|
||||
errorInfoLevel <- arbitrary
|
||||
errorInfoMessage <- arbitrary
|
||||
-- we encode 0 position as Nothing
|
||||
errorInfoPosition <- arbitrary `suchThat` (/= Just 0)
|
||||
errorInfoTraces <- arbitrary
|
||||
|
||||
pure ErrorInfo{..}
|
||||
|
||||
deriving via GenericArbitrary LoggerOpCode
|
||||
instance Arbitrary LoggerOpCode
|
||||
|
@ -18,7 +18,7 @@ import System.Nix.StorePath (StoreDir)
|
||||
import System.Nix.StorePath.Metadata (Metadata(..))
|
||||
import System.Nix.Store.Remote.Arbitrary ()
|
||||
import System.Nix.Store.Remote.Serializer
|
||||
import System.Nix.Store.Remote.Types.Logger (ErrorInfo(..), Logger(..), Trace(..))
|
||||
import System.Nix.Store.Remote.Types.Logger (Logger(..))
|
||||
import System.Nix.Store.Remote.Types.ProtoVersion (HasProtoVersion(..), ProtoVersion(..))
|
||||
import System.Nix.Store.Remote.Types.StoreConfig (TestStoreConfig)
|
||||
import System.Nix.Store.Remote.Types.WorkerOp (WorkerOp(..))
|
||||
@ -112,19 +112,9 @@ spec = parallel $ do
|
||||
prop "Maybe Activity" $ roundtripS maybeActivity
|
||||
prop "ActivityResult" $ roundtripS activityResult
|
||||
prop "Field" $ roundtripS field
|
||||
prop "Trace"
|
||||
$ forAll (arbitrary `suchThat` ((/= Just 0) . tracePosition))
|
||||
$ roundtripS trace
|
||||
prop "Trace" $ roundtripS trace
|
||||
prop "BasicError" $ roundtripS basicError
|
||||
prop "ErrorInfo"
|
||||
$ forAll (arbitrary
|
||||
`suchThat`
|
||||
(\ErrorInfo{..}
|
||||
-> errorInfoPosition /= Just 0
|
||||
&& all ((/= Just 0) . tracePosition) errorInfoTraces
|
||||
)
|
||||
)
|
||||
$ roundtripS errorInfo
|
||||
prop "ErrorInfo" $ roundtripS errorInfo
|
||||
prop "LoggerOpCode" $ roundtripS loggerOpCode
|
||||
prop "Verbosity" $ roundtripS verbosity
|
||||
prop "Logger"
|
||||
@ -159,12 +149,7 @@ hacks v (Some (QueryMissing _)) | v < ProtoVersion 1 30 = False
|
||||
hacks _ _ = True
|
||||
|
||||
errorInfoIf :: Bool -> Logger -> Bool
|
||||
errorInfoIf True (Logger_Error (Right x)) = noJust0s x
|
||||
where
|
||||
noJust0s :: ErrorInfo -> Bool
|
||||
noJust0s ErrorInfo{..} =
|
||||
errorInfoPosition /= Just 0
|
||||
&& all ((/= Just 0) . tracePosition) errorInfoTraces
|
||||
errorInfoIf True (Logger_Error (Right _)) = True
|
||||
errorInfoIf False (Logger_Error (Left _)) = True
|
||||
errorInfoIf _ (Logger_Error _) = False
|
||||
errorInfoIf _ _ = True
|
||||
|
@ -9,7 +9,6 @@ import Data.Text (Text)
|
||||
import Test.Hspec (Expectation, Spec, describe, it, parallel, shouldBe)
|
||||
import Test.Hspec.QuickCheck (prop)
|
||||
import Test.Hspec.Nix (roundtrips)
|
||||
import Test.QuickCheck (arbitrary, forAll, suchThat)
|
||||
|
||||
import qualified Data.Either
|
||||
import qualified Data.HashSet
|
||||
@ -92,19 +91,9 @@ spec = parallel $ do
|
||||
prop "ActivityID" $ roundtripS @ActivityID
|
||||
prop "Activity" $ roundtripS @Activity
|
||||
prop "Field" $ roundtripS @Field
|
||||
prop "Trace"
|
||||
$ forAll (arbitrary `suchThat` ((/= Just 0) . tracePosition))
|
||||
$ roundtripS @Trace
|
||||
prop "Trace" $ roundtripS @Trace
|
||||
prop "BasicError" $ roundtripS @BasicError
|
||||
prop "ErrorInfo"
|
||||
$ forAll (arbitrary
|
||||
`suchThat`
|
||||
(\ErrorInfo{..}
|
||||
-> errorInfoPosition /= Just 0
|
||||
&& all ((/= Just 0) . tracePosition) errorInfoTraces
|
||||
)
|
||||
)
|
||||
$ roundtripS @ErrorInfo
|
||||
prop "ErrorInfo" $ roundtripS @ErrorInfo
|
||||
prop "LoggerOpCode" $ roundtripS @LoggerOpCode
|
||||
prop "Verbosity" $ roundtripS @Verbosity
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user