Skip to content

Commit

Permalink
fix: exitcode for all setup failures (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
daejunpark authored Jul 26, 2023
1 parent dbf7e33 commit ca2b3c3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/halmos/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ def _main(_args=None) -> MainResult:
)

num_passed = sum(r.exitcode == 0 for r in test_results)
num_failed = len(test_results) - num_passed
num_failed = len(funsigs) - num_passed

print(
f"Symbolic test result: {num_passed} passed; {num_failed} failed; time: {timer() - contract_start:0.2f}s"
Expand Down
3 changes: 2 additions & 1 deletion tests/expected/all.json
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@
"num_bounded_loops": null
}
],
"test/Setup.t.sol:SetupFailTest": [],
"test/Setup.t.sol:SetupTest": [
{
"name": "check_True()",
Expand Down Expand Up @@ -1097,4 +1098,4 @@
}
]
}
}
}
14 changes: 14 additions & 0 deletions tests/test/Setup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,17 @@ contract SetupTest is Test {
assertEq(users[2], address(0));
}
}

contract SetupFailTest {
function setUp() public {
revert();
}

function check_setUp_Fail1() public {
assert(true);
}

function check_setUp_Fail2() public {
assert(true);
}
}
16 changes: 16 additions & 0 deletions tests/test_halmos.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ def test_main(cmd, expected_path, halmos_options):
assert_eq(expected["test_results"], actual["test_results"])


@pytest.mark.parametrize(
"cmd",
[
["--root", "tests", "--contract", "SetupFailTest"],
["--root", "tests", "--contract", "LibTest"],
],
ids=(
"SetupFailTest",
"LibTest",
),
)
def test_main_fail(cmd, halmos_options):
actual = asdict(_main(cmd + halmos_options.split()))
assert actual["exitcode"] != 0


def assert_eq(m1: Dict, m2: Dict) -> int:
assert list(m1.keys()) == list(m2.keys())
for c in m1:
Expand Down

0 comments on commit ca2b3c3

Please sign in to comment.