@@ -2,8 +2,12 @@ use super::test;
2
2
use crate :: result:: { SuiteTestResult , TestKindReport , TestOutcome } ;
3
3
use alloy_primitives:: { U256 , map:: HashMap } ;
4
4
use clap:: { Parser , ValueHint , builder:: RangedU64ValueParser } ;
5
+ use comfy_table:: {
6
+ Cell , Color , Row , Table , modifiers:: UTF8_ROUND_CORNERS , presets:: ASCII_MARKDOWN ,
7
+ } ;
5
8
use eyre:: { Context , Result } ;
6
9
use foundry_cli:: utils:: STATIC_FUZZ_SEED ;
10
+ use foundry_common:: shell;
7
11
use regex:: Regex ;
8
12
use std:: {
9
13
cmp:: Ordering ,
@@ -111,13 +115,17 @@ impl GasSnapshotArgs {
111
115
std:: process:: exit ( 1 )
112
116
}
113
117
} else {
118
+ if matches ! ( self . format, Some ( Format :: Table ) ) {
119
+ let table = build_gas_snapshot_table ( & tests) ;
120
+ sh_println ! ( "\n {}" , table) ?;
121
+ }
114
122
write_to_gas_snapshot_file ( & tests, self . snap , self . format ) ?;
115
123
}
116
124
Ok ( ( ) )
117
125
}
118
126
}
119
127
120
- // TODO implement pretty tables
128
+ // Gas report format on stdout.
121
129
#[ derive( Clone , Debug ) ]
122
130
pub enum Format {
123
131
Table ,
@@ -290,6 +298,31 @@ fn write_to_gas_snapshot_file(
290
298
Ok ( fs:: write ( path, content) ?)
291
299
}
292
300
301
+ fn build_gas_snapshot_table ( tests : & [ SuiteTestResult ] ) -> Table {
302
+ let mut table = Table :: new ( ) ;
303
+ if shell:: is_markdown ( ) {
304
+ table. load_preset ( ASCII_MARKDOWN ) ;
305
+ } else {
306
+ table. apply_modifier ( UTF8_ROUND_CORNERS ) ;
307
+ }
308
+
309
+ table. set_header ( vec ! [
310
+ Cell :: new( "Contract" ) . fg( Color :: Cyan ) ,
311
+ Cell :: new( "Signature" ) . fg( Color :: Cyan ) ,
312
+ Cell :: new( "Report" ) . fg( Color :: Cyan ) ,
313
+ ] ) ;
314
+
315
+ for test in tests {
316
+ let mut row = Row :: new ( ) ;
317
+ row. add_cell ( Cell :: new ( test. contract_name ( ) ) ) ;
318
+ row. add_cell ( Cell :: new ( & test. signature ) ) ;
319
+ row. add_cell ( Cell :: new ( test. result . kind . report ( ) . to_string ( ) ) ) ;
320
+ table. add_row ( row) ;
321
+ }
322
+
323
+ table
324
+ }
325
+
293
326
/// A Gas snapshot entry diff.
294
327
#[ derive( Clone , Debug , PartialEq , Eq ) ]
295
328
pub struct GasSnapshotDiff {
0 commit comments