-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
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 >/dev/null 2>&1 ; then
+ elif ! $REAL_COMPILER $color_diagnostics_enable -E - </dev/null >/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 >/dev/null 2>&1 ; then
+ elif ! $REAL_COMPILER $color_diagnostics_disable -E - </dev/null >/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
# 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
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
# -------------------------------------------------------------------------
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
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
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[@]}"
)
}