Skip to content

Commit

Permalink
test: don't to_string
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Dec 1, 2024
1 parent becae71 commit b7fda34
Showing 1 changed file with 38 additions and 71 deletions.
109 changes: 38 additions & 71 deletions crates/forge/tests/cli/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,43 +219,38 @@ contract AContractTest is DSTest {
.unwrap();

// Assert 50% branch coverage for assert failure.
cmd.arg("coverage")
.args(["--mt".to_string(), "testAssertRevertBranch".to_string()])
.assert_success()
.stdout_eq(str![[r#"
cmd.arg("coverage").args(["--mt", "testAssertRevertBranch"]).assert_success().stdout_eq(str![
[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------------|--------------|--------------|--------------|---------------|
| src/AContract.sol | 66.67% (2/3) | 50.00% (1/2) | 50.00% (1/2) | 100.00% (1/1) |
| Total | 66.67% (2/3) | 50.00% (1/2) | 50.00% (1/2) | 100.00% (1/1) |
"#]]);
"#]
]);

// Assert 50% branch coverage for proper assert.
cmd.forge_fuse()
.arg("coverage")
.args(["--mt".to_string(), "testAssertBranch".to_string()])
.assert_success()
.stdout_eq(str![[r#"
cmd.forge_fuse().arg("coverage").args(["--mt", "testAssertBranch"]).assert_success().stdout_eq(
str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------------|---------------|---------------|--------------|---------------|
| src/AContract.sol | 100.00% (3/3) | 100.00% (2/2) | 50.00% (1/2) | 100.00% (1/1) |
| Total | 100.00% (3/3) | 100.00% (2/2) | 50.00% (1/2) | 100.00% (1/1) |
"#]]);
"#]],
);

// Assert 100% coverage (assert properly covered).
cmd.forge_fuse().arg("coverage").args(["--summary".to_string()]).assert_success().stdout_eq(
str![[r#"
cmd.forge_fuse().arg("coverage").args(["--summary"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------------|---------------|---------------|---------------|---------------|
| src/AContract.sol | 100.00% (3/3) | 100.00% (2/2) | 100.00% (2/2) | 100.00% (1/1) |
| Total | 100.00% (3/3) | 100.00% (2/2) | 100.00% (2/2) | 100.00% (1/1) |
"#]],
);
"#]]);
});

forgetest!(test_require_coverage, |prj, cmd| {
Expand Down Expand Up @@ -300,10 +295,7 @@ contract AContractTest is DSTest {
.unwrap();

// Assert 50% branch coverage if only revert tested.
cmd.arg("coverage")
.args(["--mt".to_string(), "testRequireRevert".to_string()])
.assert_success()
.stdout_eq(str![[r#"
cmd.arg("coverage").args(["--mt", "testRequireRevert"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------------|---------------|---------------|--------------|---------------|
Expand All @@ -315,7 +307,7 @@ contract AContractTest is DSTest {
// Assert 50% branch coverage if only happy path tested.
cmd.forge_fuse()
.arg("coverage")
.args(["--mt".to_string(), "testRequireNoRevert".to_string()])
.args(["--mt", "testRequireNoRevert"])
.assert_success()
.stdout_eq(str![[r#"
...
Expand All @@ -327,16 +319,14 @@ contract AContractTest is DSTest {
"#]]);

// Assert 100% branch coverage.
cmd.forge_fuse().arg("coverage").args(["--summary".to_string()]).assert_success().stdout_eq(
str![[r#"
cmd.forge_fuse().arg("coverage").args(["--summary"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------------|---------------|---------------|---------------|---------------|
| src/AContract.sol | 100.00% (2/2) | 100.00% (1/1) | 100.00% (2/2) | 100.00% (1/1) |
| Total | 100.00% (2/2) | 100.00% (1/1) | 100.00% (2/2) | 100.00% (1/1) |
"#]],
);
"#]]);
});

forgetest!(test_line_hit_not_doubled, |prj, cmd| {
Expand Down Expand Up @@ -609,10 +599,7 @@ contract FooTest is DSTest {

// Assert no coverage for single path branch. 2 branches (parent and child) not covered.
cmd.arg("coverage")
.args([
"--nmt".to_string(),
"test_single_path_child_branch|test_single_path_parent_branch".to_string(),
])
.args(["--nmt", "test_single_path_child_branch|test_single_path_parent_branch"])
.assert_success()
.stdout_eq(str![[r#"
...
Expand All @@ -626,7 +613,7 @@ contract FooTest is DSTest {
// Assert no coverage for single path child branch. 1 branch (child) not covered.
cmd.forge_fuse()
.arg("coverage")
.args(["--nmt".to_string(), "test_single_path_child_branch".to_string()])
.args(["--nmt", "test_single_path_child_branch"])
.assert_success()
.stdout_eq(str![[r#"
...
Expand All @@ -638,16 +625,14 @@ contract FooTest is DSTest {
"#]]);

// Assert 100% coverage.
cmd.forge_fuse().arg("coverage").args(["--summary".to_string()]).assert_success().stdout_eq(
str![[r#"
cmd.forge_fuse().arg("coverage").args(["--summary"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------|-----------------|-----------------|-----------------|---------------|
| src/Foo.sol | 100.00% (36/36) | 100.00% (30/30) | 100.00% (16/16) | 100.00% (9/9) |
| Total | 100.00% (36/36) | 100.00% (30/30) | 100.00% (16/16) | 100.00% (9/9) |
"#]],
);
"#]]);
});

forgetest!(test_function_call_coverage, |prj, cmd| {
Expand Down Expand Up @@ -711,7 +696,7 @@ contract AContractTest is DSTest {
.unwrap();

// Assert 100% coverage.
cmd.arg("coverage").args(["--summary".to_string()]).assert_success().stdout_eq(str![[r#"
cmd.arg("coverage").args(["--summary"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------------|-----------------|---------------|---------------|---------------|
Expand Down Expand Up @@ -810,28 +795,24 @@ contract FooTest is DSTest {
.unwrap();

// Assert coverage not 100% for happy paths only.
cmd.arg("coverage").args(["--mt".to_string(), "happy".to_string()]).assert_success().stdout_eq(
str![[r#"
cmd.arg("coverage").args(["--mt", "happy"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------|----------------|----------------|--------------|---------------|
| src/Foo.sol | 75.00% (15/20) | 66.67% (14/21) | 83.33% (5/6) | 100.00% (5/5) |
| Total | 75.00% (15/20) | 66.67% (14/21) | 83.33% (5/6) | 100.00% (5/5) |
"#]],
);
"#]]);

// Assert 100% branch coverage (including clauses without body).
cmd.forge_fuse().arg("coverage").args(["--summary".to_string()]).assert_success().stdout_eq(
str![[r#"
cmd.forge_fuse().arg("coverage").args(["--summary"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------|-----------------|-----------------|---------------|---------------|
| src/Foo.sol | 100.00% (20/20) | 100.00% (21/21) | 100.00% (6/6) | 100.00% (5/5) |
| Total | 100.00% (20/20) | 100.00% (21/21) | 100.00% (6/6) | 100.00% (5/5) |
"#]],
);
"#]]);
});

forgetest!(test_yul_coverage, |prj, cmd| {
Expand Down Expand Up @@ -927,16 +908,14 @@ contract FooTest is DSTest {
)
.unwrap();

cmd.forge_fuse().arg("coverage").args(["--summary".to_string()]).assert_success().stdout_eq(
str![[r#"
cmd.forge_fuse().arg("coverage").args(["--summary"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------|-----------------|-----------------|---------------|---------------|
| src/Foo.sol | 100.00% (30/30) | 100.00% (40/40) | 100.00% (1/1) | 100.00% (7/7) |
| Total | 100.00% (30/30) | 100.00% (40/40) | 100.00% (1/1) | 100.00% (7/7) |
"#]],
);
"#]]);
});

forgetest!(test_misc_coverage, |prj, cmd| {
Expand Down Expand Up @@ -1019,16 +998,14 @@ contract FooTest is DSTest {
)
.unwrap();

cmd.forge_fuse().arg("coverage").args(["--summary".to_string()]).assert_success().stdout_eq(
str![[r#"
cmd.forge_fuse().arg("coverage").args(["--summary"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------|-----------------|---------------|---------------|---------------|
| src/Foo.sol | 100.00% (12/12) | 100.00% (9/9) | 100.00% (0/0) | 100.00% (4/4) |
| Total | 100.00% (12/12) | 100.00% (9/9) | 100.00% (0/0) | 100.00% (4/4) |
"#]],
);
"#]]);
});

// https://github.com/foundry-rs/foundry/issues/8605
Expand Down Expand Up @@ -1075,10 +1052,7 @@ contract AContractTest is DSTest {
.unwrap();

// Assert 50% coverage for true branches.
cmd.arg("coverage")
.args(["--mt".to_string(), "testTrueCoverage".to_string()])
.assert_success()
.stdout_eq(str![[r#"
cmd.arg("coverage").args(["--mt", "testTrueCoverage"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------------|--------------|--------------|--------------|---------------|
Expand All @@ -1090,7 +1064,7 @@ contract AContractTest is DSTest {
// Assert 50% coverage for false branches.
cmd.forge_fuse()
.arg("coverage")
.args(["--mt".to_string(), "testFalseCoverage".to_string()])
.args(["--mt", "testFalseCoverage"])
.assert_success()
.stdout_eq(str![[r#"
...
Expand All @@ -1102,16 +1076,14 @@ contract AContractTest is DSTest {
"#]]);

// Assert 100% coverage (true/false branches properly covered).
cmd.forge_fuse().arg("coverage").args(["--summary".to_string()]).assert_success().stdout_eq(
str![[r#"
cmd.forge_fuse().arg("coverage").args(["--summary"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------------|---------------|---------------|---------------|---------------|
| src/AContract.sol | 100.00% (5/5) | 100.00% (4/4) | 100.00% (4/4) | 100.00% (1/1) |
| Total | 100.00% (5/5) | 100.00% (4/4) | 100.00% (4/4) | 100.00% (1/1) |
"#]],
);
"#]]);
});

// https://github.com/foundry-rs/foundry/issues/8604
Expand Down Expand Up @@ -1164,10 +1136,7 @@ contract AContractTest is DSTest {
.unwrap();

// Assert 50% coverage for true branches.
cmd.arg("coverage")
.args(["--mt".to_string(), "testTrueCoverage".to_string()])
.assert_success()
.stdout_eq(str![[r#"
cmd.arg("coverage").args(["--mt", "testTrueCoverage"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------------|--------------|--------------|--------------|---------------|
Expand All @@ -1179,7 +1148,7 @@ contract AContractTest is DSTest {
// Assert 50% coverage for false branches.
cmd.forge_fuse()
.arg("coverage")
.args(["--mt".to_string(), "testFalseCoverage".to_string()])
.args(["--mt", "testFalseCoverage"])
.assert_success()
.stdout_eq(str![[r#"
...
Expand All @@ -1191,16 +1160,14 @@ contract AContractTest is DSTest {
"#]]);

// Assert 100% coverage (true/false branches properly covered).
cmd.forge_fuse().arg("coverage").args(["--summary".to_string()]).assert_success().stdout_eq(
str![[r#"
cmd.forge_fuse().arg("coverage").args(["--summary"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------------|---------------|---------------|---------------|---------------|
| src/AContract.sol | 100.00% (5/5) | 100.00% (5/5) | 100.00% (2/2) | 100.00% (1/1) |
| Total | 100.00% (5/5) | 100.00% (5/5) | 100.00% (2/2) | 100.00% (1/1) |
"#]],
);
"#]]);
});

forgetest!(test_identical_bytecodes, |prj, cmd| {
Expand Down Expand Up @@ -1262,7 +1229,7 @@ contract AContractTest is DSTest {
)
.unwrap();

cmd.arg("coverage").args(["--summary".to_string()]).assert_success().stdout_eq(str![[r#"
cmd.arg("coverage").args(["--summary"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------------|-----------------|---------------|---------------|---------------|
Expand Down Expand Up @@ -1312,7 +1279,7 @@ contract AContractTest is DSTest {
)
.unwrap();

cmd.arg("coverage").args(["--summary".to_string()]).assert_success().stdout_eq(str![[r#"
cmd.arg("coverage").args(["--summary"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------------|---------------|---------------|---------------|---------------|
Expand Down Expand Up @@ -1355,7 +1322,7 @@ contract AContractTest is DSTest {
.unwrap();

// Assert there's only one function (`increment`) reported.
cmd.arg("coverage").args(["--summary".to_string()]).assert_success().stdout_eq(str![[r#"
cmd.arg("coverage").args(["--summary"]).assert_success().stdout_eq(str![[r#"
...
| File | % Lines | % Statements | % Branches | % Funcs |
|-------------------|---------------|---------------|---------------|---------------|
Expand Down

0 comments on commit b7fda34

Please sign in to comment.