Skip to content

Commit 190c9af

Browse files
authored
Add --skip flag to exclude tests (#3432)
<!-- Reference any GitHub issues resolved by this PR --> Closes #1512 ## Introduced changes <!-- A brief description of the changes --> - ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md`
1 parent 0337ce4 commit 190c9af

37 files changed

+406
-153
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Forge
1111

12-
#### Changed
12+
#### Added
13+
- `--skip` flag to allow excluding any test whose name contains the provided string
1314

15+
#### Changed
16+
- Updated output format for `--exit-first` flag. Tests skipped due to preceding failures are no longer displayed in the summary. Alternative information is shown when applicable.
1417
- `storage address` was renamed to `contract address` in the output of `--trace-verbosity`
1518

1619
#### Fixed

crates/forge-runner/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ fn run_with_fuzzing(
158158
) -> JoinHandle<Result<TestCaseSummary<Fuzzing>>> {
159159
tokio::task::spawn(async move {
160160
if send.is_closed() {
161-
return Ok(TestCaseSummary::Skipped {});
161+
return Ok(TestCaseSummary::Interrupted {});
162162
}
163163

164164
let (fuzzing_send, mut fuzzing_rec) = channel(1);
@@ -224,7 +224,7 @@ fn run_with_fuzzing(
224224
// get Passed after Skipped. To treat fuzzing a test as Passed
225225
// we have to ensure that all fuzzing subtests Passed
226226
if runs != fuzzer_runs.get() {
227-
return Ok(TestCaseSummary::Skipped {});
227+
return Ok(TestCaseSummary::Interrupted {});
228228
}
229229
}
230230

crates/forge-runner/src/messages.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum TestResultStatus {
1414
Passed,
1515
Failed,
1616
Ignored,
17-
Skipped,
17+
Interrupted,
1818
}
1919

2020
impl From<&AnyTestCaseSummary> for TestResultStatus {
@@ -26,8 +26,8 @@ impl From<&AnyTestCaseSummary> for TestResultStatus {
2626
| AnyTestCaseSummary::Fuzzing(TestCaseSummary::Failed { .. }) => Self::Failed,
2727
AnyTestCaseSummary::Single(TestCaseSummary::Ignored { .. })
2828
| AnyTestCaseSummary::Fuzzing(TestCaseSummary::Ignored { .. }) => Self::Ignored,
29-
AnyTestCaseSummary::Single(TestCaseSummary::Skipped { .. })
30-
| AnyTestCaseSummary::Fuzzing(TestCaseSummary::Skipped { .. }) => Self::Skipped,
29+
AnyTestCaseSummary::Single(TestCaseSummary::Interrupted { .. })
30+
| AnyTestCaseSummary::Fuzzing(TestCaseSummary::Interrupted { .. }) => Self::Interrupted,
3131
}
3232
}
3333
}
@@ -120,7 +120,7 @@ impl TestResultMessage {
120120
match self.status {
121121
TestResultStatus::Passed => return format!("\n\n{msg}"),
122122
TestResultStatus::Failed => return format!("\n\nFailure data:{msg}"),
123-
TestResultStatus::Ignored | TestResultStatus::Skipped => return String::new(),
123+
TestResultStatus::Ignored | TestResultStatus::Interrupted => return String::new(),
124124
}
125125
}
126126
String::new()
@@ -131,8 +131,8 @@ impl TestResultMessage {
131131
TestResultStatus::Passed => format!("[{}]", style("PASS").green()),
132132
TestResultStatus::Failed => format!("[{}]", style("FAIL").red()),
133133
TestResultStatus::Ignored => format!("[{}]", style("IGNORE").yellow()),
134-
TestResultStatus::Skipped => {
135-
unreachable!("Skipped tests should not have visible message representation")
134+
TestResultStatus::Interrupted => {
135+
unreachable!("Interrupted tests should not have visible message representation")
136136
}
137137
}
138138
}

crates/forge-runner/src/running.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn run_test(
7373
// a channel is used to receive information indicating
7474
// that the execution of the task is no longer necessary.
7575
if send.is_closed() {
76-
return TestCaseSummary::Skipped {};
76+
return TestCaseSummary::Interrupted {};
7777
}
7878
let run_result = run_test_case(
7979
&case,
@@ -83,7 +83,7 @@ pub fn run_test(
8383
);
8484

8585
if send.is_closed() {
86-
return TestCaseSummary::Skipped {};
86+
return TestCaseSummary::Interrupted {};
8787
}
8888

8989
extract_test_case_summary(
@@ -114,7 +114,7 @@ pub(crate) fn run_fuzz_test(
114114
// a channel is used to receive information indicating
115115
// that the execution of the task is no longer necessary.
116116
if send.is_closed() | fuzzing_send.is_closed() {
117-
return TestCaseSummary::Skipped {};
117+
return TestCaseSummary::Interrupted {};
118118
}
119119

120120
let run_result = run_test_case(
@@ -128,7 +128,7 @@ pub(crate) fn run_fuzz_test(
128128
// remove it after improve exit-first tests
129129
// issue #1043
130130
if send.is_closed() {
131-
return TestCaseSummary::Skipped {};
131+
return TestCaseSummary::Interrupted {};
132132
}
133133

134134
extract_test_case_summary(

crates/forge-runner/src/test_case_summary.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub enum TestCaseSummary<T: TestType> {
165165
name: String,
166166
},
167167
/// Test case skipped due to exit first or execution interrupted, test result is ignored.
168-
Skipped {},
168+
Interrupted {},
169169
}
170170

171171
#[derive(Debug)]
@@ -181,7 +181,7 @@ impl<T: TestType> TestCaseSummary<T> {
181181
TestCaseSummary::Failed { name, .. }
182182
| TestCaseSummary::Passed { name, .. }
183183
| TestCaseSummary::Ignored { name, .. } => Some(name),
184-
TestCaseSummary::Skipped { .. } => None,
184+
TestCaseSummary::Interrupted { .. } => None,
185185
}
186186
}
187187

@@ -262,7 +262,7 @@ impl TestCaseSummary<Fuzzing> {
262262
debugging_trace,
263263
},
264264
TestCaseSummary::Ignored { name } => TestCaseSummary::Ignored { name: name.clone() },
265-
TestCaseSummary::Skipped {} => TestCaseSummary::Skipped {},
265+
TestCaseSummary::Interrupted {} => TestCaseSummary::Interrupted {},
266266
}
267267
}
268268
}
@@ -472,11 +472,11 @@ impl AnyTestCaseSummary {
472472
}
473473

474474
#[must_use]
475-
pub fn is_skipped(&self) -> bool {
475+
pub fn is_interrupted(&self) -> bool {
476476
matches!(
477477
self,
478-
AnyTestCaseSummary::Single(TestCaseSummary::Skipped { .. })
479-
| AnyTestCaseSummary::Fuzzing(TestCaseSummary::Skipped { .. })
478+
AnyTestCaseSummary::Single(TestCaseSummary::Interrupted { .. })
479+
| AnyTestCaseSummary::Fuzzing(TestCaseSummary::Interrupted { .. })
480480
)
481481
}
482482

crates/forge-runner/src/test_target_summary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ impl TestTargetSummary {
2525
}
2626

2727
#[must_use]
28-
pub fn count_skipped(&self) -> usize {
28+
pub fn count_interrupted(&self) -> usize {
2929
self.test_case_summaries
3030
.iter()
31-
.filter(|tu| tu.is_skipped())
31+
.filter(|tu| tu.is_interrupted())
3232
.count()
3333
}
3434

crates/forge/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ pub struct TestArgs {
152152
#[arg(short, long)]
153153
exact: bool,
154154

155+
/// Skips any tests whose name contains the given SKIP string.
156+
#[arg(long)]
157+
skip: Vec<String>,
158+
155159
/// Stop executing tests after the first failed test
156160
#[arg(short = 'x', long)]
157161
exit_first: bool,

crates/forge/src/run_tests/package.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ impl RunForPackageArgs {
8787
let test_filter = TestsFilter::from_flags(
8888
args.test_filter.clone(),
8989
args.exact,
90+
args.skip.clone(),
9091
args.only_ignored,
9192
args.include_ignored,
9293
args.rerun_failed,

crates/forge/src/run_tests/structs.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl Message for CollectedTestsCountMessage {
6666
pub struct TestsSummaryMessage {
6767
passed: usize,
6868
failed: usize,
69-
skipped: usize,
69+
interrupted: usize,
7070
ignored: usize,
7171
filtered: Option<usize>,
7272
}
@@ -75,13 +75,16 @@ impl TestsSummaryMessage {
7575
pub fn new(summaries: &[TestTargetSummary], filtered: Option<usize>) -> Self {
7676
let passed = summaries.iter().map(TestTargetSummary::count_passed).sum();
7777
let failed = summaries.iter().map(TestTargetSummary::count_failed).sum();
78-
let skipped = summaries.iter().map(TestTargetSummary::count_skipped).sum();
78+
let interrupted = summaries
79+
.iter()
80+
.map(TestTargetSummary::count_interrupted)
81+
.sum();
7982
let ignored = summaries.iter().map(TestTargetSummary::count_ignored).sum();
8083

8184
Self {
8285
passed,
8386
failed,
84-
skipped,
87+
interrupted,
8588
ignored,
8689
filtered,
8790
}
@@ -94,13 +97,19 @@ impl Message for TestsSummaryMessage {
9497
.filtered
9598
.map_or_else(|| "other".to_string(), |v| v.to_string());
9699

100+
let interrupted = if self.interrupted > 0 {
101+
format!("\nInterrupted execution of {} test(s).", self.interrupted)
102+
} else {
103+
String::new()
104+
};
105+
97106
format!(
98-
"{}: {} passed, {} failed, {} skipped, {} ignored, {filtered} filtered out",
107+
"{}: {} passed, {} failed, {} ignored, {filtered} filtered out{}",
99108
style("Tests").bold(),
100109
self.passed,
101110
self.failed,
102-
self.skipped,
103-
self.ignored
111+
self.ignored,
112+
interrupted
104113
)
105114
}
106115

crates/forge/src/run_tests/test_target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub async fn run_for_test_target(
7171
while let Some(task) = tasks.next().await {
7272
let result = task??;
7373

74-
if !result.is_skipped() {
74+
if !result.is_interrupted() {
7575
let test_result_message = TestResultMessage::new(
7676
&result,
7777
forge_config.output_config.detailed_resources,

0 commit comments

Comments
 (0)