summaryrefslogtreecommitdiff
path: root/tests/wrapper-compiler-errors
diff options
context:
space:
mode:
Diffstat (limited to 'tests/wrapper-compiler-errors')
-rwxr-xr-xtests/wrapper-compiler-errors43
1 files changed, 20 insertions, 23 deletions
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))