From 6d13f1ea8592d03215bcae741a8f12e68e5fd6e7 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Tue, 24 Oct 2006 23:26:32 +0000 Subject: [PATCH] (merge from head) A variety of changes to make most tests pass on Windows (with mingw): * BoostBuild.py; Make the matching of content and files be more loose and use pattern globbing of toolset names. * glob.py/project_glob.py; Rename to avoid collision with builtin Python module. * all; Update copyrights and license info. [SVN r35731] --- test/BoostBuild.py | 61 +++++++++++--- test/glob.py | 119 ---------------------------- test/project-test3/project-root.jam | 12 ++- test/regression.py | 10 +-- test/test_all.py | 9 ++- 5 files changed, 69 insertions(+), 142 deletions(-) delete mode 100644 test/glob.py diff --git a/test/BoostBuild.py b/test/BoostBuild.py index 2aa2822f2..2e7c10ad8 100644 --- a/test/BoostBuild.py +++ b/test/BoostBuild.py @@ -1,16 +1,23 @@ +# Copyright 2002-2005 Vladimir Prus. +# Copyright 2002-2003 Dave Abrahams. +# Copyright 2006 Rene Rivera. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) import TestCmd from tree import build_tree, trees_difference import copy import fnmatch +import glob import os +import re import shutil import string import types import time import tempfile import sys -import re def get_toolset(): toolset = None; @@ -39,6 +46,17 @@ def prepare_suffix_map(toolset): if os.__dict__.has_key('uname') and os.uname()[0] == 'Darwin': suffixes['.dll'] = '.dylib' +def re_remove(sequence,regex): + me = re.compile(regex) + result = filter( lambda x: me.match(x), sequence ) + for r in result: + sequence.remove(r) + +def glob_remove(sequence,pattern): + result = fnmatch.filter(sequence,pattern) + for r in result: + sequence.remove(r) + lib_prefix = 1 if windows: lib_prefix = 0 @@ -255,10 +273,13 @@ class Tester(TestCmd.TestCmd): os.chdir(self.original_workdir) for name in names: n = self.native_file_name(name) - if os.path.isdir(n): - shutil.rmtree(n, ignore_errors=0) - else: - os.unlink(n) + n = glob.glob(n) + if n: + n = n[0] + if os.path.isdir(n): + shutil.rmtree(n, ignore_errors=0) + else: + os.unlink(n) # Create working dir root again, in case # we've removed it @@ -358,10 +379,10 @@ class Tester(TestCmd.TestCmd): self.last_build_time = time.time() def read(self, name): - return open(self.native_file_name(name), "rb").read() + return open(glob.glob(self.native_file_name(name))[0], "rb").read() def read_and_strip(self, name): - lines = open(self.native_file_name(name), "rb").readlines() + lines = open(glob.glob(self.native_file_name(name))[0], "rb").readlines() result = string.join(map(string.rstrip, lines), "\n") if lines and lines[-1][-1] == '\n': return result + '\n' @@ -399,7 +420,7 @@ class Tester(TestCmd.TestCmd): def expect_addition(self, names): for name in self.adjust_names(names): try: - self.unexpected_difference.added_files.remove(name) + glob_remove(self.unexpected_difference.added_files,name) except: print "File %s not added as expected" % (name,) self.fail_test(1) @@ -410,7 +431,7 @@ class Tester(TestCmd.TestCmd): def expect_removal(self, names): for name in self.adjust_names(names): try: - self.unexpected_difference.removed_files.remove(name) + glob_remove(self.unexpected_difference.removed_files,name) except: print "File %s not removed as expected" % (name,) self.fail_test(1) @@ -443,7 +464,7 @@ class Tester(TestCmd.TestCmd): while filesets: try: - filesets[-1].remove(name) + glob_remove(filesets[-1],name) break except ValueError: filesets.pop() @@ -509,9 +530,23 @@ class Tester(TestCmd.TestCmd): print "Note: could not open file", name self.fail_test(1) - content = string.replace(content, "$toolset", self.toolset) + content = string.replace(content, "$toolset", self.toolset+"*") + + if exact: + matched = fnmatch.fnmatch(actual,content) + else: + actual_ = map(lambda x: sorted(x.split()),actual.splitlines()) + content_ = map(lambda x: sorted(x.split()),content.splitlines()) + matched = map( + lambda x,y: map(lambda n,p: fnmatch.fnmatch(n,p),x,y), + actual_, content_ ) + matched = reduce( + lambda x,y: x and reduce( + lambda a,b: a and b, + y ), + matched ) - if actual != content: + if not matched: print "Expected:\n" print content print "Got:\n" @@ -596,7 +631,7 @@ class Tester(TestCmd.TestCmd): names = [names] r = map(self.adjust_lib_name, names) r = map(self.adjust_suffix, r) - r = map(lambda x, t=self.toolset: string.replace(x, "$toolset", t), r) + r = map(lambda x, t=self.toolset: string.replace(x, "$toolset", t+"*"), r) return r def native_file_name(self, name): diff --git a/test/glob.py b/test/glob.py deleted file mode 100644 index 768c59a51..000000000 --- a/test/glob.py +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/python - -# Copyright (C) Vladimir Prus 2003. Permission to copy, use, modify, sell and -# distribute this software is granted provided this copyright notice appears in -# all copies. This software is provided "as is" without express or implied -# warranty, and with no claim as to its suitability for any purpose. - -# Test the 'glob' rule in Jamfile context. -from BoostBuild import Tester, List -import os -import string - -# Create a temporary working directory -t = Tester() - -t.write("project-root.jam", """ -""") - -t.write("Jamfile", """ -""") - -t.write("d1/a.cpp", """ -int main() { return 0; } - -""") - -t.write("d1/Jamfile", """ -exe a : [ glob *.cpp ] ../d2/d//l ; -""") - -t.write("d2/d/l.cpp", """ -#if defined(_WIN32) -__declspec(dllexport) -void force_import_lib_creation() {} -#endif -""") - -t.write("d2/d/Jamfile", """ -lib l : [ glob *.cpp ] ; -""") - -t.write("d3/d/Jamfile", """ -exe a : [ glob ../*.cpp ] ; -""") -t.write("d3/a.cpp", """ -int main() -{ - return 0; -} -""") - -t.run_build_system(subdir="d1") -t.expect_addition("d1/bin/$toolset/debug/a.exe") - -t.run_build_system(subdir="d3/d") -t.expect_addition("d3/d/bin/$toolset/debug/a.exe") - -t.rm("d2/d/bin") -t.run_build_system(subdir="d2/d") -t.expect_addition("d2/d/bin/$toolset/debug/l.dll") - -# Test that when 'source-location' is explicitly-specified -# glob works relatively to source location -t.rm("d1") - -t.write("d1/src/a.cpp", """ -int main() { return 0; } - -""") - -t.write("d1/Jamfile", """ -project : source-location src ; -exe a : [ glob *.cpp ] ../d2/d//l ; -""") - -t.run_build_system(subdir="d1") -t.expect_addition("d1/bin/$toolset/debug/a.exe") - -# Test that wildcards can include directories -t.rm("d1") - -t.write("d1/src/foo/a.cpp", """ -void bar(); -int main() { bar(); return 0; } - -""") - -t.write("d1/src/bar/b.cpp", """ -void bar() {} - -""") - - -t.write("d1/Jamfile", """ -project : source-location src ; -exe a : [ glob foo/*.cpp bar/*.cpp ] ../d2/d//l ; -""") - -t.run_build_system(subdir="d1") -t.expect_addition("d1/bin/$toolset/debug/a.exe") - -# Test that 'glob' works with absolute names -t.rm("d1/bin") - -# Note that to get current dir, we use bjam's PWD, -# not Python's os.getcwd, because the former will -# always return long path. The latter might return -# short path, and that will confuse path.glob. -t.write("d1/Jamfile", """ -project : source-location src ; -local pwd = [ PWD ] ; # Always absolute -exe a : [ glob $(pwd)/src/foo/*.cpp $(pwd)/src/bar/*.cpp ] ../d2/d//l ; -""") - -t.run_build_system(subdir="d1") -t.expect_addition("d1/bin/$toolset/debug/a.exe") - - -t.cleanup() diff --git a/test/project-test3/project-root.jam b/test/project-test3/project-root.jam index b660ceb52..8de43be51 100644 --- a/test/project-test3/project-root.jam +++ b/test/project-test3/project-root.jam @@ -1,3 +1,7 @@ +# Copyright 2002-2005 Vladimir Prus. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) import gcc ; import property ; @@ -7,10 +11,10 @@ rule properties-as-path ( properties * ) local r ; for local p in $(properties) { - if $(p:G) != - { - r += $(p) ; - } + if $(p:G) != + { + r += $(p) ; + } } return [ property.as-path [ property.remove incidental : $(r) ] ] ; diff --git a/test/regression.py b/test/regression.py index 50a0ab477..d090314d7 100644 --- a/test/regression.py +++ b/test/regression.py @@ -1,9 +1,9 @@ #!/usr/bin/python -# Copyright (C) Vladimir Prus 2003. Permission to copy, use, modify, sell and -# distribute this software is granted provided this copyright notice appears in -# all copies. This software is provided "as is" without express or implied -# warranty, and with no claim as to its suitability for any purpose. +# Copyright (C) Vladimir Prus 2003. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) # Test for the regression testing framework. from BoostBuild import Tester, List @@ -74,7 +74,7 @@ t.expect_addition("bin/r-f.test/$toolset/debug/r-f.test") # Make sure args are handled. t.expect_content("bin/r.test/$toolset/debug/r.output", - "foo\nbar\n\nEXIT STATUS: 0\n") + "foo\nbar\n\nEXIT STATUS: 0\n",True) # Test that input file is handled as well. t.write("r.cpp", """ diff --git a/test/test_all.py b/test/test_all.py index e89e10594..1ded06fee 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -1,4 +1,11 @@ #!/usr/bin/python + +# Copyright 2002-2005 Dave Abrahams. +# Copyright 2002-2006 Vladimir Prus. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + import os, sys, string from BoostBuild import get_toolset @@ -112,7 +119,7 @@ tests = [ "rebuilds", "suffix", "inherit_toolset", "skipping", - "glob", + "project_glob", "project_root_constants", "double_loading", "dll_path",