diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2018-03-12 21:30:28 +0100 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2018-03-12 21:33:39 +0100 |
commit | 878027f7332d266ed7ccca48c3b269e415e4ff75 (patch) | |
tree | 828b23b97f7d02532f0f541d249e24a09c941d20 | |
parent | da229e04fb175c568ed245f6874fe58a38d39fa7 (diff) | |
download | ccache-878027f7332d266ed7ccca48c3b269e415e4ff75.tar.gz |
test: Use helper functions instead of custom code
-rwxr-xr-x | test/run | 12 | ||||
-rw-r--r-- | test/suites/base.bash | 16 | ||||
-rw-r--r-- | test/suites/cleanup.bash | 36 | ||||
-rw-r--r-- | test/suites/direct.bash | 16 | ||||
-rw-r--r-- | test/suites/pch.bash | 28 | ||||
-rw-r--r-- | test/suites/readonly.bash | 8 |
6 files changed, 39 insertions, 77 deletions
@@ -110,6 +110,18 @@ expect_stat() { fi } +expect_file_exists() { + if [ ! -f "$1" ]; then + test_failed "Expected $1 to exist, but it's missing" + fi +} + +expect_file_missing() { + if [ -f "$1" ]; then + test_failed "Expected $1 to be missing, but it exists" + fi +} + expect_equal_files() { if [ ! -e "$1" ]; then test_failed "expect_equal_files: $1 missing" diff --git a/test/suites/base.bash b/test/suites/base.bash index 5ff9ab45..307100e8 100644 --- a/test/suites/base.bash +++ b/test/suites/base.bash @@ -645,20 +645,13 @@ EOF $CCACHE_COMPILE -c test1.c expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 - - num=`find $CCACHE_DIR -name '*.stderr' | wc -l` - if [ $num -ne 0 ]; then - test_failed "$num stderr files found, expected 0 (#1)" - fi + expect_file_count 0 '*.stderr' $CCACHE_DIR obj_file=`find $CCACHE_DIR -name '*.o'` stderr_file=`echo $obj_file | sed 's/..$/.stderr/'` echo "Warning: foo" >$stderr_file CCACHE_RECACHE=1 $CCACHE_COMPILE -c test1.c - num=`find $CCACHE_DIR -name '*.stderr' | wc -l` - if [ $num -ne 0 ]; then - test_failed "$num stderr files found, expected 0 (#2)" - fi + expect_file_count 0 '*.stderr' $CCACHE_DIR # ------------------------------------------------------------------------- TEST "No object file" @@ -706,10 +699,7 @@ int stderr(void) } EOF $CCACHE_COMPILE -Wall -W -c stderr.c 2>/dev/null - num=`find $CCACHE_DIR -name '*.stderr' | wc -l` - if [ $num -ne 1 ]; then - test_failed "$num stderr files found, expected 1" - fi + expect_file_count 1 '*.stderr' $CCACHE_DIR expect_stat 'files in cache' 2 # ------------------------------------------------------------------------- diff --git a/test/suites/cleanup.bash b/test/suites/cleanup.bash index 989c96fc..42638c76 100644 --- a/test/suites/cleanup.bash +++ b/test/suites/cleanup.bash @@ -69,15 +69,11 @@ SUITE_cleanup() { expect_stat 'cleanups performed' 1 for i in 0 1 2 3 4 5 9; do file=$CCACHE_DIR/a/result$i-4017.o - if [ ! -f $file ]; then - test_failed "File $file removed when it shouldn't" - fi + expect_file_exists $file done for i in 6 7 8; do file=$CCACHE_DIR/a/result$i-4017.o - if [ -f $file ]; then - test_failed "File $file not removed when it should" - fi + expect_file_missing $file done # ------------------------------------------------------------------------- @@ -101,15 +97,11 @@ SUITE_cleanup() { expect_stat 'cleanups performed' 1 for i in 3 4 5; do file=$CCACHE_DIR/a/result$i-4017.o - if [ ! -f $file ]; then - test_failed "File $file removed when it shouldn't" - fi + expect_file_exists $file done for i in 0 1 2 6 7 8 9; do file=$CCACHE_DIR/a/result$i-4017.o - if [ -f $file ]; then - test_failed "File $file not removed when it should" - fi + expect_file_missing $file done # ------------------------------------------------------------------------- @@ -173,15 +165,11 @@ SUITE_cleanup() { expect_stat 'files in cache' 21 for i in 0 1 3 4 5 8 9; do file=$CCACHE_DIR/a/result$i-4017.o - if [ ! -f $file ]; then - test_failed "File $file removed when it shouldn't" - fi + expect_file_exists $file done for i in 2 6 7; do file=$CCACHE_DIR/a/result$i-4017.o - if [ -f $file ]; then - test_failed "File $file not removed when it should" - fi + expect_file_missing $file done # ------------------------------------------------------------------------- @@ -195,9 +183,7 @@ SUITE_cleanup() { $CCACHE -F 480 -M 0 >/dev/null $CCACHE -c >/dev/null - if [ ! -f $CCACHE_DIR/a/abcd.unknown ]; then - test_failed "$CCACHE_DIR/a/abcd.unknown removed" - fi + expect_file_exists $CCACHE_DIR/a/abcd.unknown expect_stat 'files in cache' 28 # ------------------------------------------------------------------------- @@ -211,9 +197,7 @@ SUITE_cleanup() { expect_stat 'files in cache' 31 $CCACHE -F 480 -M 0 -c >/dev/null - if [ -f $CCACHE_DIR/a/abcd.unknown ]; then - test_failed "$CCACHE_DIR/a/abcd.unknown not removed" - fi + expect_file_missing $CCACHE_DIR/a/abcd.unknown expect_stat 'files in cache' 30 # ------------------------------------------------------------------------- @@ -225,9 +209,7 @@ SUITE_cleanup() { expect_stat 'files in cache' 1 backdate $CCACHE_DIR/a/abcd.tmp.efgh $CCACHE -c >/dev/null - if [ -f $CCACHE_DIR/a/abcd.tmp.efgh ]; then - test_failed "$CCACHE_DIR/a/abcd.tmp.unknown not removed" - fi + expect_file_missing $CCACHE_DIR/a/abcd.tmp.efgh expect_stat 'files in cache' 0 # ------------------------------------------------------------------------- diff --git a/test/suites/direct.bash b/test/suites/direct.bash index 0b2b3c8a..085029c0 100644 --- a/test/suites/direct.bash +++ b/test/suites/direct.bash @@ -133,9 +133,7 @@ EOF $CCACHE_COMPILE -MD -c test.c -o test.dir/test$ext rm -f $dep_file $CCACHE_COMPILE -MD -c test.c -o test.dir/test$ext - if [ ! -f $dep_file ]; then - test_failed "$dep_file missing" - fi + expect_file_exists $dep_file if ! grep "test$ext:" $dep_file >/dev/null 2>&1; then test_failed "$dep_file does not contain test$ext" fi @@ -144,9 +142,7 @@ EOF $CCACHE_COMPILE -MD -MQ $dep_target -c test.c -o test.dir/test$ext rm -f $dep_target $CCACHE_COMPILE -MD -MQ $dep_target -c test.c -o test.dir/test$ext - if [ ! -f $dep_file ]; then - test_failed "$dep_file missing" - fi + expect_file_exists $dep_file if ! grep $dep_target $dep_file >/dev/null 2>&1; then test_failed "$dep_file does not contain $dep_target" fi @@ -329,7 +325,7 @@ EOF expect_stat 'cache hit (direct)' 0 expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 - test -r code.gcno || test_failed "code.gcno missing" + expect_file_exists code.gcno rm code.gcno @@ -337,7 +333,7 @@ EOF expect_stat 'cache hit (direct)' 1 expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 - test -r code.gcno || test_failed "code.gcno missing" + expect_file_exists code.gcno # ------------------------------------------------------------------------- TEST "-fstack-usage" @@ -351,7 +347,7 @@ EOF expect_stat 'cache hit (direct)' 0 expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 - test -r code.su || test_failed "code.su missing" + expect_file_exists code.su rm code.su @@ -359,7 +355,7 @@ EOF expect_stat 'cache hit (direct)' 1 expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 - test -r code.su || test_failed "code.su missing" + expect_file_exists code.su fi # ------------------------------------------------------------------------- diff --git a/test/suites/pch.bash b/test/suites/pch.bash index c098e7f4..fdb8d0a2 100644 --- a/test/suites/pch.bash +++ b/test/suites/pch.bash @@ -79,9 +79,7 @@ pch_suite_gcc() { expect_stat 'cache hit (direct)' 1 expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 - if [ ! -f pch.h.gch ]; then - test_failed "pch.h.gch missing" - fi + expect_file_exists pch.h.gch # ------------------------------------------------------------------------- TEST "Create .gch, no -c, -o, with opt-in" @@ -95,9 +93,7 @@ pch_suite_gcc() { expect_stat 'cache hit (direct)' 1 expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 - if [ ! -f pch.gch ]; then - test_failed "pch.gch missing" - fi + expect_file_exists pch.gch # ------------------------------------------------------------------------- TEST "Use .gch, no -fpch-preprocess, #include" @@ -262,9 +258,7 @@ pch_suite_gcc() { expect_stat 'cache hit (direct)' 1 expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 - if [ ! -f pch.h.gch/foo ]; then - test_failed "pch.h.gch/foo missing" - fi + expect_file_exists pch.h.gch/foo backdate pch.h.gch/foo @@ -324,9 +318,7 @@ pch_suite_clang() { expect_stat 'cache hit (direct)' 1 expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 - if [ ! -f pch.h.gch ]; then - test_failed "pch.h.gch missing" - fi + expect_file_exists pch.h.gch # ------------------------------------------------------------------------- TEST "Create .gch, no -c, -o, with opt-in" @@ -340,9 +332,7 @@ pch_suite_clang() { expect_stat 'cache hit (direct)' 1 expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 - if [ ! -f pch.gch ]; then - test_failed "pch.gch missing" - fi + expect_file_exists pch.gch # ------------------------------------------------------------------------- TEST "Create .gch, include file mtime changed" @@ -371,9 +361,7 @@ EOF expect_stat 'cache miss' 2 $REAL_COMPILER $SYSROOT -c -include pch2.h pch2.c - if [ ! -f pch2.o ]; then - test_failed "pch.o missing" - fi + expect_file_exists pch2.o CCACHE_SLOPPINESS="$DEFAULT_SLOPPINESS pch_defines time_macros" $CCACHE_COMPILE $SYSROOT -c pch2.h expect_stat 'cache hit (direct)' 1 @@ -486,9 +474,7 @@ EOF expect_stat 'cache hit (direct)' 1 expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 - if [ ! -f pch.h.pth ]; then - test_failed "pch.h.pth missing" - fi + expect_file_exists pch.h.pth # ------------------------------------------------------------------------- TEST "Use .pth, no -fpch-preprocess, -include, no sloppiness" diff --git a/test/suites/readonly.bash b/test/suites/readonly.bash index d44c88f4..be986966 100644 --- a/test/suites/readonly.bash +++ b/test/suites/readonly.bash @@ -33,12 +33,8 @@ SUITE_readonly() { if [ $status2 -ne 0 ]; then test_failed "Failure when compiling test2.c read-only" fi - if [ ! -f test.o ]; then - test_failed "test.o missing" - fi - if [ ! -f test2.o ]; then - test_failed "test2.o missing" - fi + expect_file_exists test.o + expect_file_exists test2.o # ------------------------------------------------------------------------- TEST "Cache miss" |