]> git.notmuchmail.org Git - notmuch/commitdiff
tests: add a test for symbol hiding side effects
authorDavid Bremner <bremner@debian.org>
Wed, 22 Jun 2011 11:58:01 +0000 (08:58 -0300)
committerDavid Bremner <bremner@debian.org>
Thu, 23 Jun 2011 10:05:25 +0000 (07:05 -0300)
The worry here is that a binary linking with libnotmuch might lose
access to Xapian::Error symbols because libnotmuch hides them.

We are careful here to create ./fakedb/.notmuch in order to trigger a
Xapian exception, and not just a missing file check.

Thanks to jrollins and amddragon for suggestions.
(cherry picked from commit 66f37f5f6864a988f94ddb893e3a176af57f6c8e)

test/basic
test/notmuch-test
test/symbol-hiding [new file with mode: 0755]
test/symbol-test.cc [new file with mode: 0644]

index 808c96876238f1d26d9afe7dbfb9029bb5c8b1b1..d6e8c100d083b91b6719930344e2c6c7547c3051 100755 (executable)
@@ -56,7 +56,7 @@ tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)
 available=$(ls -1 ../ | \
     sed -r -e "/^(aggregate-results.sh|Makefile|Makefile.local|notmuch-test)/d" \
           -e "/^(README|test-lib.sh|test-lib.el|test-results|tmp.*|valgrind|corpus*)/d" \
 available=$(ls -1 ../ | \
     sed -r -e "/^(aggregate-results.sh|Makefile|Makefile.local|notmuch-test)/d" \
           -e "/^(README|test-lib.sh|test-lib.el|test-results|tmp.*|valgrind|corpus*)/d" \
-          -e "/^(emacs.expected-output|smtp-dummy|smtp-dummy.c|test-verbose)/d" \
+          -e "/^(emacs.expected-output|smtp-dummy|smtp-dummy.c|test-verbose|symbol-test.cc)/d" \
           -e "/^(test.expected-output|.*~)/d" \
           -e "/^(gnupg-secret-key.asc)/d" \
           -e "/^(gnupg-secret-key.NOTE)/d" \
           -e "/^(test.expected-output|.*~)/d" \
           -e "/^(gnupg-secret-key.asc)/d" \
           -e "/^(gnupg-secret-key.NOTE)/d" \
index 83f284d928808c86920ecf32dafd77c0b108336b..fe85c6a4032f9fbd2e88ad5a2bf9afce067e8679 100755 (executable)
@@ -40,6 +40,7 @@ TESTS="
   emacs-large-search-buffer
   maildir-sync
   crypto
   emacs-large-search-buffer
   maildir-sync
   crypto
+  symbol-hiding
 "
 TESTS=${NOTMUCH_TESTS:=$TESTS}
 
 "
 TESTS=${NOTMUCH_TESTS:=$TESTS}
 
diff --git a/test/symbol-hiding b/test/symbol-hiding
new file mode 100755 (executable)
index 0000000..bb55524
--- /dev/null
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2011 David Bremner
+#
+
+# This test tests whether hiding Xapian::Error symbols in libnotmuch
+# also hides them for other users of libxapian. This is motivated by
+# the discussion in http://gcc.gnu.org/wiki/Visibility'
+
+test_description='exception symbol hiding'
+
+. ./test-lib.sh
+
+run_test(){
+    result=$(LD_LIBRARY_PATH=../../lib ./symbol-test 2>&1)
+}
+
+output="A Xapian exception occurred opening database: Couldn't stat 'fakedb/.notmuch/xapian'
+caught No chert database found at path \`./nonexistant'"
+
+g++ -o symbol-test -I../../lib ../symbol-test.cc -L../../lib -lnotmuch -lxapian
+mkdir -p fakedb/.notmuch
+test_expect_success 'running test' run_test
+test_begin_subtest 'checking output'
+test_expect_equal "$result" "$output" 
+test_done
diff --git a/test/symbol-test.cc b/test/symbol-test.cc
new file mode 100644 (file)
index 0000000..1de06ea
--- /dev/null
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <xapian.h>
+#include <notmuch.h>
+main (int argc, char **argv){
+
+    notmuch_database_t *notmuch
+      = notmuch_database_open ("fakedb",
+                                    NOTMUCH_DATABASE_MODE_READ_ONLY);
+
+  try{
+    (void)new Xapian::WritableDatabase ("./nonexistant",                                       Xapian::DB_OPEN);
+  } catch (const Xapian::Error &error) {
+    printf("caught %s\n",error.get_msg().c_str());
+    return 0;
+  }
+  return 1;
+}