nextest_runner/output_spec.rs
1// Copyright (c) The nextest Contributors
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Specifies how test output is represented.
5//!
6//! The [`OutputSpec`] trait abstracts over two modes of output storage:
7//!
8//! - [`LiveSpec`]: output stored in memory during live execution, using
9//! [`ChildOutputDescription`].
10//! - [`RecordingSpec`]: output stored in recordings,
11//! using [`ZipStoreOutputDescription`].
12//!
13//! Types generic over `S: OutputSpec` use `S::ChildOutputDesc` for their output
14//! description fields. This enables adding additional associated types in the
15//! future without changing every generic type's parameter list.
16
17use crate::{record::ZipStoreOutputDescription, reporter::events::ChildOutputDescription};
18use serde::{Serialize, de::DeserializeOwned};
19
20/// Specifies how test output is represented.
21///
22/// Two implementations exist:
23///
24/// - [`LiveSpec`]: output stored in memory during live execution.
25/// - [`RecordingSpec`]: output stored in recordings.
26pub trait OutputSpec {
27 /// The type used to describe child output.
28 type ChildOutputDesc;
29}
30
31/// Output spec for live test execution.
32///
33/// Uses [`ChildOutputDescription`] for in-memory byte buffers with lazy UTF-8
34/// string conversion.
35pub struct LiveSpec;
36
37impl OutputSpec for LiveSpec {
38 type ChildOutputDesc = ChildOutputDescription;
39}
40
41/// Output spec for recorded/replayed test runs.
42///
43/// Uses [`ZipStoreOutputDescription`] for content-addressed file references in
44/// zip archives.
45pub struct RecordingSpec;
46
47impl OutputSpec for RecordingSpec {
48 type ChildOutputDesc = ZipStoreOutputDescription;
49}
50
51/// An [`OutputSpec`] that supports serialization and deserialization.
52pub trait SerializableOutputSpec:
53 OutputSpec<ChildOutputDesc: Serialize + DeserializeOwned>
54{
55}
56
57impl<S> SerializableOutputSpec for S
58where
59 S: OutputSpec,
60 S::ChildOutputDesc: Serialize + DeserializeOwned,
61{
62}
63
64/// An [`OutputSpec`] that supports generation via
65/// [`proptest::arbitrary::Arbitrary`].
66#[cfg(test)]
67pub(crate) trait ArbitraryOutputSpec:
68 OutputSpec<ChildOutputDesc: proptest::arbitrary::Arbitrary + PartialEq + 'static> + 'static
69{
70}
71
72#[cfg(test)]
73impl<S> ArbitraryOutputSpec for S
74where
75 S: OutputSpec + 'static,
76 S::ChildOutputDesc: proptest::arbitrary::Arbitrary + PartialEq + 'static,
77{
78}