Skip to content

bug(forge test): table tests only capture last iteration's console logs and gas snapshots #11066

@die-herdplatte

Description

@die-herdplatte

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

1.3.0-nightly 56b806a

What version of Foundryup are you on?

1.3.0

What command(s) is the bug in?

forge test

Operating System

Linux

Describe the bug

Hey,

I don't know if this is intentional, but with the following test contract, console logs are only emitted for the last iteration.

pragma solidity ^0.8.30;

import {Test} from "forge-std/Test.sol";
import {console} from "forge-std/console.sol";

contract MyTest is Test {
    function fixtureStr() public pure returns (string[2] memory strings) {
        strings[0] = "first";
        strings[1] = "second";
    }

    function tableStrTest(string memory str) public pure {
        console.log(str);
    }
}

Running forge test:

[PASS] tableStrTest(string) (gas: 3464)
Logs:
  second

The same thing also applies to gas snapshots, where only snapshots made in the last iteration are recorded.

Potential code section that causes this behavior: https://github.com/grandizzy/foundry/blob/887a282cca0fd1c38072fa8e1ede896d06c7b94c/crates/forge/src/runner.rs#L670-L675

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions