Skip to content

Commit efb6b2e

Browse files
committed
Print message if no gas report to show
1 parent 1c0a00c commit efb6b2e

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

crates/forge-runner/src/gas/report.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ impl ReportData {
109109

110110
impl Display for ReportData {
111111
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
112+
if self.0.is_empty() {
113+
writeln!(
114+
f,
115+
"\nNo contract gas usage data to display. Make sure your test include transactions."
116+
)?;
117+
}
118+
112119
for (name, contract_info) in &self.0 {
113120
if !contract_info.functions.is_empty() {
114121
let table = format_table_output(contract_info, name);

crates/forge/tests/e2e/gas_report.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,30 @@ fn multiple_contracts_and_constructor() {
115115
"},
116116
);
117117
}
118+
119+
#[test]
120+
fn no_transactions() {
121+
let temp = setup_package("simple_package");
122+
let output = test_runner(&temp)
123+
.arg("--gas-report")
124+
.arg("test_fib")
125+
.assert()
126+
.code(0);
127+
128+
assert_stdout_contains(
129+
output,
130+
indoc! {r"
131+
[..]Compiling[..]
132+
[..]Finished[..]
133+
134+
135+
Collected 1 test(s) from simple_package package
136+
Running 1 test(s) from src/
137+
[PASS] simple_package::tests::test_fib (l1_gas: ~0, l1_data_gas: ~0, l2_gas: ~[..])
138+
No contract gas usage data to display. Make sure your test include transactions.
139+
140+
Running 0 test(s) from tests/
141+
Tests: 1 passed, 0 failed, 0 ignored, [..] filtered out
142+
"},
143+
);
144+
}

0 commit comments

Comments
 (0)