fi
green() {
- printf "$ansi_boldgreen$*$ansi_reset\n"
+ printf "$ansi_boldgreen%s$ansi_reset\n" "$*"
}
red() {
- printf "$ansi_boldred$*$ansi_reset\n"
+ printf "$ansi_boldred%s$ansi_reset\n" "$*"
}
bold() {
- printf "$ansi_bold$*$ansi_reset\n"
+ printf "$ansi_bold%s$ansi_reset\n" "$*"
}
test_failed() {
generate_code() {
local nlines=$1
local outfile=$2
+ local i
rm -f $outfile
- for i in $(seq $nlines); do
+ for ((i = 1; i <= nlines; i++)); do
echo "int foo_$i(int x) { return x; }" >>$outfile
done
}
else
m=0
fi
- touch -t 1999010100$(printf "%02u" $m) "$@"
+ touch -t $((199901010000 + m)) "$@"
}
file_size() {
expect_stat() {
local stat="$1"
local expected_value="$2"
- local value="$(echo $($CCACHE -s | fgrep "$stat" | cut -c33-))"
+ local line
+ local value=""
+
+ while IFS= read -r line; do
+ if [[ $line = *"$stat"* ]]; then
+ value="${line:32}"
+ # remove leading & trailing whitespace
+ value="${value#${value%%[![:space:]]*}}"
+ value="${value%${value##*[![:space:]]}}"
+ break
+ fi
+ done < <($CCACHE -s)
if [ "$expected_value" != "$value" ]; then
test_failed "Expected \"$stat\" to be $expected_value, actual $value"
}
reset_environment() {
- while read name; do
- unset $name
- done <<EOF
-$(env | sed -n 's/^\(CCACHE_[A-Z0-9_]*\)=.*$/\1/p')
-EOF
+ while IFS= read -r name; do
+ if [[ $name =~ ^CCACHE_[A-Z0-9_]*$ ]]; then
+ unset $name
+ fi
+ done < <(compgen -e)
+
unset GCC_COLORS
unset TERM
unset XDG_CACHE_HOME
;;
*clang*)
COMPILER_TYPE_CLANG=true
- CLANG_VERSION_SUFFIX=$(echo $COMPILER | sed 's/.*clang//')
+ CLANG_VERSION_SUFFIX=$(echo "${COMPILER%% *}" | sed 's/.*clang//')
;;
*)
echo "WARNING: Compiler $COMPILER not supported (version: $compiler_version) -- not running tests" >&2
PATH_DELIM=":"
fi
+if [[ $OSTYPE = msys* ]]; then
+ # Native symlink support for Windows.
+ export MSYS="${MSYS:-} winsymlinks:nativestrict"
+fi
+
if $HOST_OS_APPLE; then
SDKROOT=$(xcrun --sdk macosx --show-sdk-path 2>/dev/null)
if [ "$SDKROOT" = "" ]; then
# The exact output is not tested, but at least it's something human readable
# and not random memory.
- if [ $($CCACHE --version | grep -c '^ccache version [a-zA-Z0-9_./+-]*$') -ne 1 ]; then
+ local version_pattern=$'^ccache version [a-zA-Z0-9_./+-]*\r?$'
+ if [ $($CCACHE --version | grep -E -c "$version_pattern") -ne 1 ]; then
test_failed "Unexpected output of --version"
fi
rm -rf src
# -------------------------------------------------------------------------
+if ! $HOST_OS_WINDOWS; then
TEST "Source file ending with dot"
mkdir src
rm foo.o
rm -rf src
+fi
# -------------------------------------------------------------------------
TEST "Multiple file extensions"
expect_stat 'files in cache' 1
expect_equal_object_files reference_test1.o test1.o
- CCACHE_COMPILER=$COMPILER $CCACHE non_existing_compiler_will_be_overridden_anyway -c test1.c
+ CCACHE_COMPILER=$COMPILER_BIN $CCACHE \
+ non_existing_compiler_will_be_overridden_anyway \
+ $COMPILER_ARGS -c test1.c
expect_stat 'cache hit (preprocessed)' 1
expect_stat 'cache miss' 1
expect_stat 'files in cache' 1
expect_equal_object_files reference_test1.o test1.o
- CCACHE_COMPILER=$COMPILER $CCACHE same/for/relative -c test1.c
+ CCACHE_COMPILER=$COMPILER_BIN $CCACHE same/for/relative \
+ $COMPILER_ARGS -c test1.c
expect_stat 'cache hit (preprocessed)' 2
expect_stat 'cache miss' 1
expect_stat 'files in cache' 1
expect_equal_object_files reference_test1.o test1.o
- CCACHE_COMPILER=$COMPILER $CCACHE /and/even/absolute/compilers -c test1.c
+ CCACHE_COMPILER=$COMPILER_BIN $CCACHE /and/even/absolute/compilers \
+ $COMPILER_ARGS -c test1.c
expect_stat 'cache hit (preprocessed)' 3
expect_stat 'cache miss' 1
expect_stat 'files in cache' 1
# -------------------------------------------------------------------------
+if ! $HOST_OS_WINDOWS; then
TEST "CCACHE_UMASK"
saved_umask=$(umask)
expect_perm "$stats_file" -rw-rw-r--
umask $saved_umask
+fi
# -------------------------------------------------------------------------
TEST "No object file due to bad prefix"
fi
# -------------------------------------------------------------------------
+if ! $HOST_OS_WINDOWS; then
TEST "UNCACHED_ERR_FD"
cat >compiler.sh <<'EOF'
if [ "$stderr" != "2Pu1Cc" ]; then
test_failed "Unexpected stderr: $stderr != 2Pu1Cc"
fi
+fi
# -------------------------------------------------------------------------
TEST "Invalid boolean environment configuration options"