@@ -69,25 +69,25 @@ Compiler run successful!
6969
7070Ran 8 tests for test/CounterTable.t.sol:CounterTableTest
7171[FAIL: 2 fixtures defined for diffSwap (expected 10)] tableMultipleParamsDifferentFixturesFail(uint256,bool) ([GAS])
72- [FAIL: Cannot swap; counterexample: calldata=0x717892ca00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001 args=[1, true]] tableMultipleParamsFail(uint256,bool) ([GAS ])
72+ [FAIL: Cannot swap; counterexample: calldata=0x717892ca00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001 args=[1, true]] tableMultipleParamsFail(uint256,bool) (runs: 1, [AVG_GAS ])
7373Traces:
7474 [..] CounterTableTest::tableMultipleParamsFail(1, true)
7575 └─ ← [Revert] Cannot swap
7676
7777[FAIL: No fixture defined for param noSwap] tableMultipleParamsNoParamFail(uint256,bool) ([GAS])
78- [PASS] tableMultipleParamsPass(uint256,bool) ([GAS ])
78+ [PASS] tableMultipleParamsPass(uint256,bool) (runs: 10, [AVG_GAS ])
7979Traces:
8080 [..] CounterTableTest::tableMultipleParamsPass(10, true)
8181 ├─ [..] Counter::increment()
8282 │ └─ ← [Stop]
8383 └─ ← [Stop]
8484
85- [FAIL: Amount cannot be 10; counterexample: calldata=0x44fa2375000000000000000000000000000000000000000000000000000000000000000a args=[10]] tableSingleParamFail(uint256) ([GAS ])
85+ [FAIL: Amount cannot be 10; counterexample: calldata=0x44fa2375000000000000000000000000000000000000000000000000000000000000000a args=[10]] tableSingleParamFail(uint256) (runs: 10, [AVG_GAS ])
8686Traces:
8787 [..] CounterTableTest::tableSingleParamFail(10)
8888 └─ ← [Revert] Amount cannot be 10
8989
90- [PASS] tableSingleParamPass(uint256) ([GAS ])
90+ [PASS] tableSingleParamPass(uint256) (runs: 10, [AVG_GAS ])
9191Traces:
9292 [..] CounterTableTest::tableSingleParamPass(10)
9393 ├─ [..] Counter::increment()
@@ -103,13 +103,117 @@ Ran 1 test suite [ELAPSED]: 2 tests passed, 6 failed, 0 skipped (8 total tests)
103103Failing tests:
104104Encountered 6 failing tests in test/CounterTable.t.sol:CounterTableTest
105105[FAIL: 2 fixtures defined for diffSwap (expected 10)] tableMultipleParamsDifferentFixturesFail(uint256,bool) ([GAS])
106- [FAIL: Cannot swap; counterexample: calldata=0x717892ca00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001 args=[1, true]] tableMultipleParamsFail(uint256,bool) ([GAS ])
106+ [FAIL: Cannot swap; counterexample: calldata=0x717892ca00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001 args=[1, true]] tableMultipleParamsFail(uint256,bool) (runs: 1, [AVG_GAS ])
107107[FAIL: No fixture defined for param noSwap] tableMultipleParamsNoParamFail(uint256,bool) ([GAS])
108- [FAIL: Amount cannot be 10; counterexample: calldata=0x44fa2375000000000000000000000000000000000000000000000000000000000000000a args=[10]] tableSingleParamFail(uint256) ([GAS ])
108+ [FAIL: Amount cannot be 10; counterexample: calldata=0x44fa2375000000000000000000000000000000000000000000000000000000000000000a args=[10]] tableSingleParamFail(uint256) (runs: 10, [AVG_GAS ])
109109[FAIL: Table test should have at least one parameter] tableWithNoParamFail() ([GAS])
110110[FAIL: Table test should have at least one fixture] tableWithParamNoFixtureFail(uint256) ([GAS])
111111
112112Encountered a total of 6 failing tests, 2 tests succeeded
113113
114114"# ] ] ) ;
115115} ) ;
116+
117+ // Table tests should show logs and contribute to coverage.
118+ // <https://github.com/foundry-rs/foundry/issues/11066>
119+ forgetest_init ! ( should_show_logs_and_add_coverage, |prj, cmd| {
120+ prj. wipe_contracts( ) ;
121+ prj. add_source(
122+ "Counter.sol" ,
123+ r#"
124+ contract Counter {
125+ uint256 public number;
126+
127+ function setNumber(uint256 a, uint256 b) public {
128+ if (a == 1) {
129+ number = b + 1;
130+ } else if (a == 2) {
131+ number = b + 2;
132+ } else if (a == 3) {
133+ number = b + 3;
134+ } else {
135+ number = a + b;
136+ }
137+ }
138+ }
139+ "# ,
140+ ) ;
141+ prj. add_test(
142+ "CounterTest.t.sol" ,
143+ r#"
144+ import "forge-std/Test.sol";
145+ import {Counter} from "../src/Counter.sol";
146+
147+ contract CounterTest is Test {
148+ struct TestCase {
149+ uint256 a;
150+ uint256 b;
151+ uint256 expected;
152+ }
153+
154+ Counter public counter;
155+
156+ function setUp() public {
157+ counter = new Counter();
158+ }
159+
160+ function fixtureNumbers() public pure returns (TestCase[] memory) {
161+ TestCase[] memory entries = new TestCase[](4);
162+ entries[0] = TestCase(1, 5, 6);
163+ entries[1] = TestCase(2, 10, 12);
164+ entries[2] = TestCase(3, 11, 14);
165+ entries[3] = TestCase(4, 11, 15);
166+ return entries;
167+ }
168+
169+ function tableSetNumberTest(TestCase memory numbers) public {
170+ console.log("expected", numbers.expected);
171+ counter.setNumber(numbers.a, numbers.b);
172+ require(counter.number() == numbers.expected, "test failed");
173+ }
174+ }
175+ "# ,
176+ ) ;
177+
178+ cmd. args( [ "test" , "-vvv" ] ) . assert_success( ) . stdout_eq( str ![ [ r#"
179+ [COMPILING_FILES] with [SOLC_VERSION]
180+ [SOLC_VERSION] [ELAPSED]
181+ Compiler run successful!
182+
183+ Ran 1 test for test/CounterTest.t.sol:CounterTest
184+ [PASS] tableSetNumberTest((uint256,uint256,uint256)) (runs: 4, [AVG_GAS])
185+ Logs:
186+ expected 6
187+ expected 12
188+ expected 14
189+ expected 15
190+
191+ Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED]
192+
193+ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
194+
195+ "# ] ] ) ;
196+
197+ cmd. forge_fuse( ) . args( [ "coverage" ] ) . assert_success( ) . stdout_eq( str ![ [ r#"
198+ [COMPILING_FILES] with [SOLC_VERSION]
199+ [SOLC_VERSION] [ELAPSED]
200+ Compiler run successful!
201+ Analysing contracts...
202+ Running tests...
203+
204+ Ran 1 test for test/CounterTest.t.sol:CounterTest
205+ [PASS] tableSetNumberTest((uint256,uint256,uint256)) (runs: 4, [AVG_GAS])
206+ Suite result: ok. 1 passed; 0 failed; 0 skipped; [ELAPSED]
207+
208+ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
209+
210+ ╭-----------------+---------------+---------------+---------------+---------------╮
211+ | File | % Lines | % Statements | % Branches | % Funcs |
212+ +=================================================================================+
213+ | src/Counter.sol | 100.00% (8/8) | 100.00% (7/7) | 100.00% (6/6) | 100.00% (1/1) |
214+ |-----------------+---------------+---------------+---------------+---------------|
215+ | Total | 100.00% (8/8) | 100.00% (7/7) | 100.00% (6/6) | 100.00% (1/1) |
216+ ╰-----------------+---------------+---------------+---------------+---------------╯
217+
218+ "# ] ] ) ;
219+ } ) ;
0 commit comments