Skip to content

Commit 5349e56

Browse files
authored
[nextest-runner] use subtraits for Serialize/Arbitrary bounds (#3092)
We're going to add a second `LogFile` associated type -- avoid having to add bounds everywhere.
1 parent ac25b4d commit 5349e56

File tree

3 files changed

+59
-28
lines changed

3 files changed

+59
-28
lines changed

nextest-runner/src/output_spec.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//! future without changing every generic type's parameter list.
1616
1717
use crate::{record::ZipStoreOutputDescription, reporter::events::ChildOutputDescription};
18+
use serde::{Serialize, de::DeserializeOwned};
1819

1920
/// Specifies how test output is represented.
2021
///
@@ -46,3 +47,32 @@ pub struct RecordingSpec;
4647
impl OutputSpec for RecordingSpec {
4748
type ChildOutputDesc = ZipStoreOutputDescription;
4849
}
50+
51+
/// An [`OutputSpec`] that supports serialization and deserialization.
52+
pub trait SerializableOutputSpec:
53+
OutputSpec<ChildOutputDesc: Serialize + DeserializeOwned>
54+
{
55+
}
56+
57+
impl<S> SerializableOutputSpec for S
58+
where
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)]
67+
pub(crate) trait ArbitraryOutputSpec:
68+
OutputSpec<ChildOutputDesc: proptest::arbitrary::Arbitrary + PartialEq + 'static> + 'static
69+
{
70+
}
71+
72+
#[cfg(test)]
73+
impl<S> ArbitraryOutputSpec for S
74+
where
75+
S: OutputSpec + 'static,
76+
S::ChildOutputDesc: proptest::arbitrary::Arbitrary + PartialEq + 'static,
77+
{
78+
}

nextest-runner/src/record/summary.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
//! - [`RecordingSpec`](crate::output_spec::RecordingSpec): reference to a file stored
1515
//! in the zip archive.
1616
17+
#[cfg(test)]
18+
use crate::output_spec::ArbitraryOutputSpec;
1719
use crate::{
1820
config::scripts::ScriptId,
1921
list::OwnedTestInstanceId,
20-
output_spec::{LiveSpec, OutputSpec},
22+
output_spec::{LiveSpec, OutputSpec, SerializableOutputSpec},
2123
reporter::{
2224
TestOutputDisplay,
2325
events::{
@@ -71,14 +73,14 @@ impl RecordOpts {
7173
#[serde(
7274
rename_all = "kebab-case",
7375
bound(
74-
serialize = "S::ChildOutputDesc: Serialize",
75-
deserialize = "S::ChildOutputDesc: serde::de::DeserializeOwned"
76+
serialize = "S: SerializableOutputSpec",
77+
deserialize = "S: SerializableOutputSpec"
7678
)
7779
)]
7880
#[cfg_attr(
7981
test,
8082
derive(test_strategy::Arbitrary),
81-
arbitrary(bound(S: 'static, S::ChildOutputDesc: proptest::arbitrary::Arbitrary + PartialEq + 'static))
83+
arbitrary(bound(S: ArbitraryOutputSpec))
8284
)]
8385
pub struct TestEventSummary<S: OutputSpec> {
8486
/// The timestamp of the event.
@@ -126,14 +128,14 @@ impl TestEventSummary<LiveSpec> {
126128
tag = "type",
127129
rename_all = "kebab-case",
128130
bound(
129-
serialize = "S::ChildOutputDesc: Serialize",
130-
deserialize = "S::ChildOutputDesc: serde::de::DeserializeOwned"
131+
serialize = "S: SerializableOutputSpec",
132+
deserialize = "S: SerializableOutputSpec"
131133
)
132134
)]
133135
#[cfg_attr(
134136
test,
135137
derive(test_strategy::Arbitrary),
136-
arbitrary(bound(S: 'static, S::ChildOutputDesc: proptest::arbitrary::Arbitrary + PartialEq + 'static))
138+
arbitrary(bound(S: ArbitraryOutputSpec))
137139
)]
138140
pub enum TestEventKindSummary<S: OutputSpec> {
139141
/// An event that doesn't carry output.
@@ -352,14 +354,14 @@ pub struct TestsNotSeenSummary {
352354
tag = "kind",
353355
rename_all = "kebab-case",
354356
bound(
355-
serialize = "S::ChildOutputDesc: Serialize",
356-
deserialize = "S::ChildOutputDesc: serde::de::DeserializeOwned"
357+
serialize = "S: SerializableOutputSpec",
358+
deserialize = "S: SerializableOutputSpec"
357359
)
358360
)]
359361
#[cfg_attr(
360362
test,
361363
derive(test_strategy::Arbitrary),
362-
arbitrary(bound(S: 'static, S::ChildOutputDesc: proptest::arbitrary::Arbitrary + PartialEq + 'static))
364+
arbitrary(bound(S: ArbitraryOutputSpec))
363365
)]
364366
pub enum OutputEventKind<S: OutputSpec> {
365367
/// A setup script finished.

nextest-runner/src/reporter/events.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
//! reporter. The root structure for all events is [`TestEvent`].
88
99
use super::{FinalStatusLevel, StatusLevel, TestOutputDisplay};
10+
#[cfg(test)]
11+
use crate::output_spec::ArbitraryOutputSpec;
1012
use crate::{
1113
config::{
1214
elements::{LeakTimeoutResult, SlowTimeoutResult},
1315
scripts::ScriptId,
1416
},
1517
errors::{ChildError, ChildFdError, ChildStartError, ErrorList},
1618
list::{OwnedTestInstanceId, TestInstanceId, TestList},
17-
output_spec::{LiveSpec, OutputSpec},
19+
output_spec::{LiveSpec, OutputSpec, SerializableOutputSpec},
1820
runner::{StressCondition, StressCount},
1921
test_output::{ChildExecutionOutput, ChildOutput, ChildSingleOutput},
2022
};
@@ -874,30 +876,27 @@ pub enum RunStatsFailureKind {
874876
#[derive(Serialize)]
875877
#[serde(
876878
rename_all = "kebab-case",
877-
bound(serialize = "S::ChildOutputDesc: Serialize")
879+
bound(serialize = "S: SerializableOutputSpec")
878880
)]
879881
#[cfg_attr(
880882
test,
881883
derive(test_strategy::Arbitrary),
882-
arbitrary(bound(S: 'static, S::ChildOutputDesc: proptest::arbitrary::Arbitrary + std::fmt::Debug + 'static))
884+
arbitrary(bound(S: ArbitraryOutputSpec))
883885
)]
884886
pub struct ExecutionStatuses<S: OutputSpec> {
885887
/// This is guaranteed to be non-empty.
886888
#[cfg_attr(test, strategy(proptest::collection::vec(proptest::arbitrary::any::<ExecuteStatus<S>>(), 1..=3)))]
887889
statuses: Vec<ExecuteStatus<S>>,
888890
}
889891

890-
impl<'de, S: OutputSpec> Deserialize<'de> for ExecutionStatuses<S>
891-
where
892-
S::ChildOutputDesc: serde::de::DeserializeOwned,
893-
{
892+
impl<'de, S: SerializableOutputSpec> Deserialize<'de> for ExecutionStatuses<S> {
894893
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
895894
// Deserialize as the wrapper struct that matches the Serialize output.
896-
// S is already bound as OutputSpec on this impl.
895+
// S is already bound as SerializableOutputSpec on this impl.
897896
#[derive(Deserialize)]
898897
#[serde(
899898
rename_all = "kebab-case",
900-
bound(deserialize = "S::ChildOutputDesc: serde::de::DeserializeOwned")
899+
bound(deserialize = "S: SerializableOutputSpec")
901900
)]
902901
struct Helper<S: OutputSpec> {
903902
statuses: Vec<ExecuteStatus<S>>,
@@ -1134,14 +1133,14 @@ pub struct OutputErrorSlice {
11341133
#[serde(
11351134
rename_all = "kebab-case",
11361135
bound(
1137-
serialize = "S::ChildOutputDesc: Serialize",
1138-
deserialize = "S::ChildOutputDesc: serde::de::DeserializeOwned"
1136+
serialize = "S: SerializableOutputSpec",
1137+
deserialize = "S: SerializableOutputSpec"
11391138
)
11401139
)]
11411140
#[cfg_attr(
11421141
test,
11431142
derive(test_strategy::Arbitrary),
1144-
arbitrary(bound(S: 'static, S::ChildOutputDesc: proptest::arbitrary::Arbitrary + std::fmt::Debug + 'static))
1143+
arbitrary(bound(S: ArbitraryOutputSpec))
11451144
)]
11461145
pub struct ExecuteStatus<S: OutputSpec> {
11471146
/// Retry-related data.
@@ -1189,14 +1188,14 @@ pub struct ExecuteStatus<S: OutputSpec> {
11891188
#[serde(
11901189
rename_all = "kebab-case",
11911190
bound(
1192-
serialize = "S::ChildOutputDesc: Serialize",
1193-
deserialize = "S::ChildOutputDesc: serde::de::DeserializeOwned"
1191+
serialize = "S: SerializableOutputSpec",
1192+
deserialize = "S: SerializableOutputSpec"
11941193
)
11951194
)]
11961195
#[cfg_attr(
11971196
test,
11981197
derive(test_strategy::Arbitrary),
1199-
arbitrary(bound(S: 'static, S::ChildOutputDesc: proptest::arbitrary::Arbitrary + std::fmt::Debug + 'static))
1198+
arbitrary(bound(S: ArbitraryOutputSpec))
12001199
)]
12011200
pub struct SetupScriptExecuteStatus<S: OutputSpec> {
12021201
/// Output for this setup script.
@@ -1257,14 +1256,14 @@ pub struct SetupScriptEnvMap {
12571256
tag = "type",
12581257
rename_all = "kebab-case",
12591258
bound(
1260-
serialize = "S::ChildOutputDesc: Serialize",
1261-
deserialize = "S::ChildOutputDesc: serde::de::DeserializeOwned"
1259+
serialize = "S: SerializableOutputSpec",
1260+
deserialize = "S: SerializableOutputSpec"
12621261
)
12631262
)]
12641263
#[cfg_attr(
12651264
test,
12661265
derive(test_strategy::Arbitrary),
1267-
arbitrary(bound(S: 'static, S::ChildOutputDesc: proptest::arbitrary::Arbitrary + std::fmt::Debug + 'static))
1266+
arbitrary(bound(S: ArbitraryOutputSpec))
12681267
)]
12691268
pub enum ChildExecutionOutputDescription<S: OutputSpec> {
12701269
/// The process was run and the output was captured.

0 commit comments

Comments
 (0)