foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.13k stars 1.69k forks source link

feat(`forge test`) add an optional `--json-file` argument to write both to `stdout` and to a JSON file #2210

Open adhusson opened 2 years ago

adhusson commented 2 years ago

Component

Forge

Describe the feature you would like

When running tests in a CI, it is useful to both show the human-readable output on stdout and write a JSON file to be processed at later stages by the CI.

Right now, the only way to output both is either 1) to run forge test twice, or 2) to run forge test --json | myProcessingTool, where myProcessingTool writes a JSON file and format the JSON back to human-readable output.

With forge test --json-file path/to/file you would get both outputs.

onbjerg commented 2 years ago

What would you use the JSON output for? Out of curiosity.

adhusson commented 2 years ago

Parse and format for the CI, create test summaries (e.g. this from test-reporter).

mattsse commented 2 years ago

I think you can get print+pipe with tee

adhusson commented 2 years ago

Thanks, yes it would help to print either text or JSON both on stdout and a file, but to get text to stdout + JSON to a file I think you need something like a --json-file argument.

mattsse commented 2 years ago

this is, unfortunately, a bit unambiguous because then we can't really write to file OR print to stdout

you can print and write with --json | tee out.json

0xYYY commented 2 years ago

I think what OP want is to have the stdout of forge test, but at the same time, save the output of forge test --json to a file.

To implement that, we could save the output of serialized results to a file here and here if the --json-file flag is supplied?

ByteAtATime commented 1 month ago

Hey, what is the status on this? I also need the feature for my project, to have a script that outputs the original stdout (human-readable) for the user but also get the json data for processing.