Skip to content

Commit

Permalink
✨ Hide fuzz tests unless flag
Browse files Browse the repository at this point in the history
  • Loading branch information
transmissions11 committed Mar 30, 2022
1 parent 55fc2a2 commit 482082f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions cli/src/cmd/forge/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::cmd::{
use ansi_term::Colour;
use clap::{Parser, ValueHint};
use eyre::Context;
use forge::TestKindGas;
use forge::{TestKind, TestKindGas};
use once_cell::sync::Lazy;
use regex::Regex;
use std::{
Expand All @@ -36,9 +36,11 @@ pub struct SnapshotArgs {
/// All test arguments are supported
#[clap(flatten)]
test: test::TestArgs,

/// Additional configs for test results
#[clap(flatten)]
config: SnapshotConfig,

#[clap(
help = "Compare against a snapshot and display changes from the snapshot. Takes an optional snapshot file, [default: .gas-snapshot]",
conflicts_with = "snap",
Expand All @@ -47,6 +49,7 @@ pub struct SnapshotArgs {
value_name = "SNAPSHOT_FILE",
)]
diff: Option<Option<PathBuf>>,

#[clap(
help = "Run snapshot in 'check' mode and compares against an existing snapshot file, [default: .gas-snapshot]. Exits with 0 if snapshots match. Exits with 1 and prints a diff otherwise",
conflicts_with = "diff",
Expand All @@ -55,15 +58,21 @@ pub struct SnapshotArgs {
value_name = "SNAPSHOT_FILE",
)]
check: Option<Option<PathBuf>>,

#[clap(help = "How to format the output.", long)]
format: Option<Format>,

#[clap(
help = "Output file for the snapshot.",
default_value = ".gas-snapshot",
long,
value_name = "SNAPSHOT_FILE"
)]
snap: PathBuf,

/// Include the mean and median gas use of fuzz tests in the snapshot.
#[clap(long, env = "FORGE_INCLUDE_FUZZ_TESTS")]
pub include_fuzz_tests: bool,
}

impl SnapshotArgs {
Expand Down Expand Up @@ -105,7 +114,7 @@ impl Cmd for SnapshotArgs {
std::process::exit(1)
}
} else {
write_to_snapshot_file(&tests, self.snap, self.format)?;
write_to_snapshot_file(&tests, self.snap, self.include_fuzz_tests, self.format)?;
}
Ok(())
}
Expand Down Expand Up @@ -240,10 +249,16 @@ fn read_snapshot(path: impl AsRef<Path>) -> eyre::Result<Vec<SnapshotEntry>> {
fn write_to_snapshot_file(
tests: &[Test],
path: impl AsRef<Path>,
include_fuzz_tests: bool,
_format: Option<Format>,
) -> eyre::Result<()> {
let mut out = String::new();
for test in tests {
// Ignore fuzz tests if we're not including fuzz tests in the snapshot.
if matches!(test.result.kind, TestKind::Fuzz(..)) && !include_fuzz_tests {
continue
}

writeln!(
out,
"{}:{} {}",
Expand Down
2 changes: 1 addition & 1 deletion cli/src/cmd/forge/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub struct TestArgs {
debug: Option<Regex>,

/// Print a gas report.
#[clap(long = "gas-report")]
#[clap(long, env = "FORGE_GAS_REPORT")]
gas_report: bool,

/// Force the process to exit with code 0, even if the tests fail.
Expand Down

0 comments on commit 482082f

Please sign in to comment.