]> git.notmuchmail.org Git - notmuch/commitdiff
test: add support for compiling and running C snippets
authorDavid Bremner <david@tethera.net>
Sat, 14 Mar 2015 08:02:03 +0000 (09:02 +0100)
committerDavid Bremner <david@tethera.net>
Sat, 28 Mar 2015 23:33:56 +0000 (00:33 +0100)
This is to limit the copy-pasta involved in running C tests. I decided
to keep things simple and not try to provide an actual C skeleton.

The setting of LD_LIBRARY_PATH is to force using the built libnotmuch
rather than any potential system one.

test/README
test/test-lib.sh

index 81a1c82dcdbdb9487cdbc701f7db5aa6bd9c43f0..daf416002ae16274757e06649647563cccd79caf 100644 (file)
@@ -84,6 +84,11 @@ the tests in one of the following ways.
        TEST_EMACS=my-special-emacs TEST_EMACSCLIENT=my-emacsclient ./emacs
        make test TEST_EMACS=my-special-emacs TEST_EMACSCLIENT=my-emacsclient
 
+Some tests may require a c compiler. You can choose the name and flags similarly
+to with emacs, e.g.
+
+     make test TEST_CC=gcc TEST_CFLAGS="-g -O2"
+
 Quiet Execution
 ---------------
 
index 133fbe4025143ffebf68ddaab47ff582a275dafe..486d1c430adbd714f1d08297612c390b4853e3f3 100644 (file)
@@ -73,6 +73,8 @@ if [[ ( -n "$TEST_EMACS" && -z "$TEST_EMACSCLIENT" ) || \
 fi
 TEST_EMACS=${TEST_EMACS:-${EMACS:-emacs}}
 TEST_EMACSCLIENT=${TEST_EMACSCLIENT:-emacsclient}
+TEST_CC=${TEST_CC:-cc}
+TEST_CFLAGS=${TEST_CFLAGS:-"-g -O0"}
 
 # Protect ourselves from common misconfiguration to export
 # CDPATH into the environment
@@ -1161,6 +1163,19 @@ test_python() {
                | $cmd -
 }
 
+test_C () {
+    exec_file="test${test_count}"
+    test_file="${exec_file}.c"
+    cat > ${test_file}
+    export LD_LIBRARY_PATH=${TEST_DIRECTORY}/../lib
+    ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY}/../lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc
+    echo "== stdout ==" > OUTPUT.stdout
+    echo "== stderr ==" > OUTPUT.stderr
+    ./${exec_file} "$@" 1>>OUTPUT.stdout 2>>OUTPUT.stderr
+    sed "s,${PWD},CWD,g"  OUTPUT.stdout OUTPUT.stderr > OUTPUT
+}
+
+
 # Creates a script that counts how much time it is executed and calls
 # notmuch.  $notmuch_counter_command is set to the path to the
 # generated script.  Use notmuch_counter_value() function to get the