Skip to content

Commit ad09bbe

Browse files
chore(forge): rm regex for --debug and --decode-internal (#9572)
* chore(`forge`): rm regex for --debug and --decode-internal * fix * fix tests --------- Co-authored-by: grandizzy <[email protected]>
1 parent 95442fa commit ad09bbe

File tree

2 files changed

+16
-47
lines changed

2 files changed

+16
-47
lines changed

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

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ pub struct TestArgs {
7979
///
8080
/// If the matching test is a fuzz test, then it will open the debugger on the first failure
8181
/// case. If the fuzz test does not fail, it will open the debugger on the last fuzz case.
82-
#[arg(long, conflicts_with_all = ["flamegraph", "flamechart", "decode_internal", "rerun"], value_name = "DEPRECATED_TEST_FUNCTION_REGEX")]
83-
debug: Option<Option<Regex>>,
82+
#[arg(long, conflicts_with_all = ["flamegraph", "flamechart", "decode_internal", "rerun"])]
83+
debug: bool,
8484

8585
/// Generate a flamegraph for a single test. Implies `--decode-internal`.
8686
///
@@ -102,8 +102,8 @@ pub struct TestArgs {
102102
///
103103
/// Parameters stored in memory (such as bytes or arrays) are currently decoded only when a
104104
/// single function is matched, similarly to `--debug`, for performance reasons.
105-
#[arg(long, value_name = "DEPRECATED_TEST_FUNCTION_REGEX")]
106-
decode_internal: Option<Option<Regex>>,
105+
#[arg(long)]
106+
decode_internal: bool,
107107

108108
/// Dumps all debugger steps to file.
109109
#[arg(
@@ -288,7 +288,7 @@ impl TestArgs {
288288
// Set up the project.
289289
let project = config.project()?;
290290

291-
let mut filter = self.filter(&config);
291+
let filter = self.filter(&config);
292292
trace!(target: "forge::test", ?filter, "using filter");
293293

294294
let sources_to_compile = self.get_sources_to_compile(&config, &filter)?;
@@ -312,7 +312,7 @@ impl TestArgs {
312312
}
313313
}
314314

315-
let should_debug = self.debug.is_some();
315+
let should_debug = self.debug;
316316
let should_draw = self.flamegraph || self.flamechart;
317317

318318
// Determine print verbosity and executor verbosity.
@@ -324,12 +324,12 @@ impl TestArgs {
324324
let env = evm_opts.evm_env().await?;
325325

326326
// Enable internal tracing for more informative flamegraph.
327-
if should_draw && self.decode_internal.is_none() {
328-
self.decode_internal = Some(None);
327+
if should_draw && !self.decode_internal {
328+
self.decode_internal = true;
329329
}
330330

331331
// Choose the internal function tracing mode, if --decode-internal is provided.
332-
let decode_internal = if self.decode_internal.is_some() {
332+
let decode_internal = if self.decode_internal {
333333
// If more than one function matched, we enable simple tracing.
334334
// If only one function matched, we enable full tracing. This is done in `run_tests`.
335335
InternalTraceMode::Simple
@@ -350,28 +350,6 @@ impl TestArgs {
350350
.odyssey(evm_opts.odyssey)
351351
.build::<MultiCompiler>(project_root, &output, env, evm_opts)?;
352352

353-
let mut maybe_override_mt = |flag, maybe_regex: Option<&Option<Regex>>| {
354-
if let Some(Some(regex)) = maybe_regex {
355-
sh_warn!(
356-
"specifying argument for --{flag} is deprecated and will be removed in the future, \
357-
use --match-test instead"
358-
)?;
359-
360-
let test_pattern = &mut filter.args_mut().test_pattern;
361-
if test_pattern.is_some() {
362-
eyre::bail!(
363-
"Cannot specify both --{flag} and --match-test. \
364-
Use --match-contract and --match-path to further limit the search instead."
365-
);
366-
}
367-
*test_pattern = Some(regex.clone());
368-
}
369-
370-
Ok(())
371-
};
372-
maybe_override_mt("debug", self.debug.as_ref())?;
373-
maybe_override_mt("decode-internal", self.decode_internal.as_ref())?;
374-
375353
let libraries = runner.libraries.clone();
376354
let mut outcome = self.run_tests(runner, config, verbosity, &filter, &output).await?;
377355

@@ -466,7 +444,7 @@ impl TestArgs {
466444
let silent = self.gas_report && shell::is_json() || self.summary && shell::is_json();
467445

468446
let num_filtered = runner.matching_test_functions(filter).count();
469-
if num_filtered != 1 && (self.debug.is_some() || self.flamegraph || self.flamechart) {
447+
if num_filtered != 1 && (self.debug || self.flamegraph || self.flamechart) {
470448
let action = if self.flamegraph {
471449
"generate a flamegraph"
472450
} else if self.flamechart {
@@ -486,7 +464,7 @@ impl TestArgs {
486464
}
487465

488466
// If exactly one test matched, we enable full tracing.
489-
if num_filtered == 1 && self.decode_internal.is_some() {
467+
if num_filtered == 1 && self.decode_internal {
490468
runner.decode_internal = InternalTraceMode::Full;
491469
}
492470

@@ -549,7 +527,7 @@ impl TestArgs {
549527
)?);
550528
}
551529

552-
if self.decode_internal.is_some() {
530+
if self.decode_internal {
553531
let sources =
554532
ContractSources::from_project_output(output, &config.root, Some(&libraries))?;
555533
builder = builder.with_debug_identifier(DebugTraceIdentifier::new(sources));
@@ -578,7 +556,7 @@ impl TestArgs {
578556
// We identify addresses if we're going to print *any* trace or gas report.
579557
let identify_addresses = verbosity >= 3 ||
580558
self.gas_report ||
581-
self.debug.is_some() ||
559+
self.debug ||
582560
self.flamegraph ||
583561
self.flamechart;
584562

crates/forge/tests/cli/test_cmd.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,8 +1322,7 @@ contract SimpleContractTest is Test {
13221322
"#,
13231323
)
13241324
.unwrap();
1325-
cmd.args(["test", "-vvvv", "--decode-internal", "test"]).assert_success().stdout_eq(str![[
1326-
r#"
1325+
cmd.args(["test", "-vvvv", "--decode-internal"]).assert_success().stdout_eq(str![[r#"
13271326
...
13281327
Traces:
13291328
[406629] SimpleContractTest::test()
@@ -1335,8 +1334,7 @@ Traces:
13351334
│ └─ ← [Stop]
13361335
└─ ← [Stop]
13371336
...
1338-
"#
1339-
]]);
1337+
"#]]);
13401338
});
13411339

13421340
// tests that `forge test` with a seed produces deterministic random values for uint and addresses.
@@ -2277,13 +2275,6 @@ Use --match-contract and --match-path to further limit the search.
22772275
"#]]);
22782276
});
22792277

2280-
forgetest_init!(deprecated_regex_arg, |prj, cmd| {
2281-
cmd.args(["test", "--decode-internal", "test_Increment"]).assert_success().stderr_eq(str![[r#"
2282-
Warning: specifying argument for --decode-internal is deprecated and will be removed in the future, use --match-test instead
2283-
2284-
"#]]);
2285-
});
2286-
22872278
// Test a script that calls vm.rememberKeys
22882279
forgetest_init!(script_testing, |prj, cmd| {
22892280
prj
@@ -2452,7 +2443,7 @@ contract Dummy {
24522443

24532444
let dump_path = prj.root().join("dump.json");
24542445

2455-
cmd.args(["test", "--debug", "testDummy", "--dump", dump_path.to_str().unwrap()]);
2446+
cmd.args(["test", "--mt", "testDummy", "--debug", "--dump", dump_path.to_str().unwrap()]);
24562447
cmd.assert_success();
24572448

24582449
assert!(dump_path.exists());

0 commit comments

Comments
 (0)