josecelano / cargo-pretty-test

A Rust command that prettifies the ugly `cargo test` output into a beautiful one.
https://users.rust-lang.org/t/cargo-test-output-with-indentation/100149
135 stars 1 forks source link

`--color` will control whether the emitted texts should be colored in terminal #25

Closed zjp-CN closed 11 months ago

zjp-CN commented 11 months ago

Accepts one of always,never,auto. And support environment variable CARGO_TERM_COLOR from cargo

e.g.

--color=never

--color never

CARGO_TERM_COLOR=never

zjp-CN commented 11 months ago

--color always

CI demo: https://github.com/zjp-CN/torrust-tracker/actions/runs/6315151297/job/17147036800

josecelano commented 11 months ago

Hi @zjp-CN, It's nice to have the feature to enable/disable color. I'll have to use the colourless version when I show the report in the markdown summary:

image

zjp-CN commented 11 months ago

I'll have to use the colourless version when I show the report in the markdown summary:

You've set CARGO_TERM_COLOR: always, so the summary is in color. In your case, you can override the env by --color never:

-cargo pretty-test --lib --bins >> $GITHUB_STEP_SUMMARY
+cargo pretty-test --lib --bins --color=never >> $GITHUB_STEP_SUMMARY
zjp-CN commented 11 months ago

The indent in the summary is parsed as gfm (markdown). I guess to keep raw text, you could do this (not tested)

echo -n "<pre>" >> $GITHUB_STEP_SUMMARY
echo -n "$(cargo pretty-test --color=never)" >> $GITHUB_STEP_SUMMARY
echo -n "</pre>" >> $GITHUB_STEP_SUMMARY
josecelano commented 11 months ago

The indent in the summary is parsed as gfm (markdown). I guess to keep raw text, you could do this (not tested)

echo -n "<pre>" >> $GITHUB_STEP_SUMMARY
echo -n "$(cargo pretty-test --color=never)" >> $GITHUB_STEP_SUMMARY
echo -n "</pre>" >> $GITHUB_STEP_SUMMARY

It seems the output is pretty similar (with "pre" and "backticks"):

image

zjp-CN commented 11 months ago

So that's to say the <pre> trick doesn't work here?

josecelano commented 11 months ago

So that's to say the \<pre\> trick doesn't work here?

It works but produces almost the same output as backticks. You can see here:

Generated by cargo-pretty-test
└── (OK) torrust_tracker ... (265 tests in 0.56s: ✅ 265)
    └── (OK) src/lib.rs ... (265 tests in 0.56s: ✅ 265)
        ├── bootstrap
        │   └── config
        │       └── tests
        │           └─ ✅ it_should_load_with_default_config
        ├── servers
        │   ├── apis
        │   │   ├── server
        │   │   │   └── tests
        │   │   │       └─ ✅ it_should_be_able_to_start_from_stopped_state_and_then_stop_again
        │   │   └── v1
        │   │       └── context
        │   │           ├── auth_key
        │   │           │   └── resources
        │   │           │       └── tests
        │   │           │           ├─ ✅ it_should_be_convertible_from_an_auth_key
        │   │           │           ├─ ✅ it_should_be_convertible_into_an_auth_key
        │   │           │           └─ ✅ it_should_be_convertible_into_json
Generated by cargo-pretty-test
└── (OK) torrust_tracker ... (265 tests in 0.56s: ✅ 265)
    └── (OK) src/lib.rs ... (265 tests in 0.56s: ✅ 265)
        ├── bootstrap
        │   └── config
        │       └── tests
        │           └─ ✅ it_should_load_with_default_config
        ├── servers
        │   ├── apis
        │   │   ├── server
        │   │   │   └── tests
        │   │   │       └─ ✅ it_should_be_able_to_start_from_stopped_state_and_then_stop_again
        │   │   └── v1
        │   │       └── context
        │   │           ├── auth_key
        │   │           │   └── resources
        │   │           │       └── tests
        │   │           │           ├─ ✅ it_should_be_convertible_from_an_auth_key
        │   │           │           ├─ ✅ it_should_be_convertible_into_an_auth_key
        │   │           │           └─ ✅ it_should_be_convertible_into_json