From: Joel Rosdahl Date: Fri, 30 Oct 2020 13:59:08 +0000 (+0100) Subject: Tweak color_diagnostics.bash code style X-Git-Tag: v4.1~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=adf8a4773229fe85778a9071d1754192d9409efe;p=thirdparty%2Fccache.git Tweak color_diagnostics.bash code style --- diff --git a/test/suites/color_diagnostics.bash b/test/suites/color_diagnostics.bash index 7badb4b67..31ccc078d 100644 --- a/test/suites/color_diagnostics.bash +++ b/test/suites/color_diagnostics.bash @@ -1,7 +1,7 @@ -if $COMPILER_TYPE_GCC ; then +if $COMPILER_TYPE_GCC; then color_diagnostics_enable='-fdiagnostics-color' color_diagnostics_disable='-fno-diagnostics-color' -elif $COMPILER_TYPE_CLANG ; then +elif $COMPILER_TYPE_CLANG; then color_diagnostics_enable='-fcolor-diagnostics' color_diagnostics_disable='-fno-color-diagnostics' fi @@ -13,17 +13,17 @@ SUITE_color_diagnostics_PROBE() { fi # Probe that real compiler actually supports colored diagnostics. - if [[ ! $color_diagnostics_enable || ! $color_diagnostics_disable ]] ; then + if [[ ! $color_diagnostics_enable || ! $color_diagnostics_disable ]]; then echo "compiler $COMPILER does not support colored diagnostics" - elif ! $REAL_COMPILER $color_diagnostics_enable -E - /dev/null 2>&1 ; then + elif ! $REAL_COMPILER $color_diagnostics_enable -E - /dev/null 2>&1; then echo "compiler $COMPILER (version: $compiler_version) does not support $color_diagnostics_enable" - elif ! $REAL_COMPILER $color_diagnostics_disable -E - /dev/null 2>&1 ; then + elif ! $REAL_COMPILER $color_diagnostics_disable -E - /dev/null 2>&1; then echo "compiler $COMPILER (version: $compiler_version) does not support $color_diagnostics_disable" fi } SUITE_color_diagnostics_SETUP() { - if $run_second_cpp ; then + if $run_second_cpp; then export CCACHE_CPP2=1 else export CCACHE_NOCPP2=1 @@ -50,14 +50,19 @@ color_diagnostics_generate_code() { # Heap's permutation algorithm color_diagnostics_generate_permutations() { - local -i i k="${1:?}-1" - if (( k )) ; then + local -i i + local -i k="${1:?}-1" + if ((k)); then color_diagnostics_generate_permutations "$k" - for (( i = 0 ; i < k ; ++i )) ; do - if (( k & 1 )) ; then - local tmp=${A[$i]} ; A[$i]=${A[$k]} ; A[$k]=$tmp + for ((i = 0; i < k; ++i)); do + if ((k & 1)); then + local tmp=${A[$i]} + A[$i]=${A[$k]} + A[$k]=$tmp else - local tmp=${A[0]} ; A[0]=${A[$k]} ; A[$k]=$tmp + local tmp=${A[0]} + A[0]=${A[$k]} + A[$k]=$tmp fi color_diagnostics_generate_permutations "$k" done @@ -80,6 +85,7 @@ color_diagnostics_run_on_pty() { color_diagnostics_test() { # ------------------------------------------------------------------------- TEST "Colored diagnostics automatically disabled when stderr is not a TTY (run_second_cpp=$run_second_cpp)" + color_diagnostics_generate_code 1 test1.c $CCACHE_COMPILE -Wmissing-prototypes -c -o test1.o test1.c 2>test1.stderr color_diagnostics_expect_no_color test1.stderr @@ -92,6 +98,7 @@ color_diagnostics_test() { # ------------------------------------------------------------------------- TEST "Colored diagnostics automatically enabled when stderr is a TTY (run_second_cpp=$run_second_cpp)" + color_diagnostics_generate_code 1 test1.c color_diagnostics_run_on_pty test1.output "$CCACHE_COMPILE -Wmissing-prototypes -c -o test1.o test1.c" color_diagnostics_expect_color test1.output @@ -103,16 +110,20 @@ color_diagnostics_test() { expect_stat 'cache hit (preprocessed)' 1 # ------------------------------------------------------------------------- - while read -r case ; do + while read -r case; do TEST "Cache object shared across ${case} (run_second_cpp=$run_second_cpp)" + color_diagnostics_generate_code 1 test1.c - local each ; for each in ${case} ; do + local each + for each in ${case}; do case $each in color,*) - local color_flag=$color_diagnostics_enable color_expect=color + local color_flag=$color_diagnostics_enable + local color_expect=color ;; nocolor,*) - local color_flag=$color_diagnostics_disable color_expect=no_color + local color_flag=$color_diagnostics_disable + local color_expect=no_color ;; esac case $each in @@ -129,7 +140,7 @@ color_diagnostics_test() { expect_stat 'cache miss' 1 expect_stat 'cache hit (preprocessed)' 3 done < <( - A=( {color,nocolor},{tty,notty} ) + A=({color,nocolor},{tty,notty}) color_diagnostics_generate_permutations "${#A[@]}" ) }