1
# Copyright 2002-2005 Vladimir Prus.
2
# Copyright 2002-2003 Dave Abrahams.
3
# Copyright 2006 Rene Rivera.
4
# Distributed under the Boost Software License, Version 1.0.
5
# (See accompanying file LICENSE_1_0.txt or copy at
6
# http://www.boost.org/LICENSE_1_0.txt)
3
9
from tree import build_tree, trees_difference
23
from StringIO import StringIO
25
annotation_func = None
29
def print_annotation(name, value):
30
"""Writes some named bit of information about test
38
def flush_annotations():
40
for ann in annotations:
41
print_annotation(ann[0], ann[1])
46
def set_defer_annotations(n):
47
global defer_annotations
50
def annotation(name, value):
51
"""Records an annotation about test run."""
52
annotations.append((name, value))
53
if not defer_annotations:
93
150
self.toolset = get_toolset()
94
151
self.pass_toolset = pass_toolset
96
153
prepare_suffix_map(pass_toolset and self.toolset or 'gcc')
100
jam_build_dir = "bin.ntx86"
101
elif os.name == 'posix' and os.__dict__.has_key('uname'):
102
if os.uname()[0].lower().startswith('cygwin'):
103
jam_build_dir = "bin.cygwinx86"
104
if 'TMP' in os.environ and os.environ['TMP'].find('~') != -1:
105
print 'Setting $TMP to /tmp to get around problem with short path names'
106
os.environ['TMP'] = '/tmp'
107
elif os.uname()[0] == 'Linux':
109
if re.match("i.86", cpu):
110
jam_build_dir = "bin.linuxx86";
155
if not '--default-bjam' in sys.argv:
158
jam_build_dir = "bin.ntx86"
159
elif os.name == 'posix' and os.__dict__.has_key('uname'):
160
if os.uname()[0].lower().startswith('cygwin'):
161
jam_build_dir = "bin.cygwinx86"
162
if 'TMP' in os.environ and os.environ['TMP'].find('~') != -1:
163
print 'Setting $TMP to /tmp to get around problem with short path names'
164
os.environ['TMP'] = '/tmp'
165
elif os.uname()[0] == 'Linux':
167
if re.match("i.86", cpu):
168
jam_build_dir = "bin.linuxx86";
170
jam_build_dir = "bin.linux" + os.uname()[4]
171
elif os.uname()[0] == 'SunOS':
172
jam_build_dir = "bin.solaris"
173
elif os.uname()[0] == 'Darwin':
174
jam_build_dir = "bin.macosxppc"
175
elif os.uname()[0] == "AIX":
176
jam_build_dir = "bin.aix"
177
elif os.uname()[0] == "IRIX64":
178
jam_build_dir = "bin.irix"
179
elif os.uname()[0] == "FreeBSD":
180
jam_build_dir = "bin.freebsd"
181
elif os.uname()[0] == "OSF1":
182
jam_build_dir = "bin.osf"
112
jam_build_dir = "bin.linux" + os.uname()[4]
113
elif os.uname()[0] == 'SunOS':
114
jam_build_dir = "bin.solaris"
115
elif os.uname()[0] == 'Darwin':
116
jam_build_dir = "bin.macosxppc"
117
elif os.uname()[0] == "AIX":
118
jam_build_dir = "bin.aix"
119
elif os.uname()[0] == "IRIX64":
120
jam_build_dir = "bin.irix"
121
elif os.uname()[0] == "FreeBSD":
122
jam_build_dir = "bin.freebsd"
123
elif os.uname()[0] == "OSF1":
124
jam_build_dir = "bin.osf"
126
raise "Don't know directory where jam is build for this system: " + os.name + "/" + os.uname()[0]
128
raise "Don't know directory where jam is build for this system: " + os.name
130
if boost_build_path is None:
131
boost_build_path = self.original_workdir
184
raise "Don't know directory where jam is build for this system: " + os.name + "/" + os.uname()[0]
186
raise "Don't know directory where jam is build for this system: " + os.name
188
# Find there jam_src is located.
189
# try for the debug version if it's lying around
191
dirs = [os.path.join('../../../jam/src', jam_build_dir + '.debug'),
192
os.path.join('../../../jam/src', jam_build_dir),
193
os.path.join('../../jam_src', jam_build_dir + '.debug'),
194
os.path.join('../../jam_src', jam_build_dir),
195
os.path.join('../jam_src', jam_build_dir + '.debug'),
196
os.path.join('../jam_src', jam_build_dir),
200
if os.path.exists(d):
204
print "Cannot find built Boost.Jam"
134
207
verbosity = ['-d0', '--quiet']
135
208
if '--verbose' in sys.argv:
136
209
keywords['verbose'] = 1
137
210
verbosity = ['-d+2']
212
if boost_build_path is None:
213
boost_build_path = self.original_workdir
139
215
program_list = []
141
# Find there jam_src is located.
142
# try for the debug version if it's lying around
144
dirs = [os.path.join('../../../jam/src', jam_build_dir + '.debug'),
145
os.path.join('../../../jam/src', jam_build_dir),
146
os.path.join('../../jam_src', jam_build_dir + '.debug'),
147
os.path.join('../../jam_src', jam_build_dir),
148
os.path.join('../jam_src', jam_build_dir + '.debug'),
149
os.path.join('../jam_src', jam_build_dir),
153
if os.path.exists(d):
217
if '--default-bjam' in sys.argv:
218
program_list.append(executable)
157
print "Cannot find built Boost.Jam"
161
program_list.append(os.path.join(jam_build_dir, executable))
221
program_list.append(os.path.join(jam_build_dir, executable))
162
223
program_list.append('-sBOOST_BUILD_PATH=' + boost_build_path)
164
225
program_list += verbosity
226
program_list += ["--ignore-toolset-requirements"]
166
228
program_list += arguments.split(" ")
312
387
expect = " (expected %d)" % status
314
print '"%s" returned %d%s' % (
315
kw['program'], _status(self), expect)
389
annotation("failed command", '"%s" returned %d%s' % (
390
kw['program'], _status(self), expect))
392
annotation("reason", "error returned by bjam")
317
393
self.fail_test(1)
319
395
if not stdout is None and not match(self.stdout(), stdout):
320
print "Expected STDOUT =========="
322
print "Actual STDOUT ============"
396
annotation("reason", "Unexpected stdout")
397
annotation("Expected STDOUT", stdout)
398
annotation("Actual STDOUT", self.stdout())
324
399
stderr = self.stderr()
326
print "STDERR ==================="
401
annotation("STDERR", stderr)
328
402
self.maybe_do_diff(self.stdout(), stdout)
329
403
self.fail_test(1, dump_stdio = 0)
349
421
self.unexpected_difference = copy.deepcopy(self.difference)
351
423
self.last_build_time = time.time()
425
def glob_file(self, name):
427
if hasattr(self,'difference'):
428
for f in self.difference.added_files+self.difference.modified_files+self.difference.touched_files:
429
if fnmatch.fnmatch(f,name):
430
result = self.native_file_name(f)
433
result = glob.glob(self.native_file_name(name))
353
438
def read(self, name):
354
return open(self.native_file_name(name), "rb").read()
441
name = string.replace(name, "$toolset", self.toolset+"*")
442
name = self.glob_file(name)
443
return open(name, "rU").read()
445
annotation("reason", "Could not open '%s'" % name)
356
449
def read_and_strip(self, name):
357
lines = open(self.native_file_name(name), "rb").readlines()
450
lines = open(self.glob_file(name), "rb").readlines()
358
451
result = string.join(map(string.rstrip, lines), "\n")
359
452
if lines and lines[-1][-1] == '\n':
360
453
return result + '\n'
458
556
def expect_nothing(self, names):
459
557
for name in self.adjust_names(names):
460
558
if name in self.difference.added_files:
461
print "File %s is added, but no action was expected" % (name,)
560
"File %s is added, but no action was expected" % (name,))
462
561
self.fail_test(1)
463
562
if name in self.difference.removed_files:
464
print "File %s is removed, but no action was expected" % (name,)
564
"File %s is removed, but no action was expected" % (name,))
465
565
self.fail_test(1)
467
567
if name in self.difference.modified_files:
468
print "File %s is modified, but no action was expected" % (name,)
569
"File %s is modified, but no action was expected" % (name,))
469
570
self.fail_test(1)
470
571
if name in self.difference.touched_files:
471
print "File %s is touched, but no action was expected" % (name,)
573
"File %s is touched, but no action was expected" % (name,))
472
574
self.fail_test(1)
474
576
def expect_nothing_more(self):
490
592
print '------- The following changes were unexpected ------- '
491
593
self.unexpected_difference.pprint()
494
def expect_content(self, name, content, exact=0):
596
def _expect_line(self, content, expected):
597
expected = expected.strip()
598
lines = content.splitlines()
602
if fnmatch.fnmatch(line, expected):
607
print "Did not found expected line in output:"
609
print "The output was:"
613
def expect_output_line(self, expected):
614
self._expect_line(self.stdout(), expected)
616
def expect_content_line(self, name, expected):
617
content = self._read_file(name)
618
self._expect_line(content, expected)
620
def _read_file(self, name, exact=0):
495
621
name = self.adjust_names(name)[0]
498
actual = self.read(name)
625
result = self.read(name)
500
actual = string.replace(self.read_and_strip(name), "\\", "/")
627
result = string.replace(self.read_and_strip(name), "\\", "/")
628
except (IOError, IndexError):
502
629
print "Note: could not open file", name
503
630
self.fail_test(1)
505
content = string.replace(content, "$toolset", self.toolset)
507
if actual != content:
634
def expect_content(self, name, content, exact=0):
635
actual = self._read_file(name, exact)
636
content = string.replace(content, "$toolset", self.toolset+"*")
640
matched = fnmatch.fnmatch(actual,content)
642
actual_ = map(lambda x: sorted(x.split()),actual.splitlines())
643
content_ = map(lambda x: sorted(x.split()),content.splitlines())
644
if len(actual_) == len(content_):
646
lambda x,y: map(lambda n,p: fnmatch.fnmatch(n,p),x,y),
649
lambda x,y: x and reduce(
508
655
print "Expected:\n"