Skip to content

Commit

Permalink
Use relpath first, and then abspath.
Browse files Browse the repository at this point in the history
This accounts for error reported w.r.t. the fix for ticket CxxTest#56.
  • Loading branch information
whart222 authored and Oliviers-OSS committed Aug 5, 2015
1 parent 59cffaf commit 49090ef
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 10 deletions.
21 changes: 17 additions & 4 deletions python/cxxtest/cxxtestgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,23 @@ def isDynamic(suite):
def writeInclude(output, file):
'''Add #include "file" statement'''
global lastIncluded
file = os.path.abspath(file)
if file == lastIncluded: return
output.writelines( [ '#include "', file, '"\n\n' ] )
lastIncluded = file
if options.outputFileName:
dirname = os.path.split(options.outputFileName)[0]
tfile = relpath(file, dirname)
if os.path.exists(tfile):
if tfile == lastIncluded: return
output.writelines( [ '#include "', tfile, '"\n\n' ] )
lastIncluded = tfile
return
#
# Use an absolute path if the relative path failed
#
tfile = os.path.abspath(file)
if os.path.exists(tfile):
if tfile == lastIncluded: return
output.writelines( [ '#include "', tfile, '"\n\n' ] )
lastIncluded = tfile
return

def generateSuite( output, suite ):
'''Write a suite declared with CXXTEST_SUITE()'''
Expand Down
21 changes: 17 additions & 4 deletions python/python3/cxxtest/cxxtestgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,23 @@ def isDynamic(suite):
def writeInclude(output, file):
'''Add #include "file" statement'''
global lastIncluded
file = os.path.abspath(file)
if file == lastIncluded: return
output.writelines( [ '#include "', file, '"\n\n' ] )
lastIncluded = file
if options.outputFileName:
dirname = os.path.split(options.outputFileName)[0]
tfile = relpath(file, dirname)
if os.path.exists(tfile):
if tfile == lastIncluded: return
output.writelines( [ '#include "', tfile, '"\n\n' ] )
lastIncluded = tfile
return
#
# Use an absolute path if the relative path failed
#
tfile = os.path.abspath(file)
if os.path.exists(tfile):
if tfile == lastIncluded: return
output.writelines( [ '#include "', tfile, '"\n\n' ] )
lastIncluded = tfile
return

def generateSuite( output, suite ):
'''Write a suite declared with CXXTEST_SUITE()'''
Expand Down
45 changes: 43 additions & 2 deletions test/test_cxxtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# the U.S. Government retains certain rights in this software.
#-------------------------------------------------------------------------

import shutil
import time
import sys
import os
Expand Down Expand Up @@ -298,9 +299,10 @@ def check_root(self, prefix='', output=None):
#
self.passed=True

def compile(self, prefix='', args=None, compile='', output=None, main=None, failGen=False, run=None, logfile=None, failBuild=False):
def compile(self, prefix='', args=None, compile='', output=None, main=None, failGen=False, run=None, logfile=None, failBuild=False, init=True):
"""Run cxxtestgen and compile the code that is generated"""
self.init(prefix)
if init:
self.init(prefix)
#
if self.cxxtest_import:
try:
Expand Down Expand Up @@ -698,6 +700,45 @@ def test_bad1(self):
else:
self.compile(prefix='bad1', args="--error-printer BadTest.h", output='bad.out')

#
# Testing path manipulation
#

def test_normal_sympath(self):
"""Normal Behavior - symbolic path"""
_files = " ".join(["LessThanEquals.h","Relation.h","DefaultTraits.h","DoubleCall.h","SameData.h","SameFiles.h","Tsm.h","TraitsTest.h","MockTest.h","SameZero.h"])
prefix = 'normal_sympath'
self.init(prefix=prefix)
try:
os.remove('test_sympath')
except:
pass
try:
shutil.rmtree('../test_sympath')
except:
pass
os.mkdir('../test_sympath')
os.symlink('../test_sympath', 'test_sympath')
self.py_cpp = 'test_sympath/'+prefix+'_py.cpp'
self.compile(prefix=prefix, init=False, args="--error-printer "+_files, output="normal.out")
os.remove('test_sympath')
shutil.rmtree('../test_sympath')

def test_normal_relpath(self):
"""Normal Behavior - relative path"""
_files = " ".join(["LessThanEquals.h","Relation.h","DefaultTraits.h","DoubleCall.h","SameData.h","SameFiles.h","Tsm.h","TraitsTest.h","MockTest.h","SameZero.h"])
prefix = 'normal_relative'
self.init(prefix=prefix)
try:
shutil.rmtree('../test_relpath')
except:
pass
os.mkdir('../test_relpath')
self.py_cpp = '../test_relpath/'+prefix+'_py.cpp'
self.compile(prefix=prefix, init=False, args="--error-printer "+_files, output="normal.out")
shutil.rmtree('../test_relpath')



class TestCpp(BaseTestCase, unittest.TestCase):

Expand Down

0 comments on commit 49090ef

Please sign in to comment.