]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
test: Use helper functions instead of custom code
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 12 Mar 2018 20:30:28 +0000 (21:30 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 12 Mar 2018 20:33:39 +0000 (21:33 +0100)
test/run
test/suites/base.bash
test/suites/cleanup.bash
test/suites/direct.bash
test/suites/pch.bash
test/suites/readonly.bash

index 1baf3646d25cc2c4b6b6eb48a4645ed45de55979..f065316cc82587a62bda6707692d1214b80c3b71 100755 (executable)
--- a/test/run
+++ b/test/run
@@ -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"
index 5ff9ab456ba5b533442e38e71519295e31a1f8eb..307100e84d3888519e20230370186e8f187450b8 100644 (file)
@@ -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
 
     # -------------------------------------------------------------------------
index 989c96fc7304799d822765071a2c8870470cfe92..42638c762ede3a70560a25321fd755553cf9bcb8 100644 (file)
@@ -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
 
     # -------------------------------------------------------------------------
index 0b2b3c8a5946522b332374ac99d2b91f79ab5f9b..085029c090c73c050727421dadb344c071b8aa51 100644 (file)
@@ -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
 
     # -------------------------------------------------------------------------
index c098e7f41ce6a3405d6eb57785d6c47564f98d30..fdb8d0a2ffe349b9b8dce226d028275a70d1e486 100644 (file)
@@ -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"
index d44c88f4370427ab12f13e0c2eaeecbe415274d4..be98696687450db59eb0e870078c3d0c6434824d 100644 (file)
@@ -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"