summaryrefslogtreecommitdiff
path: root/tests/warn
diff options
context:
space:
mode:
authorJohan Dahlin <johan@gnome.org>2010-09-02 16:59:48 -0300
committerJohan Dahlin <johan@gnome.org>2010-09-02 17:19:03 -0300
commit4da9654e44eff6eb7c22510d89a3b00e969a16ab (patch)
tree3b747cca74c24d847d66bc3de5b2e1cca9caf64b /tests/warn
parent64fe43160220f2145e8ce903772251f335e8ca2a (diff)
downloadgobject-introspection-4da9654e44eff6eb7c22510d89a3b00e969a16ab.tar.gz
[tests] Rework tester to be executed once per test
Instead of running all tests in the same instance
Diffstat (limited to 'tests/warn')
-rw-r--r--tests/warn/Makefile.am6
-rw-r--r--tests/warn/warningtester.py54
2 files changed, 34 insertions, 26 deletions
diff --git a/tests/warn/Makefile.am b/tests/warn/Makefile.am
index a1e274d3..aefc7a70 100644
--- a/tests/warn/Makefile.am
+++ b/tests/warn/Makefile.am
@@ -1,10 +1,10 @@
include $(top_srcdir)/common.mk
-warning_tests = \
+TESTS = \
return-gobject.h \
unresolved-type.h
EXTRA_DIST = warningtester.py common.h $(warning_tests)
-check-local:
- @PYTHONPATH=$(top_builddir):$(top_srcdir) $(PYTHON) $(srcdir)/warningtester.py $(warning_tests)
+TESTS_ENVIRONMENT = PYTHONPATH=$(top_builddir):$(top_srcdir) $(PYTHON) $(srcdir)/warningtester.py
+
diff --git a/tests/warn/warningtester.py b/tests/warn/warningtester.py
index 66c11a68..757b1d52 100644
--- a/tests/warn/warningtester.py
+++ b/tests/warn/warningtester.py
@@ -39,15 +39,29 @@ def _diff(orig, new, short):
except StopIteration:
pass
else:
- print repr(orig), repr(new)
print 'ERROR: while comparing %s:' % (short, )
for line in list(lines)[2:]:
- print '%s: %s' % (short, line[:-1])
+ print '%s: %r' % (short, line[:-1])
return diff
+def _extract_expected(filename):
+ fd = open(filename)
+ data = fd.read()
+
+ retval = []
+ while data:
+ pos = data.find("EXPECT:")
+ data = data[pos+7:]
+ end = data.find('\n')
+ if end == -1:
+ break
+ retval.append(data[:end])
+ data = data[end:]
+ return sorted(retval)
+
def check(args):
- filenames = args
+ filename = args[0]
output = StringIO()
namespace = Namespace("Test", "1.0")
@@ -66,8 +80,8 @@ def check(args):
ss.set_cpp_options(options.cpp_includes,
options.cpp_defines,
options.cpp_undefines)
- ss.parse_files(filenames)
- ss.parse_macros(filenames)
+ ss.parse_files([filename])
+ ss.parse_macros([filename])
transformer.parse(ss.get_symbols())
ap = AnnotationParser()
@@ -79,26 +93,20 @@ def check(args):
final = IntrospectablePass(transformer)
final.validate()
- warnings = output.getvalue()[:-1].split('\n')
+ raw = output.getvalue()
+ if raw.endswith('\n'):
+ raw = raw[:-1]
+ warnings = raw.split('\n')
failed_tests = 0
- for warning in warnings:
- filename, actual = warning.split(":", 1)
- fd = open(filename)
- data = fd.read()
- pos = data.find("EXPECT:")
- if pos == -1:
- raise SystemExit("%s: unexpected warning %s" % (filename, warning,))
- expected = data[pos+7:]
- while expected.endswith('\n'):
- expected = expected[:-1]
+ expected_warnings = _extract_expected(filename)
+ if len(expected_warnings) != len(warnings):
+ raise SystemExit(
+ "ERROR: expected %d warnings, but got %d: %s\n",
+ len(expected_warnings), len(warnings), warnings.join('\n'))
+ for warning, expected in zip(warnings, expected_warnings):
+ actual = warning.split(":", 1)[1]
if _diff(actual, expected, filename):
- failed_tests += 1
-
- print 'PASS: %d of %d tested passed' % (len(filenames) - failed_tests,
- len(filenames))
-
- if failed_tests:
- raise SystemExit("ERROR: some tests failed")
+ raise SystemExit("ERROR: tests %r failed" % (filename, ))
sys.exit(check(sys.argv[1:]))