Accept an optional --seed parameter for check, otherwise default to random.

Also, show the seed on failure.
This commit is contained in:
KtorZ
2024-03-03 20:36:01 +01:00
parent a7b9d4bb22
commit 7a2537432a
14 changed files with 100 additions and 55 deletions

View File

@@ -38,3 +38,4 @@ clap_complete = "4.3.2"
inquire = "0.6.2"
num-bigint = "0.4.3"
ordinal = "0.3.2"
rand = "0.8.5"

View File

@@ -39,7 +39,7 @@ pub fn exec(
mainnet,
}: Args,
) -> miette::Result<()> {
with_project(directory.as_deref(), false, |p| {
with_project(directory.as_deref(), u32::default(), false, |p| {
if rebuild {
p.build(false, Tracing::silent())?;
}

View File

@@ -47,7 +47,7 @@ pub fn exec(
validator,
}: Args,
) -> miette::Result<()> {
with_project(None, false, |p| {
with_project(None, u32::default(), false, |p| {
let title = module.as_ref().map(|m| {
format!(
"{m}{}",

View File

@@ -29,7 +29,7 @@ pub fn exec(
rebuild,
}: Args,
) -> miette::Result<()> {
with_project(directory.as_deref(), false, |p| {
with_project(directory.as_deref(), u32::default(), false, |p| {
if rebuild {
p.build(false, Tracing::silent())?;
}

View File

@@ -29,7 +29,7 @@ pub fn exec(
rebuild,
}: Args,
) -> miette::Result<()> {
with_project(directory.as_deref(), false, |p| {
with_project(directory.as_deref(), u32::default(), false, |p| {
if rebuild {
p.build(false, Tracing::silent())?;
}

View File

@@ -1,7 +1,6 @@
use aiken_lang::ast::{TraceLevel, Tracing};
use aiken_project::watch::{self, watch_project, with_project};
use clap::builder::MapValueParser;
use clap::builder::{PossibleValuesParser, TypedValueParser};
use clap::builder::{MapValueParser, PossibleValuesParser, TypedValueParser};
use std::{path::PathBuf, process};
#[derive(clap::Args)]
@@ -52,17 +51,23 @@ pub fn exec(
}: Args,
) -> miette::Result<()> {
let result = if watch {
watch_project(directory.as_deref(), watch::default_filter, 500, |p| {
p.build(
uplc,
match filter_traces {
Some(filter_traces) => filter_traces(trace_level),
None => Tracing::All(trace_level),
},
)
})
watch_project(
directory.as_deref(),
watch::default_filter,
u32::default(),
500,
|p| {
p.build(
uplc,
match filter_traces {
Some(filter_traces) => filter_traces(trace_level),
None => Tracing::All(trace_level),
},
)
},
)
} else {
with_project(directory.as_deref(), deny, |p| {
with_project(directory.as_deref(), u32::default(), deny, |p| {
p.build(
uplc,
match filter_traces {
@@ -77,8 +82,8 @@ pub fn exec(
}
#[allow(clippy::type_complexity)]
pub fn filter_traces_parser(
) -> MapValueParser<PossibleValuesParser, fn(String) -> fn(TraceLevel) -> Tracing> {
pub fn filter_traces_parser()
-> MapValueParser<PossibleValuesParser, fn(String) -> fn(TraceLevel) -> Tracing> {
PossibleValuesParser::new(["user-defined", "compiler-generated", "all"]).map(
|s: String| match s.as_str() {
"user-defined" => Tracing::UserDefined,

View File

@@ -1,6 +1,7 @@
use super::build::{filter_traces_parser, trace_level_parser};
use aiken_lang::ast::{TraceLevel, Tracing};
use aiken_project::watch::{self, watch_project, with_project};
use rand::prelude::*;
use std::{path::PathBuf, process};
#[derive(clap::Args)]
@@ -25,6 +26,10 @@ pub struct Args {
#[clap(long)]
watch: bool,
/// An initial seed to initialize the pseudo-random generator for property-tests.
#[clap(long)]
seed: Option<u32>,
/// Only run tests if they match any of these strings.
/// You can match a module with `-m aiken/list` or `-m list`.
/// You can match a test with `-m "aiken/list.{map}"` or `-m "aiken/option.{flatten_1}"`
@@ -66,28 +71,41 @@ pub fn exec(
watch,
filter_traces,
trace_level,
seed,
}: Args,
) -> miette::Result<()> {
let mut rng = rand::thread_rng();
let seed = seed.unwrap_or_else(|| rng.gen());
let result = if watch {
watch_project(directory.as_deref(), watch::default_filter, 500, |p| {
p.check(
skip_tests,
match_tests.clone(),
debug,
exact_match,
match filter_traces {
Some(filter_traces) => filter_traces(trace_level),
None => Tracing::All(trace_level),
},
)
})
watch_project(
directory.as_deref(),
watch::default_filter,
seed,
500,
|p| {
p.check(
skip_tests,
match_tests.clone(),
debug,
exact_match,
seed,
match filter_traces {
Some(filter_traces) => filter_traces(trace_level),
None => Tracing::All(trace_level),
},
)
},
)
} else {
with_project(directory.as_deref(), deny, |p| {
with_project(directory.as_deref(), seed, deny, |p| {
p.check(
skip_tests,
match_tests.clone(),
debug,
exact_match,
seed,
match filter_traces {
Some(filter_traces) => filter_traces(trace_level),
None => Tracing::All(trace_level),

View File

@@ -29,11 +29,17 @@ pub fn exec(
}: Args,
) -> miette::Result<()> {
let result = if watch {
watch_project(directory.as_deref(), watch::default_filter, 500, |p| {
watch_project(
directory.as_deref(),
watch::default_filter,
u32::default(),
500,
|p| p.docs(destination.clone()),
)
} else {
with_project(directory.as_deref(), u32::default(), deny, |p| {
p.docs(destination.clone())
})
} else {
with_project(directory.as_deref(), deny, |p| p.docs(destination.clone()))
};
result.map_err(|_| process::exit(1))