Skip to content

Commit

Permalink
[replays-dont-count-cases] persisted failures are not counted against…
Browse files Browse the repository at this point in the history
… successful cases.

this way when `PROPTEST_CASES` <= `number of persisted cases` we
will not end up never creating new cases to test against. rather,
all persisted cases will be tested _and then_ a new number of cases
will run equal to the number of `PROPTEST_CASES`.
  • Loading branch information
rex-remind101 committed Jan 31, 2023
1 parent f8eff50 commit a854d2e
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 47 deletions.
11 changes: 7 additions & 4 deletions proptest-derive/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ impl ToTokens for ToReg {
ToReg::Range(to) => {
let params: Vec<_> = (0..to).map(param).collect();
NestedTuple(&params).to_tokens(tokens)
},
}
ToReg::API => call_site_ident(API_PARAM_NAME).to_tokens(tokens),
}
}
Expand Down Expand Up @@ -520,8 +520,7 @@ impl<'a, T: ToTokens> ToTokens for NestedTuple<'a, T> {
let NestedTuple(elems) = self;
if elems.is_empty() {
quote_append!(tokens, ());
}
else if let [x] = elems {
} else if let [x] = elems {
x.to_tokens(tokens);
} else {
let chunks = elems.chunks(NESTED_TUPLE_CHUNK_SIZE);
Expand All @@ -547,7 +546,11 @@ impl<'a, T: ToTokens> ToTokens for NestedTuple<'a, T> {
}
}

fn map_ctor_to_tokens(tokens: &mut TokenStream, ctors: &[Ctor], closure: &MapClosure) {
fn map_ctor_to_tokens(
tokens: &mut TokenStream,
ctors: &[Ctor],
closure: &MapClosure,
) {
let ctors = NestedTuple(ctors);

quote_append!(tokens,
Expand Down
2 changes: 1 addition & 1 deletion proptest-derive/tests/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ enum ZeroOneTwo {
#[derive(Arbitrary, Debug)]
enum Nested {
First(SameType),
Second(ZeroOneTwo, OneTwo)
Second(ZeroOneTwo, OneTwo),
}

#[test]
Expand Down
1 change: 0 additions & 1 deletion proptest-derive/tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ enum Quux {
},
}


#[test]
fn asserting_arbitrary() {
fn assert_arbitrary<T: Arbitrary>() {}
Expand Down
4 changes: 2 additions & 2 deletions proptest-derive/tests/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use proptest_derive::Arbitrary;

#[derive(Debug, Arbitrary)]
struct T1 {
f1: u8
f1: u8,
}

#[derive(Debug, Arbitrary)]
Expand Down Expand Up @@ -104,7 +104,7 @@ struct T20 {
f17: u128,
f18: f32,
f19: f64,
f20: bool
f20: bool,
}

#[test]
Expand Down
1 change: 0 additions & 1 deletion proptest/src/arbitrary/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ impl<A: Arbitrary, const N: usize> Arbitrary for [A; N] {
}
}


#[cfg(test)]
mod test {
no_panic_test!(
Expand Down
7 changes: 1 addition & 6 deletions proptest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@
))]
#![cfg_attr(
feature = "unstable",
feature(
allocator_api,
try_trait_v2,
generator_trait,
never_type
)
feature(allocator_api, try_trait_v2, generator_trait, never_type)
)]
#![cfg_attr(all(feature = "std", feature = "unstable"), feature(ip))]
#![cfg_attr(
Expand Down
7 changes: 3 additions & 4 deletions proptest/src/test_runner/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ const VERBOSE: &str = "PROPTEST_VERBOSE";
#[cfg(feature = "std")]
const RNG_ALGORITHM: &str = "PROPTEST_RNG_ALGORITHM";
#[cfg(feature = "std")]
const DISABLE_FAILURE_PERSISTENCE: &str = "PROPTEST_DISABLE_FAILURE_PERSISTENCE";
const DISABLE_FAILURE_PERSISTENCE: &str =
"PROPTEST_DISABLE_FAILURE_PERSISTENCE";

#[cfg(feature = "std")]
fn contextualize_config(mut result: Config) -> Config {
Expand Down Expand Up @@ -127,9 +128,7 @@ fn contextualize_config(mut result: Config) -> Config {
"RngAlgorithm",
RNG_ALGORITHM,
),
DISABLE_FAILURE_PERSISTENCE => {
result.failure_persistence = None
}
DISABLE_FAILURE_PERSISTENCE => result.failure_persistence = None,

_ => {
if var.starts_with("PROPTEST_") {
Expand Down
24 changes: 24 additions & 0 deletions proptest/src/test_runner/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,33 @@ pub enum TestCaseError {
Fail(Reason),
}

/// Indicates the type of test that ran successfully.
///
/// This is used for managing whether or not a success is counted against
/// configured `PROPTEST_CASES`; only `NewCases` shall be counted.
///
/// TODO-v2: Ideally `TestCaseResult = Result<TestCaseOk, TestCaseError>`
/// however this breaks source compability in version 1.x.x because
/// `TestCaseResult` is public.
#[derive(Debug, Clone)]
pub(crate) enum TestCaseOk {
NewCaseSuccess,
PersistedCaseSuccess,
ReplayFromForkSuccess,
CacheHitSuccess,
Reject,
}

/// Convenience for the type returned by test cases.
pub type TestCaseResult = Result<(), TestCaseError>;

/// Intended to replace `TestCaseResult` in v2.
///
/// TODO-v2: Ideally `TestCaseResult = Result<TestCaseOk, TestCaseError>`
/// however this breaks source compability in version 1.x.x because
/// `TestCaseResult` is public.
pub(crate) type TestCaseResultV2 = Result<TestCaseOk, TestCaseError>;

impl TestCaseError {
/// Rejects the generated test input as invalid for this test case. This
/// does not count as a test failure (nor a success); rather, it simply
Expand Down
Loading

0 comments on commit a854d2e

Please sign in to comment.