Skip to content

Commit f3718f8

Browse files
grandizzyDaniPopes
andauthored
test: invariant sequence colors (#11730)
* chore: add invariant output test * fix: enable/disable global yansi color with flag * update --------- Co-authored-by: DaniPopes <[email protected]>
1 parent f510f58 commit f3718f8

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

crates/forge/tests/cli/test_cmd/mod.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4234,3 +4234,42 @@ Tip: Run `forge test --rerun` to retry only the 2 failed tests
42344234
42354235
"#]]);
42364236
});
4237+
4238+
// <https://github.com/foundry-rs/foundry/issues/11632>
4239+
#[cfg(not(feature = "isolate-by-default"))]
4240+
forgetest_init!(invariant_consistent_output, |prj, cmd| {
4241+
prj.update_config(|config| {
4242+
config.fuzz.seed = Some(U256::from(100u32));
4243+
config.invariant.runs = 10;
4244+
config.invariant.depth = 100;
4245+
config.invariant.show_metrics = false;
4246+
});
4247+
prj.add_test(
4248+
"InvariantOutputTest.t.sol",
4249+
r#"
4250+
import {Test} from "forge-std/Test.sol";
4251+
4252+
contract InvariantOutputTest is Test {
4253+
uint256 count;
4254+
4255+
function setCond(uint256 cond) public {
4256+
if (cond > type(uint256).max / 2) {
4257+
count++;
4258+
}
4259+
}
4260+
4261+
function setUp() public {
4262+
targetContract(address(this));
4263+
}
4264+
4265+
function invariant_check_count() public view {
4266+
require(count < 2, "failed invariant");
4267+
}
4268+
}
4269+
"#,
4270+
);
4271+
4272+
cmd.args(["test", "--mt", "invariant_check_count", "--color", "always"])
4273+
.assert_failure()
4274+
.stdout_eq(file!["../../fixtures/invariant_traces.svg": TermSvg]);
4275+
});
Lines changed: 78 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)