2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-16 01:12:13 +00:00

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]
This commit is contained in:
Vladimir Prus
2002-07-02 10:34:43 +00:00
parent 3392742d1e
commit a607cd9ece
4 changed files with 130 additions and 24 deletions

View File

@@ -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):

View File

@@ -60,6 +60,9 @@
<dt><a href="#method-read">Method <tt>read</tt></a></dt>
<dt><a href="#method-read_and_strip">Method
<tt>read_and_strip</tt></a></dt>
<dt><a href="#methods-expectations">Methods for declaring
expectations</a></dt>
@@ -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.</p>
<h3><a name="method-__init__">Method <tt>__init__(self,
arguments='', executable='bjam')</tt></a></h3>
<h3><a name="method-__init__">Method <tt>__init__(self, arguments='',
executable='bjam')</tt></a></h3>
<p><b>Effects:</b></p>
@@ -214,12 +217,11 @@ FAILED test of D:\MyDocu~1\Work\build\boost-build\boost-build -d0
<tt>original_workdir</tt>.</li>
<li>Determines the location of executable (<code>bjam</code> by
default) and build system files, assuming that the current
directory is <tt>tools/build/test</tt>. Formulates jam
invocation command, which will include explicit setting for
<tt>BOOST_BUILD_PATH</tt> variable and arguments passed to this
methods, if any. This command will be used by subsequent
invocation of <a href=
default) and build system files, assuming that the current directory is
<tt>tools/build/test</tt>. Formulates jam invocation command, which
will include explicit setting for <tt>BOOST_BUILD_PATH</tt> variable
and arguments passed to this methods, if any. This command will be used
by subsequent invocation of <a href=
"#method-run_build_system"><tt>run_build_system</tt></a>. Finally,
initializes the base class.</li>
@@ -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 <tt>names</tt> should be
relative paths.</p>
<h3><a name="method-run_build_system">Method
<tt>run_build_system(self, subdir='', extra_args='', stdout=None,
stderr='', status=0,
<h3><a name="method-run_build_system">Method <tt>run_build_system(self,
subdir='', extra_args='', stdout=None, stderr='', status=0,
**kw)</tt></a></h3>
<p><b>Effects:</b></p>
@@ -305,6 +306,21 @@ FAILED test of D:\MyDocu~1\Work\build\boost-build\boost-build -d0
<p>Read the specified file and returns it content. Raises an exception is
the file is absent.</p>
<h3><a name="method-read_and_strip">Method <tt>read_and_strip(self,
name)</tt></a></h3>
<p><b>Effects:</b></p>
<p>Read the specified file and returns it content, after removing
trailing whitespace from every line. Raises an exception is the file is
absent.</p>
<p><b>Rationale:</b></p>
<p>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.</p>
<h3><a name="methods-expectations">Methods for declaring
expectations</a></h3>
@@ -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
<tt>unexpected_difference</tt> is empty by now.</p>
<p>Lastly, there's a method to compare file content with expected
content:</p>
<tt>expect_content(self, name, content, exact=0)</tt>
<p>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:</p>
<ul>
<li>The <tt>read_and_strip</tt> method is used to read the file, which
removes trailing whitespace</li>
<li>Each backslash in the file content is converted to forward
slash.</li>
</ul>
<h3><a name="methods-ignoring">Methods for ignoring changes</a></h3>
<p>There are five methods which ignore changes made to the working tree.

View File

@@ -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):

View File

@@ -60,6 +60,9 @@
<dt><a href="#method-read">Method <tt>read</tt></a></dt>
<dt><a href="#method-read_and_strip">Method
<tt>read_and_strip</tt></a></dt>
<dt><a href="#methods-expectations">Methods for declaring
expectations</a></dt>
@@ -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.</p>
<h3><a name="method-__init__">Method <tt>__init__(self,
arguments='', executable='bjam')</tt></a></h3>
<h3><a name="method-__init__">Method <tt>__init__(self, arguments='',
executable='bjam')</tt></a></h3>
<p><b>Effects:</b></p>
@@ -214,12 +217,11 @@ FAILED test of D:\MyDocu~1\Work\build\boost-build\boost-build -d0
<tt>original_workdir</tt>.</li>
<li>Determines the location of executable (<code>bjam</code> by
default) and build system files, assuming that the current
directory is <tt>tools/build/test</tt>. Formulates jam
invocation command, which will include explicit setting for
<tt>BOOST_BUILD_PATH</tt> variable and arguments passed to this
methods, if any. This command will be used by subsequent
invocation of <a href=
default) and build system files, assuming that the current directory is
<tt>tools/build/test</tt>. Formulates jam invocation command, which
will include explicit setting for <tt>BOOST_BUILD_PATH</tt> variable
and arguments passed to this methods, if any. This command will be used
by subsequent invocation of <a href=
"#method-run_build_system"><tt>run_build_system</tt></a>. Finally,
initializes the base class.</li>
@@ -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 <tt>names</tt> should be
relative paths.</p>
<h3><a name="method-run_build_system">Method
<tt>run_build_system(self, subdir='', extra_args='', stdout=None,
stderr='', status=0,
<h3><a name="method-run_build_system">Method <tt>run_build_system(self,
subdir='', extra_args='', stdout=None, stderr='', status=0,
**kw)</tt></a></h3>
<p><b>Effects:</b></p>
@@ -305,6 +306,21 @@ FAILED test of D:\MyDocu~1\Work\build\boost-build\boost-build -d0
<p>Read the specified file and returns it content. Raises an exception is
the file is absent.</p>
<h3><a name="method-read_and_strip">Method <tt>read_and_strip(self,
name)</tt></a></h3>
<p><b>Effects:</b></p>
<p>Read the specified file and returns it content, after removing
trailing whitespace from every line. Raises an exception is the file is
absent.</p>
<p><b>Rationale:</b></p>
<p>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.</p>
<h3><a name="methods-expectations">Methods for declaring
expectations</a></h3>
@@ -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
<tt>unexpected_difference</tt> is empty by now.</p>
<p>Lastly, there's a method to compare file content with expected
content:</p>
<tt>expect_content(self, name, content, exact=0)</tt>
<p>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:</p>
<ul>
<li>The <tt>read_and_strip</tt> method is used to read the file, which
removes trailing whitespace</li>
<li>Each backslash in the file content is converted to forward
slash.</li>
</ul>
<h3><a name="methods-ignoring">Methods for ignoring changes</a></h3>
<p>There are five methods which ignore changes made to the working tree.