From 25cd65fa6db552955fcac4dbb5ed9d6b743dc613 Mon Sep 17 00:00:00 2001 From: Bill Hart Date: Sat, 23 Mar 2013 15:24:35 -0600 Subject: [PATCH] Changes to reinitialize global data. Adding tests that directly call the cxxtest.cxxtestgen.main() function. --- python/cxxtest/cxx_parser.py | 18 ++++++++++ python/cxxtest/cxxtest_fog.py | 3 -- python/cxxtest/cxxtest_parser.py | 14 +++++--- python/cxxtest/cxxtestgen.py | 21 ++++++----- python/python3/cxxtest/cxx_parser.py | 18 ++++++++++ python/python3/cxxtest/cxxtest_fog.py | 3 -- python/python3/cxxtest/cxxtest_parser.py | 14 +++++--- python/python3/cxxtest/cxxtestgen.py | 21 ++++++----- test/test_cxxtest.py | 45 +++++++++++++++--------- 9 files changed, 111 insertions(+), 46 deletions(-) diff --git a/python/cxxtest/cxx_parser.py b/python/cxxtest/cxx_parser.py index 616dcda..c78bfcb 100644 --- a/python/cxxtest/cxx_parser.py +++ b/python/cxxtest/cxx_parser.py @@ -58,6 +58,7 @@ except ImportError: from ordereddict import OrderedDict +# global data lexer = None scope_lineno = 0 identifier_lineno = {} @@ -65,6 +66,7 @@ _parsedata=None noExceptionLogic = True + def ply_init(data): global _parsedata _parsedata=data @@ -2100,6 +2102,22 @@ def p_error(p): # The function that performs the parsing # def parse_cpp(data=None, filename=None, debug=0, optimize=0, verbose=False, func_filter=None): + # + # Reset global data + # + global lexer + lexer = None + global scope_lineno + scope_lineno = 0 + global indentifier_lineno + identifier_lineno = {} + global _parse_info + _parse_info=None + global _parsedata + _parsedata=None + global noExceptionLogic + noExceptionLogic = True + # if debug > 0: print "Debugging parse_cpp!" # diff --git a/python/cxxtest/cxxtest_fog.py b/python/cxxtest/cxxtest_fog.py index 12a4ff3..a157b68 100644 --- a/python/cxxtest/cxxtest_fog.py +++ b/python/cxxtest/cxxtest_fog.py @@ -16,9 +16,6 @@ import sys import re -#from os.path import abspath, dirname -#sys.path.insert(0, dirname(dirname(abspath(__file__)))) -#sys.path.insert(0, dirname(dirname(abspath(__file__)))+"/cxx_parse") from cxxtest_misc import abort import cxx_parser import re diff --git a/python/cxxtest/cxxtest_parser.py b/python/cxxtest/cxxtest_parser.py index 1416ddc..daa5596 100644 --- a/python/cxxtest/cxxtest_parser.py +++ b/python/cxxtest/cxxtest_parser.py @@ -11,9 +11,6 @@ import codecs import re -#import sys -#import getopt -#import glob from cxxtest.cxxtest_misc import abort # Global variables @@ -24,11 +21,20 @@ def scanInputFiles(files, _options): '''Scan all input files for test suites''' + # + # Reset global data + # global options options=_options + global suites + suites = [] + global suite + suite = None + global inBlock + inBlock = 0 + # for file in files: scanInputFile(file) - global suites if len(suites) is 0 and not options.root: abort( 'No tests defined' ) return [options,suites] diff --git a/python/cxxtest/cxxtestgen.py b/python/cxxtest/cxxtestgen.py index a52ae80..b4ab489 100644 --- a/python/cxxtest/cxxtestgen.py +++ b/python/cxxtest/cxxtestgen.py @@ -37,9 +37,9 @@ except ImportError: from cxxtest_misc import relpath +# Global data is initialized by main() options = [] suites = [] - wrotePreamble = 0 wroteWorld = 0 lastIncluded = '' @@ -56,15 +56,20 @@ def main(args=sys.argv): wroteWorld=0 global lastIncluded lastIncluded = '' - global suites + suites = [] global options - files = parseCommandline(args) - if imported_fog and options.fog: - [options,suites] = cxxtest_fog.scanInputFiles( files, options ) - else: - [options,suites] = cxxtest_parser.scanInputFiles( files, options ) - writeOutput() + options = [] + # + try: + files = parseCommandline(args) + if imported_fog and options.fog: + [options,suites] = cxxtest_fog.scanInputFiles( files, options ) + else: + [options,suites] = cxxtest_parser.scanInputFiles( files, options ) + writeOutput() + except SystemExit: + pass def create_parser(asciidoc=False): parser = OptionParser("cxxtestgen [options] [ ...]") diff --git a/python/python3/cxxtest/cxx_parser.py b/python/python3/cxxtest/cxx_parser.py index 0bc3e46..7a65dab 100644 --- a/python/python3/cxxtest/cxx_parser.py +++ b/python/python3/cxxtest/cxx_parser.py @@ -58,6 +58,7 @@ except ImportError: from ordereddict import OrderedDict +# global data lexer = None scope_lineno = 0 identifier_lineno = {} @@ -65,6 +66,7 @@ _parsedata=None noExceptionLogic = True + def ply_init(data): global _parsedata _parsedata=data @@ -2100,6 +2102,22 @@ def p_error(p): # The function that performs the parsing # def parse_cpp(data=None, filename=None, debug=0, optimize=0, verbose=False, func_filter=None): + # + # Reset global data + # + global lexer + lexer = None + global scope_lineno + scope_lineno = 0 + global indentifier_lineno + identifier_lineno = {} + global _parse_info + _parse_info=None + global _parsedata + _parsedata=None + global noExceptionLogic + noExceptionLogic = True + # if debug > 0: print("Debugging parse_cpp!") # diff --git a/python/python3/cxxtest/cxxtest_fog.py b/python/python3/cxxtest/cxxtest_fog.py index e960fdd..45dc940 100644 --- a/python/python3/cxxtest/cxxtest_fog.py +++ b/python/python3/cxxtest/cxxtest_fog.py @@ -16,9 +16,6 @@ import sys import re -#from os.path import abspath, dirname -#sys.path.insert(0, dirname(dirname(abspath(__file__)))) -#sys.path.insert(0, dirname(dirname(abspath(__file__)))+"/cxx_parse") from .cxxtest_misc import abort from . import cxx_parser import re diff --git a/python/python3/cxxtest/cxxtest_parser.py b/python/python3/cxxtest/cxxtest_parser.py index fc14d4f..931df24 100644 --- a/python/python3/cxxtest/cxxtest_parser.py +++ b/python/python3/cxxtest/cxxtest_parser.py @@ -11,9 +11,6 @@ import codecs import re -#import sys -#import getopt -#import glob from cxxtest.cxxtest_misc import abort # Global variables @@ -24,11 +21,20 @@ def scanInputFiles(files, _options): '''Scan all input files for test suites''' + # + # Reset global data + # global options options=_options + global suites + suites = [] + global suite + suite = None + global inBlock + inBlock = 0 + # for file in files: scanInputFile(file) - global suites if len(suites) is 0 and not options.root: abort( 'No tests defined' ) return [options,suites] diff --git a/python/python3/cxxtest/cxxtestgen.py b/python/python3/cxxtest/cxxtestgen.py index 69a065d..1d5abf2 100644 --- a/python/python3/cxxtest/cxxtestgen.py +++ b/python/python3/cxxtest/cxxtestgen.py @@ -37,9 +37,9 @@ except ImportError: from .cxxtest_misc import relpath +# Global data is initialized by main() options = [] suites = [] - wrotePreamble = 0 wroteWorld = 0 lastIncluded = '' @@ -56,15 +56,20 @@ def main(args=sys.argv): wroteWorld=0 global lastIncluded lastIncluded = '' - global suites + suites = [] global options - files = parseCommandline(args) - if imported_fog and options.fog: - [options,suites] = cxxtest_fog.scanInputFiles( files, options ) - else: - [options,suites] = cxxtest_parser.scanInputFiles( files, options ) - writeOutput() + options = [] + # + try: + files = parseCommandline(args) + if imported_fog and options.fog: + [options,suites] = cxxtest_fog.scanInputFiles( files, options ) + else: + [options,suites] = cxxtest_parser.scanInputFiles( files, options ) + writeOutput() + except SystemExit: + pass def create_parser(asciidoc=False): parser = OptionParser("cxxtestgen [options] [ ...]") diff --git a/test/test_cxxtest.py b/test/test_cxxtest.py index 8204131..a2c7ff1 100644 --- a/test/test_cxxtest.py +++ b/test/test_cxxtest.py @@ -24,6 +24,12 @@ ply_available=True except: ply_available=False +try: + import cxxtest + cxxtest_available=True + import cxxtest.cxxtestgen +except: + cxxtest_available=False currdir = os.path.dirname(os.path.abspath(__file__))+os.sep sampledir = os.path.dirname(os.path.dirname(currdir))+'/sample'+os.sep @@ -211,7 +217,6 @@ def check_if_supported(self, filename, msg): log=currdir+'check'+'_build.log' cmd = join_commands("cd %s" % currdir, "%s %s %s %s. %s%s../ %s > %s 2>&1" % (self.compiler, self.exe_option, target, self.include_option, self.include_option, currdir, filename, log)) - ##print cmd status = subprocess.call(cmd, shell=True) os.remove(log) if status != 0 or not os.path.exists(target): @@ -231,26 +236,30 @@ def init(self, prefix): def check_root(self, prefix='', output=None): self.init(prefix) args = "--have-eh --abort-on-fail --root --error-printer" - cmd = join_commands("cd %s" % currdir, + if cxxtest_available: + os.chdir(currdir) + cxxtest.cxxtestgen.main(['cxxtestgen', self.fog, '-o', self.py_cpp]+re.split('[ ]+',args)) + else: + cmd = join_commands("cd %s" % currdir, "%s %s../bin/cxxtestgen %s -o %s %s > %s 2>&1" % (sys.executable, currdir, self.fog, self.py_cpp, args, self.py_out)) - #print self.fog, "CMD", cmd - status = subprocess.call(cmd, shell=True) - self.assertEqual(status, 0, 'Error executing cxxtestgen') + status = subprocess.call(cmd, shell=True) + self.assertEqual(status, 0, 'Error executing cxxtestgen') # files = [self.py_cpp] for i in [1,2]: args = "--have-eh --abort-on-fail --part Part%s.h" % str(i) file = currdir+self.prefix+'_py%s.cpp' % str(i) files.append(file) - cmd = join_commands("cd %s" % currdir, + if cxxtest_available: + cxxtest.cxxtestgen.main(['cxxtestgen', self.fog, '-o', file]+re.split('[ ]+',args)) + else: + cmd = join_commands("cd %s" % currdir, "%s %s../bin/cxxtestgen %s -o %s %s > %s 2>&1" % (sys.executable, currdir, self.fog, file, args, self.py_out)) - ##print cmd - status = subprocess.call(cmd, shell=True) - self.assertEqual(status, 0, 'Error executing cxxtestgen') + status = subprocess.call(cmd, shell=True) + self.assertEqual(status, 0, 'Error executing cxxtestgen') # cmd = join_commands("cd %s" % currdir, "%s %s %s %s. %s%s../ %s > %s 2>&1" % (self.compiler, self.exe_option, self.build_target, self.include_option, self.include_option, currdir, ' '.join(files), self.build_log)) - ##print cmd status = subprocess.call(cmd, shell=True) for file in files: if os.path.exists(file): @@ -275,17 +284,23 @@ def compile(self, prefix='', args=None, compile='', output=None, main=None, fail """Run cxxtestgen and compile the code that is generated""" self.init(prefix) # - cmd = join_commands("cd %s" % currdir, + if cxxtest_available: + try: + status = cxxtest.cxxtestgen.main(['cxxtestgen', self.fog, '-o', self.py_cpp]+re.split('[ ]+',args)) + except: + status = 1 + else: + cmd = join_commands("cd %s" % currdir, "%s %s../bin/cxxtestgen %s -o %s %s > %s 2>&1" % (sys.executable, currdir, self.fog, self.py_cpp, args, self.py_out)) - #print ("HERE "+cmd) - status = subprocess.call(cmd, shell=True) + status = subprocess.call(cmd, shell=True) if failGen: if status == 0: self.fail('Expected cxxtestgen to fail.') else: self.passed=True return - self.assertEqual(status, 0, 'Error executing command: '+cmd) + if not cxxtest_available: + self.assertEqual(status, 0, 'Error executing command: '+cmd) # if not main is None: # Compile with main @@ -295,7 +310,6 @@ def compile(self, prefix='', args=None, compile='', output=None, main=None, fail # Compile without main cmd = join_commands("cd %s" % currdir, "%s %s %s %s. %s%s../ %s %s > %s 2>&1" % (self.compiler, self.exe_option, self.build_target, self.include_option, self.include_option, currdir, compile, self.py_cpp, self.build_log)) - #print("HERE "+cmd) status = subprocess.call(cmd, shell=True) if failBuild: if status == 0: @@ -313,7 +327,6 @@ def compile(self, prefix='', args=None, compile='', output=None, main=None, fail else: cmd = run % (self.valgrind, self.build_target, self.px_pre) status = subprocess.call(cmd, shell=True) - #print "HERE-status",status OUTPUT = open(self.px_pre,'a') OUTPUT.write('Error level = '+str(status)+'\n') OUTPUT.close()