Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- cddlRoundTripCborSpec ∷ ∀ a. (HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR a) ⇒ Version → Text → SpecWith CddlData
- cddlRoundTripExpectation ∷ (HasCallStack, Show a, Eq a) ⇒ Text → Version → Version → Trip a a → CddlVarFile → Expectation
- cddlRoundTripAnnCborSpec ∷ ∀ a. (HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) ⇒ Version → Text → SpecWith CddlData
- cddlRoundTripAnnExpectation ∷ ∀ a. (HasCallStack, Show a, Eq a) ⇒ Text → Version → Version → Trip a (Annotator a) → CddlVarFile → Expectation
- newtype Cddl = Cddl {
- unCddl ∷ ByteString
- newtype Cbor = Cbor {
- unCbor ∷ ByteString
- newtype DiagCbor = DiagCbor {
- unDiagCbor ∷ ByteString
- data CddlData = CddlData {
- cddlData ∷ !Cddl
- cddlNumExamples ∷ !Int
- data CddlVarFile = CddlVarFile {}
- beforeAllCddlFile ∷ HasCallStack ⇒ Int → IO [ByteString] → SpecWith CddlData → Spec
- withCddlVarFile ∷ HasCallStack ⇒ Text → CddlData → (CddlVarFile → IO b) → IO b
- genCddlDiagCbor ∷ HasCallStack ⇒ Int → Cddl → IO [DiagCbor]
- diagCborToCbor ∷ HasCallStack ⇒ DiagCbor → IO Cbor
- validateCddlConformance ∷ FilePath → ByteString → IO (Either String ByteString)
- readProcessNoFailure ∷ String → ProcessConfig stdin stdout stderr → ByteString → IO (Either String ByteString)
- usingTempFile ∷ ByteString → (FilePath → IO a) → IO a
Documentation
cddlRoundTripCborSpec Source #
∷ ∀ a. (HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR a) | |
⇒ Version | Serialization version |
→ Text | Name of the CDDL variable to test |
→ SpecWith CddlData |
Using the supplied CddlData
inside the SpecWith
generate random data and run the
cddlRoundTripExpectation
for the supplied CDDL variable
cddlRoundTripExpectation Source #
∷ (HasCallStack, Show a, Eq a) | |
⇒ Text | |
→ Version | Version to use for decoding |
→ Version | Version to use for encoding |
→ Trip a a | Decode/encoder that needs tsting |
→ CddlVarFile | Randomly generated data and the CDDL spec |
→ Expectation |
Verify that random data generated is:
- Decoded successfully into a Haskell type using the decoder in
Trip
and the version supplied - When reencoded conforms to the CDDL spec and produces valid
FlatTerm
- When decoded again from the bytes produced by the encoder matches the type exactly when it was decoded from random bytes
cddlRoundTripAnnCborSpec Source #
∷ ∀ a. (HasCallStack, Eq a, Show a, EncCBOR a, DecCBOR (Annotator a)) | |
⇒ Version | Serialization version |
→ Text | Cddl variable name |
→ SpecWith CddlData |
Similar to cddlRoundTripCborSpec
, but for Annotator.
cddlRoundTripAnnExpectation ∷ ∀ a. (HasCallStack, Show a, Eq a) ⇒ Text → Version → Version → Trip a (Annotator a) → CddlVarFile → Expectation Source #
Same as cddlRoundTripExpectation
, but works for decoders that are wrapped into
Annotator
Helper functions and types
Human readable CBOR, which was randomly generated.
DiagCbor | |
|
CddlData | |
|
data CddlVarFile Source #
CddlVarFile | |
|
∷ HasCallStack | |
⇒ Int | Number of random cases to generate |
→ IO [ByteString] | Action that produces a list of valid CDDL specs |
→ SpecWith CddlData | |
→ Spec |
Given an action that produces CDDL content, we combine it all into CddlData
and
make it available to every subsequent Spec. Important point about this is that the
supplied action will only be executed once.
∷ HasCallStack | |
⇒ Text | Name of the variable that will be tested |
→ CddlData | CddlData that will be used for random data generation |
→ (CddlVarFile → IO b) | Action that can use the random data for roundtrip and conformance testing |
→ IO b |
Given a CddlData
and a CDDL variable name present in the supplied data, generate a
CddlVarFile
, that contains random data for that variable.
genCddlDiagCbor ∷ HasCallStack ⇒ Int → Cddl → IO [DiagCbor] Source #
diagCborToCbor ∷ HasCallStack ⇒ DiagCbor → IO Cbor Source #
Convert randomly generated Cbor in special Diag (human readable) format to binary CBOR format
validateCddlConformance Source #
∷ FilePath | File path to the file with CDDL spec |
→ ByteString | CBOR encoded data that should conform with CDDL spec |
→ IO (Either String ByteString) |
Run a cddl
process and validate that encoded data is in confomrance with the
supplied CDDL spec
readProcessNoFailure ∷ String → ProcessConfig stdin stdout stderr → ByteString → IO (Either String ByteString) Source #
Run a process with readProcess
and return Left
on failure, which will contain the
output produced on stderr
. Accepts lazy bytestring as input for the spawned
process. In case when a process exits successfuly, the output is returned on the
Right
. Upon a successful exit, stderr
output is ignored to avoid polluting test
suite output with copious amounts of warnings.
usingTempFile ∷ ByteString → (FilePath → IO a) → IO a Source #
Write binary data to a temporary file and apply an action to a temporary file name path that contains that data. File is guaranteed to be alive only until the supplied action is active, therefore make sure not to return the name for the temporary file name.