Skip to content

Commit d6af051

Browse files
committed
revert test modifications from #9244 for TestArgs, simply pass + flatten ShellOpts in args
1 parent 7f78bce commit d6af051

File tree

3 files changed

+19
-39
lines changed

3 files changed

+19
-39
lines changed

crates/cli/src/opts/shell.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use foundry_common::shell::{ColorChoice, OutputFormat, OutputMode, Shell, Verbos
44
// note: `verbose` and `quiet` cannot have `short` because of conflicts with multiple commands.
55

66
/// Global shell options.
7-
#[derive(Clone, Copy, Debug, Parser)]
7+
#[derive(Clone, Copy, Debug, Default, Parser)]
88
pub struct ShellOpts {
99
/// Verbosity level of the log messages.
1010
///

crates/forge/bin/cmd/test/mod.rs

+11-37
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use forge::{
1717
MultiContractRunner, MultiContractRunnerBuilder, TestFilter, TestOptions, TestOptionsBuilder,
1818
};
1919
use foundry_cli::{
20-
opts::CoreBuildArgs,
20+
opts::{CoreBuildArgs, ShellOpts},
2121
utils::{self, LoadConfig},
2222
};
2323
use foundry_common::{compile::ProjectCompiler, evm::EvmArgs, fs, shell};
@@ -178,6 +178,9 @@ pub struct TestArgs {
178178
/// Print detailed test summary table.
179179
#[arg(long, help_heading = "Display options", requires = "summary")]
180180
pub detailed: bool,
181+
182+
#[command(flatten)]
183+
shell: ShellOpts,
181184
}
182185

183186
impl TestArgs {
@@ -991,56 +994,34 @@ fn junit_xml_report(results: &BTreeMap<String, SuiteResult>, verbosity: u8) -> R
991994

992995
#[cfg(test)]
993996
mod tests {
994-
use crate::opts::{Forge, ForgeSubcommand};
995-
996997
use super::*;
997998
use foundry_config::{Chain, InvariantConfig};
998999
use foundry_test_utils::forgetest_async;
9991000

10001001
#[test]
10011002
fn watch_parse() {
1002-
let args = match Forge::parse_from(["foundry-cli", "test", "-vw"]).cmd {
1003-
ForgeSubcommand::Test(args) => args,
1004-
_ => unreachable!(),
1005-
};
1003+
let args: TestArgs = TestArgs::parse_from(["foundry-cli", "-vw"]);
10061004
assert!(args.watch.watch.is_some());
10071005
}
10081006

10091007
#[test]
10101008
fn fuzz_seed() {
1011-
let args = match Forge::parse_from(["foundry-cli", "test", "--fuzz-seed", "0x10"]).cmd {
1012-
ForgeSubcommand::Test(args) => args,
1013-
_ => unreachable!(),
1014-
};
1009+
let args: TestArgs = TestArgs::parse_from(["foundry-cli", "--fuzz-seed", "0x10"]);
10151010
assert!(args.fuzz_seed.is_some());
10161011
}
10171012

10181013
// <https://github.com/foundry-rs/foundry/issues/5913>
10191014
#[test]
10201015
fn fuzz_seed_exists() {
1021-
let args = match Forge::parse_from([
1022-
"foundry-cli",
1023-
"test",
1024-
"-vvv",
1025-
"--gas-report",
1026-
"--fuzz-seed",
1027-
"0x10",
1028-
])
1029-
.cmd
1030-
{
1031-
ForgeSubcommand::Test(args) => args,
1032-
_ => unreachable!(),
1033-
};
1016+
let args: TestArgs =
1017+
TestArgs::parse_from(["foundry-cli", "-vvv", "--gas-report", "--fuzz-seed", "0x10"]);
10341018
assert!(args.fuzz_seed.is_some());
10351019
}
10361020

10371021
#[test]
10381022
fn extract_chain() {
10391023
let test = |arg: &str, expected: Chain| {
1040-
let args = match Forge::parse_from(["foundry-cli", "test", arg]).cmd {
1041-
ForgeSubcommand::Test(args) => args,
1042-
_ => unreachable!(),
1043-
};
1024+
let args = TestArgs::parse_from(["foundry-cli", arg]);
10441025
assert_eq!(args.evm_opts.env.chain, Some(expected));
10451026
let (config, evm_opts) = args.load_config_and_evm_opts().unwrap();
10461027
assert_eq!(config.chain, Some(expected));
@@ -1094,19 +1075,12 @@ contract FooBarTest is DSTest {
10941075
)
10951076
.unwrap();
10961077

1097-
let args = match Forge::parse_from([
1078+
let args = TestArgs::parse_from([
10981079
"foundry-cli",
1099-
"test",
11001080
"--gas-report",
11011081
"--root",
11021082
&prj.root().to_string_lossy(),
1103-
])
1104-
.cmd
1105-
{
1106-
ForgeSubcommand::Test(args) => args,
1107-
_ => unreachable!(),
1108-
};
1109-
1083+
]);
11101084
let outcome = args.run().await.unwrap();
11111085
let gas_report = outcome.gas_report.unwrap();
11121086

crates/script/src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ use dialoguer::Confirm;
2626
use eyre::{ContextCompat, Result};
2727
use forge_script_sequence::{AdditionalContract, NestedValue};
2828
use forge_verify::RetryArgs;
29-
use foundry_cli::{opts::CoreBuildArgs, utils::LoadConfig};
29+
use foundry_cli::{
30+
opts::{CoreBuildArgs, ShellOpts},
31+
utils::LoadConfig,
32+
};
3033
use foundry_common::{
3134
abi::{encode_function_args, get_func},
3235
evm::{Breakpoints, EvmArgs},
@@ -210,6 +213,9 @@ pub struct ScriptArgs {
210213

211214
#[command(flatten)]
212215
pub retry: RetryArgs,
216+
217+
#[clap(flatten)]
218+
pub shell: ShellOpts,
213219
}
214220

215221
impl ScriptArgs {

0 commit comments

Comments
 (0)