Accept an optional --seed parameter for check, otherwise default to random.
Also, show the seed on failure.
This commit is contained in:
@@ -226,6 +226,7 @@ where
|
||||
match_tests: Option<Vec<String>>,
|
||||
verbose: bool,
|
||||
exact_match: bool,
|
||||
seed: u32,
|
||||
tracing: Tracing,
|
||||
) -> Result<(), Vec<Error>> {
|
||||
let options = Options {
|
||||
@@ -237,6 +238,7 @@ where
|
||||
match_tests,
|
||||
verbose,
|
||||
exact_match,
|
||||
seed,
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -322,6 +324,7 @@ where
|
||||
match_tests,
|
||||
verbose,
|
||||
exact_match,
|
||||
seed,
|
||||
} => {
|
||||
let tests =
|
||||
self.collect_tests(verbose, match_tests, exact_match, options.tracing)?;
|
||||
@@ -330,7 +333,7 @@ where
|
||||
self.event_listener.handle_event(Event::RunningTests);
|
||||
}
|
||||
|
||||
let tests = self.run_tests(tests);
|
||||
let tests = self.run_tests(tests, seed);
|
||||
|
||||
let errors: Vec<Error> = tests
|
||||
.iter()
|
||||
@@ -786,7 +789,7 @@ where
|
||||
Ok(tests)
|
||||
}
|
||||
|
||||
fn run_tests(&self, tests: Vec<Test>) -> Vec<TestResult<UntypedExpr>> {
|
||||
fn run_tests(&self, tests: Vec<Test>, seed: u32) -> Vec<TestResult<UntypedExpr>> {
|
||||
use rayon::prelude::*;
|
||||
|
||||
let data_types = utils::indexmap::as_ref_values(&self.data_types);
|
||||
@@ -797,7 +800,7 @@ where
|
||||
Test::UnitTest(unit_test) => unit_test.run(),
|
||||
// TODO: Get the seed from the command-line, defaulting to a random one when not
|
||||
// provided.
|
||||
Test::PropertyTest(property_test) => property_test.run(42),
|
||||
Test::PropertyTest(property_test) => property_test.run(seed),
|
||||
})
|
||||
.collect::<Vec<TestResult<PlutusData>>>()
|
||||
.into_iter()
|
||||
|
||||
@@ -10,6 +10,7 @@ pub enum CodeGenMode {
|
||||
match_tests: Option<Vec<String>>,
|
||||
verbose: bool,
|
||||
exact_match: bool,
|
||||
seed: u32,
|
||||
},
|
||||
Build(bool),
|
||||
NoOp,
|
||||
|
||||
@@ -267,8 +267,6 @@ impl PropertyTest {
|
||||
} = next_prng
|
||||
{
|
||||
if result.failed(self.can_error) {
|
||||
println!("{:#?}", result.result());
|
||||
|
||||
let mut counterexample = Counterexample {
|
||||
value,
|
||||
choices: next_prng.choices(),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{telemetry::Terminal, Project};
|
||||
use crate::{telemetry::Terminal, Error, Project};
|
||||
use miette::{Diagnostic, IntoDiagnostic};
|
||||
use notify::{Event, RecursiveMode, Watcher};
|
||||
use owo_colors::{OwoColorize, Stream::Stderr};
|
||||
@@ -75,7 +75,12 @@ pub fn default_filter(evt: &Event) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_project<A>(directory: Option<&Path>, deny: bool, mut action: A) -> miette::Result<()>
|
||||
pub fn with_project<A>(
|
||||
directory: Option<&Path>,
|
||||
seed: u32,
|
||||
deny: bool,
|
||||
mut action: A,
|
||||
) -> miette::Result<()>
|
||||
where
|
||||
A: FnMut(&mut Project<Terminal>) -> Result<(), Vec<crate::error::Error>>,
|
||||
{
|
||||
@@ -116,17 +121,24 @@ where
|
||||
}
|
||||
);
|
||||
|
||||
if errs.iter().any(|e| matches!(e, Error::TestFailure { .. })) {
|
||||
eprintln!(
|
||||
" ━━━━━━\n ╰─▶ use {} {} to replay",
|
||||
"--seed".if_supports_color(Stderr, |s| s.bold()),
|
||||
format!("{seed}").if_supports_color(Stderr, |s| s.bold())
|
||||
);
|
||||
}
|
||||
return Err(ExitFailure::into_report());
|
||||
} else {
|
||||
eprintln!(
|
||||
"{}",
|
||||
Summary {
|
||||
error_count: 0,
|
||||
warning_count
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
eprintln!(
|
||||
"{}",
|
||||
Summary {
|
||||
error_count: 0,
|
||||
warning_count
|
||||
}
|
||||
);
|
||||
|
||||
if warning_count > 0 && deny {
|
||||
Err(ExitFailure::into_report())
|
||||
} else {
|
||||
@@ -148,6 +160,7 @@ where
|
||||
pub fn watch_project<F, A>(
|
||||
directory: Option<&Path>,
|
||||
filter: F,
|
||||
seed: u32,
|
||||
debounce: u32,
|
||||
mut action: A,
|
||||
) -> miette::Result<()>
|
||||
@@ -219,7 +232,7 @@ where
|
||||
.if_supports_color(Stderr, |s| s.bold())
|
||||
.if_supports_color(Stderr, |s| s.purple()),
|
||||
);
|
||||
with_project(directory, false, &mut action).unwrap_or(())
|
||||
with_project(directory, seed, false, &mut action).unwrap_or(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user