diff --git a/scripts/run_docker_compare.bash b/scripts/run_docker_compare.bash index 8fc4b74a..127f8f10 100755 --- a/scripts/run_docker_compare.bash +++ b/scripts/run_docker_compare.bash @@ -7,6 +7,8 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" : ${SHELL:="NO"} # or YES to launch a shell instead of running the test : ${TRACE:="NO"} # or YES to send traces to jaeger : ${BACKTRACE:="NO"} # or YES to print a rust backtrace when panicking +: ${NO_COLOR:=""} # Set to anything to disable color output + cd "$DIR/../" REALPATH=$(command -v uu-realpath || command -v realpath) @@ -25,6 +27,10 @@ function launch_container { local additional_flags=() local additional_args=() + if [ "$NO_COLOR" != "" ]; then + additional_flags+=(--env "NO_COLOR=$NO_COLOR") + fi + if [ "$SHELL" != "YES" ]; then additional_args+=(cargo run) else diff --git a/scripts/run_docker_integration_test.bash b/scripts/run_docker_integration_test.bash index b1bb8cf7..163aefe4 100755 --- a/scripts/run_docker_integration_test.bash +++ b/scripts/run_docker_integration_test.bash @@ -4,6 +4,8 @@ set -euo pipefail IFS=$'\n\t' DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +: ${NO_COLOR:=""} # Set to anything to disable color output + cd "$DIR/../" REALPATH=$(command -v uu-realpath || command -v realpath) MAKE=$(command -v gmake || command -v make) @@ -40,7 +42,11 @@ function get_test_names { function launch_container { local test="$1" - local additional_args=() + local additional_flags=() + + if [ "$NO_COLOR" != "" ]; then + additional_flags+=(--env "NO_COLOR=$NO_COLOR") + fi local init_script=$(cat < String { - format!( - "\x1b[38;2;{red};{green};{blue}m", - red = red, - green = green, - blue = blue - ) + if DiffResult::should_use_color() { + format!( + "\x1b[38;2;{red};{green};{blue}m", + red = red, + green = green, + blue = blue + ) + } else { + String::new() + } } #[allow(dead_code)] fn background_color(red: u8, green: u8, blue: u8) -> String { - format!( - "\x1b[48;2;{red};{green};{blue}m", - red = red, - green = green, - blue = blue - ) + if DiffResult::should_use_color() { + format!( + "\x1b[48;2;{red};{green};{blue}m", + red = red, + green = green, + blue = blue + ) + } else { + String::new() + } } fn reset_color() -> &'static str { - "\x1b[0m" + if DiffResult::should_use_color() { + "\x1b[0m" + } else { + "" + } + } + + fn should_use_color() -> bool { + !std::env::var("NO_COLOR").is_ok_and(|val| !val.is_empty()) } }