Skip to content

no coverage data from constructor #3453

@izlatkin

Description

@izlatkin

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (5342d1c 2022-09-26T16:07:26.540702Z)

What command(s) is the bug in?

forge coverage --match constructor_1 --report lcov

Operating System

macOS (Intel)

Describe the bug

There is no coverage information from the constructor block (see screenshot)
image

source: constructor_1.sol

contract C {
     uint x;
	constructor(uint b) {
		if (b > 0) {
			x = 1;
			return;
		}
		else {
			x = 2;
			return;
		}
		x = 3;
	}

    function f(uint _x) public {
        uint a = 3;
        if (x > 2) {
            a = 5;
        }
        x = _x;
        assert(a >= 3);
    }

    function set_max(uint _x, uint _y) public {
        if(_x > _y){
            x = _x;
        }else{
            x = _y;
        }
    }
}

Test:

import "forge-std/Test.sol";
import "../src/constructor_1.sol";

contract constructor_1_Test is Test {
	C c0;
	C c1;
	C c2;
	function setUp() public {
		c0 = new C(1);
		c1 = new C(1);
		c2 = new C(0);
	}
	function test_constructor_1_0() public {
		c0.f(1);
		assertTrue(true);
	}
	function test_constructor_1_1() public {
		c1.f(0);
		assertTrue(true);
	}
	function test_constructor_1_2() public {
		c2.f(1);
		assertTrue(true);
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Completed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions