summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2014-05-06 13:22:48 +0100
committerPhilip Withnall <philip.withnall@collabora.co.uk>2014-05-06 13:22:48 +0100
commit33b3dfcfe90291632ed2f28e0a25cf0bc48ee6c4 (patch)
tree0d7fb3466bf5e8d26b8a9835530ec1c7223fcf04
parent0293d68ce2cdfcdad02d27943af849cc7e182333 (diff)
tests: Move templates out of wrapper-compiler-errors into new files
This makes the tests a little less hard-coded.
-rw-r--r--tests/Makefile.am9
-rw-r--r--tests/generic.head.c7
-rw-r--r--tests/generic.tail.c1
-rw-r--r--tests/gvariant-builder.c2
-rw-r--r--tests/gvariant-get-child.c2
-rw-r--r--tests/gvariant-get.c2
-rw-r--r--tests/gvariant-iter.c2
-rw-r--r--tests/gvariant-lookup.c2
-rw-r--r--tests/gvariant-new.c2
-rw-r--r--tests/gvariant.head.c9
-rw-r--r--tests/gvariant.tail.c4
-rw-r--r--tests/nonnull.c2
-rwxr-xr-xtests/wrapper-compiler-errors43
13 files changed, 64 insertions, 23 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index eb23d6c..943afdc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,4 +15,13 @@ TESTS = \
nonnull.c \
$(NULL)
+templates = \
+ generic.head.c \
+ generic.tail.c \
+ gvariant.head.c \
+ gvariant.tail.c \
+ $(NULL)
+
+EXTRA_DIST = $(templates)
+
-include $(top_srcdir)/git.mk
diff --git a/tests/generic.head.c b/tests/generic.head.c
new file mode 100644
index 0000000..a197905
--- /dev/null
+++ b/tests/generic.head.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+#include <glib.h>
+
+int
+main (void)
+{
diff --git a/tests/generic.tail.c b/tests/generic.tail.c
new file mode 100644
index 0000000..5c34318
--- /dev/null
+++ b/tests/generic.tail.c
@@ -0,0 +1 @@
+}
diff --git a/tests/gvariant-builder.c b/tests/gvariant-builder.c
index 6cebb70..3ed447f 100644
--- a/tests/gvariant-builder.c
+++ b/tests/gvariant-builder.c
@@ -1,3 +1,5 @@
+/* Template: gvariant */
+
/*
* No error
*/
diff --git a/tests/gvariant-get-child.c b/tests/gvariant-get-child.c
index 08c2bce..ed73d62 100644
--- a/tests/gvariant-get-child.c
+++ b/tests/gvariant-get-child.c
@@ -1,3 +1,5 @@
+/* Template: gvariant */
+
/*
* No error
*/
diff --git a/tests/gvariant-get.c b/tests/gvariant-get.c
index f4e0fa4..cfa2700 100644
--- a/tests/gvariant-get.c
+++ b/tests/gvariant-get.c
@@ -1,3 +1,5 @@
+/* Template: gvariant */
+
/*
* No error
*/
diff --git a/tests/gvariant-iter.c b/tests/gvariant-iter.c
index 03e0117..cebe522 100644
--- a/tests/gvariant-iter.c
+++ b/tests/gvariant-iter.c
@@ -1,3 +1,5 @@
+/* Template: gvariant */
+
/*
* No error
*/
diff --git a/tests/gvariant-lookup.c b/tests/gvariant-lookup.c
index e6d91af..fde9418 100644
--- a/tests/gvariant-lookup.c
+++ b/tests/gvariant-lookup.c
@@ -1,3 +1,5 @@
+/* Template: gvariant */
+
/*
* No error
*/
diff --git a/tests/gvariant-new.c b/tests/gvariant-new.c
index 451a610..45f1f13 100644
--- a/tests/gvariant-new.c
+++ b/tests/gvariant-new.c
@@ -1,3 +1,5 @@
+/* Template: gvariant */
+
/*
* Expected a GVariant variadic argument of type ‘char *’ but saw one of type ‘guint’.
* floating_variant = g_variant_new ("(sss)", "hello", my_string, a_little_int_short_and_stout);
diff --git a/tests/gvariant.head.c b/tests/gvariant.head.c
new file mode 100644
index 0000000..200a490
--- /dev/null
+++ b/tests/gvariant.head.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+#include <glib.h>
+
+int
+main (void)
+{
+ GVariant *floating_variant = NULL, *existing_variant;
+ existing_variant = g_variant_new_boolean (FALSE); /* arbitrary */
diff --git a/tests/gvariant.tail.c b/tests/gvariant.tail.c
new file mode 100644
index 0000000..54e9867
--- /dev/null
+++ b/tests/gvariant.tail.c
@@ -0,0 +1,4 @@
+ g_variant_unref (existing_variant);
+ if (floating_variant != NULL)
+ g_variant_unref (floating_variant);
+}
diff --git a/tests/nonnull.c b/tests/nonnull.c
index d795c00..1fcf626 100644
--- a/tests/nonnull.c
+++ b/tests/nonnull.c
@@ -1,3 +1,5 @@
+/* Template: generic */
+
/*
* No error
*/
diff --git a/tests/wrapper-compiler-errors b/tests/wrapper-compiler-errors
index c705038..408ec01 100755
--- a/tests/wrapper-compiler-errors
+++ b/tests/wrapper-compiler-errors
@@ -1,6 +1,8 @@
#!/bin/sh
-# Take an input file which contains one or more sections of the form:
+# Take an input file which contains a header of the form:
+# /* Template: [template name] */
+# followed by a blank line, then one or more sections of the form:
# /*
# [Error message|‘No error’]
# */
@@ -12,7 +14,8 @@
# C-style comments (‘/* … */’), but can contain C++-style ones (‘// …’).
#
# The wrapper script takes each section and wraps the code in a main() function
-# with some standard variables and reference count handling. It then compiles
+# with some standard variables and reference count handling provided by the
+# named template. It then compiles
# the code using Clang with gnome-clang, and checks the compiler output against
# the expected error message. If the expected error message is ‘No error’ it
# asserts there’s no error.
@@ -22,7 +25,6 @@ temp_dir=`mktemp -d`
echo "Reading input from ${input_filename}."
echo "Using temporary directory ${temp_dir}."
-echo ""
test_status=0
@@ -31,11 +33,21 @@ test_status=0
system_includes=`echo | cpp -Wp,-v 2>&1 | grep '^[[:space:]]' | \
sed -e 's/^[[:space:]]*/-isystem/' | tr "\n" ' '`
+# Extract the template name.
+template_name=`head -n 1 "${input_filename}" | \
+ sed -n 's/\/\*[[:space:]]*Template:\(.*\)\*\//\1/p' | \
+ tr -d ' '`
+
+echo "Using template ${template_name}."
+
# Split the input file up into sections, delimiting on ‘/*’ on a line by itself.
+tail -n +3 "${input_filename}" > "${temp_dir}/${input_filename}.tail"
csplit --keep-files --elide-empty-files --silent \
--prefix="${temp_dir}/${input_filename}_" \
--suffix-format='%02d.c' \
- "${input_filename}" '/^\/\*/' '{*}'
+ "${temp_dir}/${input_filename}.tail" '/^\/\*/' '{*}'
+
+echo ""
num=0
while [[ -f `printf "${temp_dir}/${input_filename}_%02d.c" ${num}` ]]; do
@@ -50,25 +62,10 @@ while [[ -f `printf "${temp_dir}/${input_filename}_%02d.c" ${num}` ]]; do
echo " - Outputting to error files ${expected_error_filename} and ${actual_error_filename}."
# Wrap the section’s code with a prefix and suffix.
- (cat << EOF
-#include <stdio.h>
-
-#include <glib.h>
-
-int
-main (void)
-{
- GVariant *floating_variant = NULL, *existing_variant;
- existing_variant = g_variant_new_boolean (FALSE); /* arbitrary */
-EOF
- cat $section_filename
- cat << EOF
- g_variant_unref (existing_variant);
- if (floating_variant != NULL)
- g_variant_unref (floating_variant);
-}
-EOF
-) > $section_filename.tmp
+ (cat "${template_name}.head.c"
+ cat "${section_filename}"
+ cat "${template_name}.tail.c"
+ ) > $section_filename.tmp
mv -f $section_filename.tmp $section_filename
num=$((num + 1))