11

Followed docs at https://book.getfoundry.sh/reference/forge-std/console-log

Tests are passing but console.log is not doing anything. I excepted it would print the output in the terminal.

Test contract is as follows:

pragma solidity =0.8.17;
import "forge-std/console.sol";
import "forge-std/Test.sol";

contract ProjectTest is Test { ProjectRouter router;

function setUp() public { router = new ProjectRouter(); console.log("DONE"); // NOT WORKING }

function test() public { // PASSED string memory name = router.name(); assertEq(router.name(), "Router"); }

function test123() public { // PASSED console.log(123); // NOT WORKING } }

Tried

contract ProjectTest is console, Test

But that gave more than 256 errors which look like this:

error[9097]: DeclarationError: Identifier already declared.
    --> lib/forge-std/src/console.sol:2090:3:
     |
2090 |   function log(bool p0, bool p1, bool p2, uint p3) internal view {
     |   ^ (Relevant source part starts here and spans across multiple lines).
Note: The previous declaration is here:
  --> lib/forge-std/lib/ds-test/src/test.sol:19:5:
   |
19 |     event log                    (string);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Delvir0
  • 115
  • 1
  • 5

1 Answers1

18

You need to increase the verbosity of forge test

That is, try forge test -vv for the log output. or forge test -vvvv for a full trace of every function call.

https://book.getfoundry.sh/reference/forge/forge-test

-v --verbosity Verbosity of the EVM.

Pass multiple times to increase the verbosity (e.g. -v, -vv, -vvv).

Verbosity levels:

  • 2: Print logs for all tests
  • 3: Print execution traces for failing tests
  • 4: Print execution traces for all tests, and setup traces for failing tests
  • 5: Print execution and setup traces for all tests

Bob Baxley
  • 344
  • 2
  • 5