Skip to content

Commit

Permalink
Changes to reinitialize global data.
Browse files Browse the repository at this point in the history
Adding tests that directly call the cxxtest.cxxtestgen.main()
function.
  • Loading branch information
whart222 committed Mar 23, 2013
1 parent 2434226 commit 25cd65f
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 46 deletions.
18 changes: 18 additions & 0 deletions python/cxxtest/cxx_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@
except ImportError:
from ordereddict import OrderedDict

# global data
lexer = None
scope_lineno = 0
identifier_lineno = {}
_parse_info=None
_parsedata=None
noExceptionLogic = True


def ply_init(data):
global _parsedata
_parsedata=data
Expand Down Expand Up @@ -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!"
#
Expand Down
3 changes: 0 additions & 3 deletions python/cxxtest/cxxtest_fog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions python/cxxtest/cxxtest_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

import codecs
import re
#import sys
#import getopt
#import glob
from cxxtest.cxxtest_misc import abort

# Global variables
Expand All @@ -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]
Expand Down
21 changes: 13 additions & 8 deletions python/cxxtest/cxxtestgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
except ImportError:
from cxxtest_misc import relpath

# Global data is initialized by main()
options = []
suites = []

wrotePreamble = 0
wroteWorld = 0
lastIncluded = ''
Expand All @@ -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] [<filename> ...]")
Expand Down
18 changes: 18 additions & 0 deletions python/python3/cxxtest/cxx_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@
except ImportError:
from ordereddict import OrderedDict

# global data
lexer = None
scope_lineno = 0
identifier_lineno = {}
_parse_info=None
_parsedata=None
noExceptionLogic = True


def ply_init(data):
global _parsedata
_parsedata=data
Expand Down Expand Up @@ -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!")
#
Expand Down
3 changes: 0 additions & 3 deletions python/python3/cxxtest/cxxtest_fog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions python/python3/cxxtest/cxxtest_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

import codecs
import re
#import sys
#import getopt
#import glob
from cxxtest.cxxtest_misc import abort

# Global variables
Expand All @@ -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]
Expand Down
21 changes: 13 additions & 8 deletions python/python3/cxxtest/cxxtestgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
except ImportError:
from .cxxtest_misc import relpath

# Global data is initialized by main()
options = []
suites = []

wrotePreamble = 0
wroteWorld = 0
lastIncluded = ''
Expand All @@ -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] [<filename> ...]")
Expand Down
45 changes: 29 additions & 16 deletions test/test_cxxtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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()
Expand Down

0 comments on commit 25cd65f

Please sign in to comment.