foundry icon indicating copy to clipboard operation
foundry copied to clipboard

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

Open adhusson opened this issue 3 years ago • 7 comments

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.

adhusson avatar Jul 05 '22 09:07 adhusson

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

onbjerg avatar Jul 05 '22 10:07 onbjerg

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

adhusson avatar Jul 05 '22 10:07 adhusson

I think you can get print+pipe with tee

mattsse avatar Jul 05 '22 10:07 mattsse

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.

adhusson avatar Jul 05 '22 10:07 adhusson

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

mattsse avatar Jul 05 '22 10:07 mattsse

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?

0xYYY avatar Jul 05 '22 15:07 0xYYY

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.

ByteAtATime avatar Aug 07 '24 01:08 ByteAtATime