You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The original no_colors.rs test did not function correctly (removing/commenting out the line cmd.env("NO_COLOR", "1"); did not change test outcomes). A new test suite should be created to validate the behavior of the CLI when it comes to ANSI styling and various conditions that affect it (such as the NO_COLOR environment variable).
Suggestion
The following general test outline is recommended based on current knowledge (tests/ansi_test.rs):
// SPDX-License-Identifier: Apache-2.0//! Test suite focussed on testing that ANSI is or isn't used in stdout/stderr based on options to//! suppress ansi-formatting.pubmod common;usecrate::common::TestResult;use predicates::prelude::*;#[test]fnexample_test_with_color() -> TestResult{with_color(|mut cmd, _test_dir| {
cmd.arg("--help").assert().stdout(has_ansi());Ok(())})}#[test]fnexample_test_without_color() -> TestResult{without_color(|mut cmd, _test_dir| {
cmd.arg("--help").assert().stdout(no_ansi()).stderr(no_ansi());Ok(())})}/// Run a test with ANSI styling enabled.////// See also [`common::with_test_dir`].fnwith_color<C>(callback:C) -> TestResultwhereC:FnOnce(assert_cmd::Command,&assert_fs::TempDir) -> TestResult,{
common::with_test_dir(|cmd, test_dir| callback(cmd, test_dir))}/// Run a test with the `NO_COLOR` environment variable set.////// See also [`common::with_test_dir`].fnwithout_color<C>(callback:C) -> TestResultwhereC:FnOnce(assert_cmd::Command,&assert_fs::TempDir) -> TestResult,{
common::with_test_dir(|mut cmd, test_dir| {
cmd.env("NO_COLOR","1");callback(cmd, test_dir)})}/// Create a predicate that evaluates to `true` if a given string contains ANSI characters.fnhas_ansi() -> predicates::str::RegexPredicate{// This regular expression is based on based on (MIT licensed):// <https://github.com/TheLarkInn/ansi-regex>constANSI_REGEX:&str = r"\x1b\[([\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e])";
predicates::str::is_match(ANSI_REGEX).expect("static regular expression should always be valid")}/// Create a predicate that evaluates to `true` if a given string does not contain ANSI characters.fnno_ansi() -> predicates::boolean::NotPredicate<predicates::str::RegexPredicate,str>{has_ansi().not()}
The text was updated successfully, but these errors were encountered:
Test Improvements
Caused by #13
Relates to #5, #16
Summary
The original
no_colors.rs
test did not function correctly (removing/commenting out the linecmd.env("NO_COLOR", "1");
did not change test outcomes). A new test suite should be created to validate the behavior of the CLI when it comes to ANSI styling and various conditions that affect it (such as theNO_COLOR
environment variable).Suggestion
The following general test outline is recommended based on current knowledge (
tests/ansi_test.rs
):The text was updated successfully, but these errors were encountered: