Script to test if headers are self-sufficient.
authorEmil Mikulic <emikulic@gmail.com>
Wed, 4 May 2011 15:00:43 +0000 (01:00 +1000)
committerEmil Mikulic <emikulic@gmail.com>
Sat, 28 May 2011 10:10:52 +0000 (20:10 +1000)
release.sh
test_headers.sh [new file with mode: 0755]

index 1f420bd..03ce007 100755 (executable)
@@ -6,6 +6,7 @@
 # This is for developer use only and lives in the repo but
 # shouldn't end up in a tarball.
 #
+# Remember to run "./test_headers.sh *.h"
 # Remember to run "make depend" to update deps in Makefile.in
 #
 
diff --git a/test_headers.sh b/test_headers.sh
new file mode 100755 (executable)
index 0000000..9295408
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/sh
+# copyright (c) 2011 Emil Mikulic.
+#
+# The rule is that every header has to bring in all of its dependencies.
+#
+# This script tests to make sure it's true: for each header file,
+# test-compile a C source file that includes just the header.
+#
+# Also test that it can be included twice without problems.
+#
+src=_test_hdr.c
+obj=_test_hdr.o
+
+if [ $# -eq 0 ]; then
+  echo "usage: $0 *.h" >&2
+  exit 1
+fi
+
+for f in $*; do
+  cat >$src <<EOF
+#include "$f"
+void test_hdr_do_nothing(void) { }
+EOF
+  if gcc -c $src 2>/dev/null; then
+    true
+  else
+    echo "===> FAIL: $f <==="
+    gcc -c $src
+  fi
+
+  cat >$src <<EOF
+#include "$f"
+#include "$f"
+void test_hdr_do_nothing(void) { }
+EOF
+  if gcc -c $src 2>/dev/null; then
+    true
+  else
+    echo "===> FAIL DOUBLE: $f <==="
+    gcc -c $src
+  fi
+done
+
+rm $src $obj