]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Add test case for directives-only/rewrite-includes
authorAnders F Björklund <anders.f.bjorklund@gmail.com>
Sun, 25 Jun 2017 19:49:15 +0000 (21:49 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 30 Jan 2018 20:39:24 +0000 (21:39 +0100)
Use run_second_cpp = false (also known sometimes as "cpp1"),
but instruct the preprocessor to only handle include directives.

Make sure that any headers are still processed, and that both
the #define and -D work as usual (with regular preprocessing).

test/suites/cpp1.bash [new file with mode: 0644]

diff --git a/test/suites/cpp1.bash b/test/suites/cpp1.bash
new file mode 100644 (file)
index 0000000..eefa1f4
--- /dev/null
@@ -0,0 +1,65 @@
+SUITE_cpp1_PROBE() {
+    touch test.c
+    if $COMPILER_TYPE_GCC; then
+        if ! $UNCACHED_COMPILE -E -fdirectives-only test.c >/dev/null 2>&1; then
+            echo "-fdirectives-only not supported by compiler"
+            return
+        fi
+    elif $COMPILER_TYPE_CLANG; then
+        if ! $UNCACHED_COMPILE -E -frewrite-includes test.c >/dev/null 2>&1; then
+            echo "-frewrite-includes not supported by compiler"
+            return
+        fi
+    else
+        echo "Unknown compiler: $COMPILER"
+        return
+    fi
+}
+
+SUITE_cpp1_SETUP() {
+    export CCACHE_NOCPP2=1
+    echo "#define FOO 1" >test1.h
+    backdate test1.h
+    echo "#include \"test1.h\"" >test1.c
+    echo "#define BAR 2" >>test1.c
+    echo "int foo(int x) { return FOO; }" >>test1.c
+    echo "int bar(int x) { return BAR; }" >>test1.c
+    echo "int baz(int x) { return BAZ; }" >>test1.c
+}
+
+SUITE_cpp1() {
+    if $COMPILER_TYPE_GCC; then
+        cpp_flag="-fdirectives-only"
+    elif $COMPILER_TYPE_CLANG; then
+        cpp_flag="-frewrite-includes"
+    fi
+    cpp_flag="$cpp_flag -DBAZ=3"
+
+    # -------------------------------------------------------------------------
+    TEST "Base case"
+
+    $UNCACHED_COMPILE $cpp_flag -c -o reference_test1.o test1.c
+
+    $CCACHE_COMPILE $cpp_flag -c test1.c
+    expect_stat 'cache hit (direct)' 0
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 1
+    expect_equal_object_files reference_test1.o test1.o
+
+    unset CCACHE_NODIRECT
+
+    $CCACHE_COMPILE $cpp_flag -c test1.c
+    expect_stat 'cache hit (direct)' 0
+    expect_stat 'cache hit (preprocessed)' 1
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 2
+    expect_equal_object_files reference_test1.o test1.o
+
+    $CCACHE_COMPILE $cpp_flag -c test1.c
+    expect_stat 'cache hit (direct)' 1
+    expect_stat 'cache hit (preprocessed)' 1
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 2
+    expect_equal_object_files reference_test1.o test1.o
+}