From a607cd9ece5b27c405fb920bdd384b884a32d412 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Tue, 2 Jul 2002 10:34:43 +0000 Subject: [PATCH] Test system improvements w.r.t. file content matching. * test/BoostBuild.py (Tester.read_and_strip, Tester.expect_content): New methods. * test/test_system.html: Document the above methods. [SVN r14274] --- test/BoostBuild.py | 23 ++++++++++++++++- test/test_system.html | 54 ++++++++++++++++++++++++++++++++-------- v2/test/BoostBuild.py | 23 ++++++++++++++++- v2/test/test_system.html | 54 ++++++++++++++++++++++++++++++++-------- 4 files changed, 130 insertions(+), 24 deletions(-) diff --git a/test/BoostBuild.py b/test/BoostBuild.py index 0573ff945..a3a8b07ad 100644 --- a/test/BoostBuild.py +++ b/test/BoostBuild.py @@ -175,7 +175,16 @@ 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(self.native_file_name(name), "r").read() + + def read_and_strip(self, name): + lines = open(self.native_file_name(name), "r").readlines() + result = string.join(map(string.rstrip, lines), "\n") + if lines and lines[-1][-1] == '\n': + return result + '\n' + else: + return result + # A number of methods below check expectations with actual difference # between directory trees before and after build. @@ -264,6 +273,18 @@ class Tester(TestCmd.TestCmd): if not self.unexpected_difference.empty(): self.fail_test(1) + def expect_content(self, name, content, exact=0): + if exact: + actual = self.read(name) + else: + actual = string.replace(self.read_and_strip(name), "\\", "/") + + if actual != content: + print "Expected:\n" + print content + print "Got:\n" + print actual + self.fail_test(1) # Helpers def mul(self, *arguments): diff --git a/test/test_system.html b/test/test_system.html index 11d0e5724..f00ad9925 100644 --- a/test/test_system.html +++ b/test/test_system.html @@ -60,6 +60,9 @@
Method read
+
Method + read_and_strip
+
Methods for declaring expectations
@@ -204,8 +207,8 @@ FAILED test of D:\MyDocu~1\Work\build\boost-build\boost-build -d0 This is true on all platforms. In some contexts, a list of files is allowed. In that case any object with sequence interface is allowed.

-

Method __init__(self, - arguments='', executable='bjam')

+

Method __init__(self, arguments='', + executable='bjam')

Effects:

@@ -214,12 +217,11 @@ FAILED test of D:\MyDocu~1\Work\build\boost-build\boost-build -d0 original_workdir.
  • Determines the location of executable (bjam by - default) and build system files, assuming that the current - directory is tools/build/test. Formulates jam - invocation command, which will include explicit setting for - BOOST_BUILD_PATH variable and arguments passed to this - methods, if any. This command will be used by subsequent - invocation of tools/build/test. Formulates jam invocation command, which + will include explicit setting for BOOST_BUILD_PATH variable + and arguments passed to this methods, if any. This command will be used + by subsequent invocation of run_build_system. Finally, initializes the base class.
  • @@ -261,9 +263,8 @@ FAILED test of D:\MyDocu~1\Work\build\boost-build\boost-build -d0 to the current time. All the elements in names should be relative paths.

    -

    Method - run_build_system(self, subdir='', extra_args='', stdout=None, - stderr='', status=0, +

    Method run_build_system(self, + subdir='', extra_args='', stdout=None, stderr='', status=0, **kw)

    Effects:

    @@ -305,6 +306,21 @@ FAILED test of D:\MyDocu~1\Work\build\boost-build\boost-build -d0

    Read the specified file and returns it content. Raises an exception is the file is absent.

    +

    Method read_and_strip(self, + name)

    + +

    Effects:

    + +

    Read the specified file and returns it content, after removing + trailing whitespace from every line. Raises an exception is the file is + absent.

    + +

    Rationale:

    + +

    Althought this method is questionable, there are a lot of cases when + jam or shells it uses insert spaces. It seems that introducing this + method is much simpler than dealing with all those cases.

    +

    Methods for declaring expectations

    @@ -340,6 +356,22 @@ FAILED test of D:\MyDocu~1\Work\build\boost-build\boost-build -d0 all the changes are either expected or ignored, in other words that unexpected_difference is empty by now.

    +

    Lastly, there's a method to compare file content with expected + content:

    + expect_content(self, name, content, exact=0) + +

    The method fails the test if the content of file identified by 'name' + is different from 'content'. If 'exact' is true, the file content is used + as-is, otherwise, two transformations are applied:

    + +
      +
    • The read_and_strip method is used to read the file, which + removes trailing whitespace
    • + +
    • Each backslash in the file content is converted to forward + slash.
    • +
    +

    Methods for ignoring changes

    There are five methods which ignore changes made to the working tree. diff --git a/v2/test/BoostBuild.py b/v2/test/BoostBuild.py index 0573ff945..a3a8b07ad 100644 --- a/v2/test/BoostBuild.py +++ b/v2/test/BoostBuild.py @@ -175,7 +175,16 @@ 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(self.native_file_name(name), "r").read() + + def read_and_strip(self, name): + lines = open(self.native_file_name(name), "r").readlines() + result = string.join(map(string.rstrip, lines), "\n") + if lines and lines[-1][-1] == '\n': + return result + '\n' + else: + return result + # A number of methods below check expectations with actual difference # between directory trees before and after build. @@ -264,6 +273,18 @@ class Tester(TestCmd.TestCmd): if not self.unexpected_difference.empty(): self.fail_test(1) + def expect_content(self, name, content, exact=0): + if exact: + actual = self.read(name) + else: + actual = string.replace(self.read_and_strip(name), "\\", "/") + + if actual != content: + print "Expected:\n" + print content + print "Got:\n" + print actual + self.fail_test(1) # Helpers def mul(self, *arguments): diff --git a/v2/test/test_system.html b/v2/test/test_system.html index 11d0e5724..f00ad9925 100644 --- a/v2/test/test_system.html +++ b/v2/test/test_system.html @@ -60,6 +60,9 @@

    Method read
    +
    Method + read_and_strip
    +
    Methods for declaring expectations
    @@ -204,8 +207,8 @@ FAILED test of D:\MyDocu~1\Work\build\boost-build\boost-build -d0 This is true on all platforms. In some contexts, a list of files is allowed. In that case any object with sequence interface is allowed.

    -

    Method __init__(self, - arguments='', executable='bjam')

    +

    Method __init__(self, arguments='', + executable='bjam')

    Effects:

    @@ -214,12 +217,11 @@ FAILED test of D:\MyDocu~1\Work\build\boost-build\boost-build -d0 original_workdir.
  • Determines the location of executable (bjam by - default) and build system files, assuming that the current - directory is tools/build/test. Formulates jam - invocation command, which will include explicit setting for - BOOST_BUILD_PATH variable and arguments passed to this - methods, if any. This command will be used by subsequent - invocation of tools/build/test. Formulates jam invocation command, which + will include explicit setting for BOOST_BUILD_PATH variable + and arguments passed to this methods, if any. This command will be used + by subsequent invocation of run_build_system. Finally, initializes the base class.
  • @@ -261,9 +263,8 @@ FAILED test of D:\MyDocu~1\Work\build\boost-build\boost-build -d0 to the current time. All the elements in names should be relative paths.

    -

    Method - run_build_system(self, subdir='', extra_args='', stdout=None, - stderr='', status=0, +

    Method run_build_system(self, + subdir='', extra_args='', stdout=None, stderr='', status=0, **kw)

    Effects:

    @@ -305,6 +306,21 @@ FAILED test of D:\MyDocu~1\Work\build\boost-build\boost-build -d0

    Read the specified file and returns it content. Raises an exception is the file is absent.

    +

    Method read_and_strip(self, + name)

    + +

    Effects:

    + +

    Read the specified file and returns it content, after removing + trailing whitespace from every line. Raises an exception is the file is + absent.

    + +

    Rationale:

    + +

    Althought this method is questionable, there are a lot of cases when + jam or shells it uses insert spaces. It seems that introducing this + method is much simpler than dealing with all those cases.

    +

    Methods for declaring expectations

    @@ -340,6 +356,22 @@ FAILED test of D:\MyDocu~1\Work\build\boost-build\boost-build -d0 all the changes are either expected or ignored, in other words that unexpected_difference is empty by now.

    +

    Lastly, there's a method to compare file content with expected + content:

    + expect_content(self, name, content, exact=0) + +

    The method fails the test if the content of file identified by 'name' + is different from 'content'. If 'exact' is true, the file content is used + as-is, otherwise, two transformations are applied:

    + +
      +
    • The read_and_strip method is used to read the file, which + removes trailing whitespace
    • + +
    • Each backslash in the file content is converted to forward + slash.
    • +
    +

    Methods for ignoring changes

    There are five methods which ignore changes made to the working tree.