Safe Haskell | None |
---|---|
Language | Haskell2010 |
Test.Util.Serialisation.Golden
Contents
Description
Golden tests infrastructure.
Golden tests are implemented using tasty-golden.
When adding a new golden test, running the test suite locally will generate the golden files. These files should be checked in as CI will fail if there are missing golden files.
Failing a golden test suite when the corresponding golden files are not found
is done via the --no-create
flag, which surprisingly is opt-in. In our
nix
infrastructure, this flag for CI is set in
ouroboros-network.nix:
# Command-line options for test suites: packages.ouroboros-consensus-byron-test.components.tests.test.testFlags = lib.mkForce [ "-- >no-create" ]; packages.ouroboros-consensus-shelley-test.components.tests.test.testFlags = lib.mkForce [ "-- >no-create" ]; packages.ouroboros-consensus-cardano-test.components.tests.test.testFlags = lib.mkForce [ "-- >no-create" ];
In particular, if we introduce golden tests in different suites, we need to add a line in the nix configuration above similar to the previous ones, eg:
packages.some-new-package.components.tests.test.testFlags = lib.mkForce [ "-- >no-create" ];
Synopsis
- data Examples blk = Examples {
- exampleBlock ∷ Labelled blk
- exampleSerialisedBlock ∷ Labelled (Serialised blk)
- exampleHeader ∷ Labelled (Header blk)
- exampleSerialisedHeader ∷ Labelled (SerialisedHeader blk)
- exampleHeaderHash ∷ Labelled (HeaderHash blk)
- exampleGenTx ∷ Labelled (GenTx blk)
- exampleGenTxId ∷ Labelled (GenTxId blk)
- exampleApplyTxErr ∷ Labelled (ApplyTxErr blk)
- exampleQuery ∷ Labelled (SomeSecond BlockQuery blk)
- exampleResult ∷ Labelled (SomeResult blk)
- exampleAnnTip ∷ Labelled (AnnTip blk)
- exampleLedgerState ∷ Labelled (LedgerState blk)
- exampleChainDepState ∷ Labelled (ChainDepState (BlockProtocol blk))
- exampleExtLedgerState ∷ Labelled (ExtLedgerState blk)
- exampleSlotNo ∷ Labelled SlotNo
- type Labelled a = [(Maybe String, a)]
- class ToGoldenDirectory a where
- toGoldenDirectory ∷ a → FilePath
- combineExamples ∷ ∀ blk. (∀ a. Labelled a → Labelled a → Labelled a) → Examples blk → Examples blk → Examples blk
- goldenTest_SerialiseDisk ∷ ∀ blk. (SerialiseDiskConstraints blk, HasCallStack) ⇒ CodecConfig blk → FilePath → Examples blk → TestTree
- goldenTest_SerialiseNodeToClient ∷ ∀ blk. (SerialiseNodeToClientConstraints blk, SupportedNetworkProtocolVersion blk, ToGoldenDirectory (QueryVersion, BlockNodeToClientVersion blk), HasCallStack) ⇒ CodecConfig blk → FilePath → Examples blk → TestTree
- goldenTest_SerialiseNodeToNode ∷ ∀ blk. (SerialiseNodeToNodeConstraints blk, SupportedNetworkProtocolVersion blk, ToGoldenDirectory (BlockNodeToNodeVersion blk), HasCallStack) ⇒ CodecConfig blk → FilePath → Examples blk → TestTree
- goldenTest_all ∷ (SerialiseDiskConstraints blk, SerialiseNodeToNodeConstraints blk, SerialiseNodeToClientConstraints blk, SupportedNetworkProtocolVersion blk, ToGoldenDirectory (BlockNodeToNodeVersion blk), ToGoldenDirectory (QueryVersion, BlockNodeToClientVersion blk), HasCallStack) ⇒ CodecConfig blk → FilePath → Examples blk → TestTree
- labelled ∷ [(String, a)] → Labelled a
- mapExamples ∷ ∀ blk. (∀ a. Labelled a → Labelled a) → Examples blk → Examples blk
- prefixExamples ∷ String → Examples blk → Examples blk
- unlabelled ∷ a → Labelled a
Documentation
Constructors
Examples | |
Fields
|
class ToGoldenDirectory a where Source #
Convert a
to a FilePath
that can be used as the directory containing
golden output files.
This class allows overriding the Show
in cases where that output is not
suitable to be used as a directory.
For example, the Show
output for a hard fork enabled NodeToNodeVersion
will contain colons, asterisks, spaces, parentheses, ... and other
characters that we don't want to use for a directory name. For instance
colons cannot be used in Windows file/folder names.
Minimal complete definition
Nothing
Methods
toGoldenDirectory ∷ a → FilePath Source #
default toGoldenDirectory ∷ Show a ⇒ a → FilePath Source #
combineExamples ∷ ∀ blk. (∀ a. Labelled a → Labelled a → Labelled a) → Examples blk → Examples blk → Examples blk Source #
goldenTest_SerialiseDisk ∷ ∀ blk. (SerialiseDiskConstraints blk, HasCallStack) ⇒ CodecConfig blk → FilePath → Examples blk → TestTree Source #
goldenTest_SerialiseNodeToClient ∷ ∀ blk. (SerialiseNodeToClientConstraints blk, SupportedNetworkProtocolVersion blk, ToGoldenDirectory (QueryVersion, BlockNodeToClientVersion blk), HasCallStack) ⇒ CodecConfig blk → FilePath → Examples blk → TestTree Source #
goldenTest_SerialiseNodeToNode ∷ ∀ blk. (SerialiseNodeToNodeConstraints blk, SupportedNetworkProtocolVersion blk, ToGoldenDirectory (BlockNodeToNodeVersion blk), HasCallStack) ⇒ CodecConfig blk → FilePath → Examples blk → TestTree Source #
Arguments
∷ (SerialiseDiskConstraints blk, SerialiseNodeToNodeConstraints blk, SerialiseNodeToClientConstraints blk, SupportedNetworkProtocolVersion blk, ToGoldenDirectory (BlockNodeToNodeVersion blk), ToGoldenDirectory (QueryVersion, BlockNodeToClientVersion blk), HasCallStack) | |
⇒ CodecConfig blk | |
→ FilePath | Path relative to the root of the repository that contains the golden files |
→ Examples blk | |
→ TestTree |
Golden tests for all things we serialise to disk and send across the network.
Exceptions: when an encoder throws an exception, which can happen when
serialising a Shelley header in combination with
CardanoNodeToNodeVersion1
, we show
the exception and use that as the
output.
prefixExamples ∷ String → Examples blk → Examples blk Source #
Add the given prefix to each labelled example.
When a label is empty, the prefix is used as the label. If the label is not
empty, the prefix and _
are prepended.
unlabelled ∷ a → Labelled a Source #