@@ -2203,3 +2203,66 @@ contract CounterTest is DSTest {
22032203...
22042204"# ] ] ) ;
22052205} ) ;
2206+
2207+ // Test that coverage files are written even when tests fail.
2208+ forgetest ! ( coverage_with_failing_tests, |prj, cmd| {
2209+ prj. insert_ds_test( ) ;
2210+ prj. add_source(
2211+ "Counter.sol" ,
2212+ r#"
2213+ contract Counter {
2214+ uint256 public number;
2215+
2216+ function setNumber(uint256 newNumber) public {
2217+ number = newNumber;
2218+ }
2219+
2220+ function increment() public {
2221+ number++;
2222+ }
2223+ }
2224+ "# ,
2225+ ) ;
2226+
2227+ prj. add_source(
2228+ "CounterTest.sol" ,
2229+ r#"
2230+ import "./test.sol";
2231+ import {Counter} from "./Counter.sol";
2232+
2233+ contract CounterTest is DSTest {
2234+ Counter public counter;
2235+
2236+ function setUp() public {
2237+ counter = new Counter();
2238+ counter.setNumber(0);
2239+ }
2240+
2241+ function test_Increment() public {
2242+ counter.increment();
2243+ assertEq(counter.number(), 1);
2244+ }
2245+
2246+ function test_FailingTest() public {
2247+ counter.increment();
2248+ // This assertion will fail
2249+ assertEq(counter.number(), 999);
2250+ }
2251+ }
2252+ "# ,
2253+ ) ;
2254+
2255+ // Run coverage - this should exit with error code 1 due to failing test,
2256+ // but the lcov file should still be written.
2257+ cmd. arg( "coverage" ) . args( [ "--report=lcov" ] ) . assert_failure( ) ;
2258+
2259+ // Verify that the lcov.info file was created despite test failure
2260+ let lcov = prj. root( ) . join( "lcov.info" ) ;
2261+ assert!( lcov. exists( ) , "lcov.info should be created even when tests fail" ) ;
2262+
2263+ // Verify the coverage data is valid and includes the counter contract
2264+ let lcov_content = std:: fs:: read_to_string( & lcov) . unwrap( ) ;
2265+ assert!( lcov_content. contains( "SF:src/Counter.sol" ) , "Coverage should include Counter.sol" ) ;
2266+ assert!( lcov_content. contains( "FN:" ) , "Coverage should include function data" ) ;
2267+ assert!( lcov_content. contains( "DA:" ) , "Coverage should include line hit data" ) ;
2268+ } ) ;
0 commit comments