File tree Expand file tree Collapse file tree 3 files changed +66
-6
lines changed Expand file tree Collapse file tree 3 files changed +66
-6
lines changed Original file line number Diff line number Diff line change @@ -116,10 +116,9 @@ impl<'a> CoverageReporter for LcovReporter<'a> {
116
116
if hits == 0 { "-" . to_string( ) } else { hits. to_string( ) }
117
117
) ?;
118
118
}
119
- // Statements are not in the LCOV format
120
- CoverageItemKind :: Statement => {
121
- writeln ! ( self . destination, "DA:{line},{hits}" ) ?;
122
- }
119
+ // Statements are not in the LCOV format.
120
+ // We don't add them in order to avoid doubling line hits.
121
+ _ => { }
123
122
}
124
123
}
125
124
Original file line number Diff line number Diff line change 1
- use foundry_test_utils:: str;
1
+ use foundry_test_utils:: { assert_data_eq , str} ;
2
2
3
3
forgetest ! ( basic_coverage, |_prj, cmd| {
4
4
cmd. args( [ "coverage" ] ) ;
@@ -210,3 +210,64 @@ contract AContractTest is DSTest {
210
210
211
211
"# ] ] ) ;
212
212
} ) ;
213
+
214
+ forgetest ! ( test_line_hit_not_doubled, |prj, cmd| {
215
+ prj. insert_ds_test( ) ;
216
+ prj. add_source(
217
+ "AContract.sol" ,
218
+ r#"
219
+ contract AContract {
220
+ int public i;
221
+
222
+ function foo() public {
223
+ i = 1;
224
+ }
225
+ }
226
+ "# ,
227
+ )
228
+ . unwrap( ) ;
229
+
230
+ prj. add_source(
231
+ "AContractTest.sol" ,
232
+ r#"
233
+ import "./test.sol";
234
+ import {AContract} from "./AContract.sol";
235
+
236
+ contract AContractTest is DSTest {
237
+ function testFoo() public {
238
+ AContract a = new AContract();
239
+ a.foo();
240
+ }
241
+ }
242
+ "# ,
243
+ )
244
+ . unwrap( ) ;
245
+
246
+ let lcov_info = prj. root( ) . join( "lcov.info" ) ;
247
+ cmd. arg( "coverage" ) . args( [
248
+ "--report" . to_string( ) ,
249
+ "lcov" . to_string( ) ,
250
+ "--report-file" . to_string( ) ,
251
+ lcov_info. to_str( ) . unwrap( ) . to_string( ) ,
252
+ ] ) ;
253
+ cmd. assert_success( ) ;
254
+ assert!( lcov_info. exists( ) ) ;
255
+
256
+ // We want to make sure DA:8,1 is added only once so line hit is not doubled.
257
+ assert_data_eq!(
258
+ std:: fs:: read_to_string( lcov_info) . unwrap( ) ,
259
+ str ![ [ r#"TN:
260
+ SF:src/AContract.sol
261
+ FN:7,AContract.foo
262
+ FNDA:1,AContract.foo
263
+ DA:8,1
264
+ FNF:1
265
+ FNH:1
266
+ LF:1
267
+ LH:1
268
+ BRF:0
269
+ BRH:0
270
+ end[..]
271
+ "# ] ]
272
+ ) ;
273
+ } ) ;
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ pub use script::{ScriptOutcome, ScriptTester};
28
28
// re-exports for convenience
29
29
pub use foundry_compilers;
30
30
31
- pub use snapbox:: { file, str} ;
31
+ pub use snapbox:: { assert_data_eq , file, str} ;
32
32
33
33
/// Initializes tracing for tests.
34
34
pub fn init_tracing ( ) {
You can’t perform that action at this time.
0 commit comments