From 33b3dfcfe90291632ed2f28e0a25cf0bc48ee6c4 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 6 May 2014 13:22:48 +0100 Subject: tests: Move templates out of wrapper-compiler-errors into new files This makes the tests a little less hard-coded. --- tests/Makefile.am | 9 +++++++++ tests/generic.head.c | 7 +++++++ tests/generic.tail.c | 1 + tests/gvariant-builder.c | 2 ++ tests/gvariant-get-child.c | 2 ++ tests/gvariant-get.c | 2 ++ tests/gvariant-iter.c | 2 ++ tests/gvariant-lookup.c | 2 ++ tests/gvariant-new.c | 2 ++ tests/gvariant.head.c | 9 +++++++++ tests/gvariant.tail.c | 4 ++++ tests/nonnull.c | 2 ++ tests/wrapper-compiler-errors | 43 ++++++++++++++++++++----------------------- 13 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 tests/generic.head.c create mode 100644 tests/generic.tail.c create mode 100644 tests/gvariant.head.c create mode 100644 tests/gvariant.tail.c (limited to 'tests') 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 + +#include + +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 + +#include + +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 - -#include - -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)) -- cgit v1.2.3