[Synopsis-changes] Synopsis/Synopsis/tests/qmtest/classes synopsis_database.py,1.3,1.4 synopsis_test.py,1.2,1.3
Stefan Seefeld stefan at synopsis.fresco.orgMon Jan 12 20:31:05 UTC 2004
- Previous message: [Synopsis-changes] Synopsis/Synopsis autogen.sh,1.5,1.6
- Next message: [Synopsis-changes] Synopsis/Synopsis/Synopsis AST.py,1.30,1.31
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Update of /cvs/synopsis/Synopsis/tests/qmtest/classes
In directory frida:/tmp/cvs-serv9911/qmtest/classes
Modified Files:
synopsis_database.py synopsis_test.py
Log Message:
adapt test classes to support C++ API tests
Index: synopsis_database.py
===================================================================
RCS file: /cvs/synopsis/Synopsis/tests/qmtest/classes/synopsis_database.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -p -d -r1.3 -r1.4
--- synopsis_database.py 2 Dec 2003 16:34:30 -0000 1.3
+++ synopsis_database.py 12 Jan 2004 20:31:03 -0000 1.4
@@ -7,16 +7,23 @@
# see the file COPYING for details.
#
-from qm.test import database
-from qm.test.database import TestDescriptor
-from qm.test.database import NoSuchTestError, NoSuchSuiteError
-from qm.test.suite import Suite
+from qm.fields import TextField
+from qm.test import database
+from qm.test.database import TestDescriptor
+from qm.test.database import NoSuchTestError, NoSuchSuiteError
+from qm.test.suite import Suite
import os, string, dircache
class Database(database.Database):
"""The Database stores the synopsis tests."""
+ arguments = [TextField(name="CXX"),
+ TextField(name="CPPFLAGS"),
+ TextField(name="CXXFLAGS"),
+ TextField(name="LDFLAGS"),
+ TextField(name="LIBS")]
+
def GetSuite(self, id):
"""Construct a suite for the given id"""
@@ -41,6 +48,17 @@ class Database(database.Database):
dircache.listdir(path))
suite_ids = []
+ elif id.startswith('Cxx-API'):
+ test_ids = []
+ suite_ids = filter(lambda x: os.path.isdir(os.path.join(path, x)),
+ dircache.listdir(path))
+ if 'src' in suite_ids:
+ test_ids = map(lambda x: os.path.splitext(x)[0],
+ filter(lambda x: x.endswith('.cc'),
+ dircache.listdir(os.path.join(path, 'src'))))
+ suite_ids.remove('src')
+ if 'expected' in suite_ids: suite_ids.remove('expected')
+
else:
test_ids = []
suite_ids = filter(lambda x: os.path.isdir(os.path.join(path, x)),
@@ -48,10 +66,12 @@ class Database(database.Database):
if 'input' in suite_ids:
test_ids = map(lambda x: os.path.splitext(x)[0],
dircache.listdir(os.path.join(path, 'input')))
- if 'CVS' in test_ids: test_ids.remove('CVS')
suite_ids.remove('input')
if 'expected' in suite_ids: suite_ids.remove('expected')
- if 'CVS' in suite_ids: suite_ids.remove('CVS')
+
+ if 'CVS' in test_ids: test_ids.remove('CVS')
+ if 'CVS' in suite_ids: suite_ids.remove('CVS')
+ if 'autom4te.cache' in suite_ids: suite_ids.remove('autom4te.cache')
if id:
test_ids = map(lambda x: string.join([id, x], '.'), test_ids)
@@ -66,6 +86,10 @@ class Database(database.Database):
if id.startswith('Processors.Linker'):
return self.make_linker_test(id)
+
+ elif id.startswith('Cxx-API'):
+ return self.make_api_test(id)
+
else:
return self.make_test(id)
@@ -116,3 +140,21 @@ class Database(database.Database):
parameters['synopsis'] = os.path.join(*components + ['synopsis.py'])
return TestDescriptor(self, id, 'synopsis_test.ProcessorTest', parameters)
+
+ def make_api_test(self, id):
+
+ components = id.split('.')
+ dirname = os.path.join(*components[:-1])
+
+ parameters = {}
+ parameters['CXX'] = self.CXX
+ parameters['CPPFLAGS'] = self.CPPFLAGS
+ parameters['CXXFLAGS'] = self.CXXFLAGS
+ parameters['LDFLAGS'] = self.LDFLAGS
+ parameters['LIBS'] = self.LIBS
+ parameters['src'] = os.path.join(dirname, 'src', components[-1]) + '.cc'
+ parameters['exe'] = os.path.join(dirname, 'bin', components[-1])
+ parameters['expected'] = os.path.join(dirname, 'expected',
+ components[-1] + '.out')
+
+ return TestDescriptor(self, id, 'synopsis_test.APITest', parameters)
Index: synopsis_test.py
===================================================================
RCS file: /cvs/synopsis/Synopsis/tests/qmtest/classes/synopsis_test.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -p -d -r1.2 -r1.3
--- synopsis_test.py 3 Dec 2003 05:43:55 -0000 1.2
+++ synopsis_test.py 12 Jan 2004 20:31:03 -0000 1.3
@@ -16,6 +16,56 @@ import os
import string
import sys
+class APITest(Test):
+ """Compile and run a test to validate the C++ API."""
+
+ arguments = [TextField(name="src", description="The source file."),
+ TextField(name="exe", description="The executable file."),
+ TextField(name="expected", description="The expected output file."),
+ TextField(name="CXX", description="The compiler command."),
+ TextField(name="CPPFLAGS", description="The preprocessor flags."),
+ TextField(name="CXXFLAGS", description="The compiler flags."),
+ TextField(name="LDFLAGS", description="The linker flags."),
+ TextField(name="LIBS", description="The libraries to link with.")]
+
+ def compile(self, context, result):
+ if not os.path.isdir(os.path.dirname(self.exe)):
+ os.makedirs(os.path.dirname(self.exe))
+
+ command = '%s %s %s %s -o %s %s %s'%(self.CXX,
+ self.CPPFLAGS, self.CXXFLAGS,
+ self.LDFLAGS,
+ self.exe, self.src, self.LIBS)
+ compiler = RedirectedExecutable()
+ status = compiler.Run(string.split(command))
+ if os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0:
+ return self.exe
+ else:
+ result.Fail('compilation failed',
+ {'synopsis_test.error': compiler.stderr,
+ 'synopsis_test.command': command})
+ return None
+
+ def Run(self, context, result):
+ exe = self.compile(context, result)
+ if not exe: return
+ test = RedirectedExecutable()
+ status = test.Run([exe])
+ if not os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0:
+ result.Fail('program exit value : %i'%os.WEXITSTATUS(status))
+ if test.stderr: result['orthotest.error'] = test.stderr
+
+ expected = string.join(open(self.expected, 'r').readlines(), '')
+ if expected and not test.stdout:
+ result.Fail('program did not generate output')
+ elif expected and not expected == test.stdout:
+ expected = '\'%s\''%(expected)
+ output = '\'%s\''%(test.stdout)
+ result.Fail('incorrect output',
+ {'synopsis_test.expected': expected,
+ 'synopsis_test.output': output})
+
+
class ProcessorTest(Test):
"""Process an input file with a synopsis script and
compare the output."""
- Previous message: [Synopsis-changes] Synopsis/Synopsis autogen.sh,1.5,1.6
- Next message: [Synopsis-changes] Synopsis/Synopsis/Synopsis AST.py,1.30,1.31
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Synopsis-changes mailing list