Skip to content

Commit a446ab3

Browse files
authored
test(config): add test for test_failures_file path normalization (#12235)
1 parent 9c0737c commit a446ab3

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

crates/forge/tests/cli/config.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,3 +2031,46 @@ Warning (2018): Function state mutability can be restricted to pure
20312031
"#,
20322032
);
20332033
});
2034+
2035+
forgetest_init!(test_failures_file_normalization, |prj, cmd| {
2036+
// Update config with custom path containing "./" prefix
2037+
prj.update_config(|config| {
2038+
config.test_failures_file = PathBuf::from("./my-custom-failures");
2039+
});
2040+
2041+
prj.wipe_contracts();
2042+
prj.add_test(
2043+
"MixedTests.t.sol",
2044+
r#"
2045+
import {Test} from "forge-std/Test.sol";
2046+
2047+
contract MixedTests is Test {
2048+
function testPass() public pure {
2049+
require(1 == 1);
2050+
}
2051+
2052+
function testFail() public pure {
2053+
require(1 == 2, "testFail failed");
2054+
}
2055+
}
2056+
"#,
2057+
);
2058+
2059+
// Run test and verify test_failures_file is created at the correct location
2060+
cmd.args(["test"]).assert_failure();
2061+
let failures_file = prj.root().join("my-custom-failures");
2062+
assert!(failures_file.exists());
2063+
assert!(fs::read_to_string(&failures_file).unwrap().contains("testFail"));
2064+
2065+
// Verify --rerun works from subdirectory
2066+
let rerun_output = cmd
2067+
.forge_fuse()
2068+
.current_dir(prj.root().join("src"))
2069+
.args(["test", "--rerun"])
2070+
.assert_failure()
2071+
.get_output()
2072+
.stdout_lossy();
2073+
assert!(rerun_output.contains("Ran 1 test"));
2074+
assert!(rerun_output.contains("testFail()"));
2075+
assert!(!rerun_output.contains("[PASS] testPass()"));
2076+
});

0 commit comments

Comments
 (0)