colored-rs / colored

(Rust) Coloring terminal so simple you already know how to do it !
Mozilla Public License 2.0
1.74k stars 84 forks source link

Replace `println!` calls with snapshot tests #158

Closed spenserblack closed 11 months ago

spenserblack commented 11 months ago

As discussed in #156, this converts the visual tests into things that can be asserted with cargo test. These can still be visually reviewed with cat path/to/snapshot. This also registers the detected language for *.snap files as plain text -- currently, GitHub will detect them as Jest snapshot files and apply a JavaScript-like syntax highlighting otherwise. This also installs cargo-insta when a contributor creates a new codespace.

The one println! in a test that I didn't address is here https://github.com/colored-rs/colored/blob/682adf8050f7566b4cef125515c1248c8e55736b/src/lib.rs#L839

Since that didn't look like part of the test, but just a snippet to help debug. I was tempted to switch it to a dbg! call, but dbg! prints the Debug formatting instead of the display formatting.

spenserblack commented 11 months ago

Oh, interesting. The CI environment didn't detect truecolor support by default, causing the snapshot tests to fail. I updated the env key in the test workflow to force true color. Perhaps there should be some sort of togglable value, even if it's internal, so that this can be forced inside tests instead of leaving it up to the environment.