"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "googletest/scripts/gen_gtest_pred_impl.py" between
googletest-release-1.10.0.tar.gz and googletest-release-1.11.0.tar.gz

About: GoogleTest is Google's (unit) testing and mocking framework for C++ tests.

gen_gtest_pred_impl.py  (googletest-release-1.10.0):gen_gtest_pred_impl.py  (googletest-release-1.11.0)
skipping to change at line 80 skipping to change at line 80
# A map that defines the values used in the preamble template. # A map that defines the values used in the preamble template.
DEFS = { DEFS = {
'today' : time.strftime('%m/%d/%Y'), 'today' : time.strftime('%m/%d/%Y'),
'year' : time.strftime('%Y'), 'year' : time.strftime('%Y'),
'command' : '%s %s' % (os.path.basename(sys.argv[0]), n), 'command' : '%s %s' % (os.path.basename(sys.argv[0]), n),
'n' : n 'n' : n
} }
return ( return (
"""// Copyright 2006, Google Inc. """// Copyright 2006, Google Inc.
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
skipping to change at line 113 skipping to change at line 113
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This file is AUTOMATICALLY GENERATED on %(today)s by command // This file is AUTOMATICALLY GENERATED on %(today)s by command
// '%(command)s'. DO NOT EDIT BY HAND! // '%(command)s'. DO NOT EDIT BY HAND!
// //
// Implements a family of generic predicate assertion macros. // Implements a family of generic predicate assertion macros.
// GOOGLETEST_CM0001 DO NOT DELETE
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_ #ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
#define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_ #define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace testing { namespace testing {
// This header implements a family of generic predicate assertion // This header implements a family of generic predicate assertion
// macros: // macros:
skipping to change at line 243 skipping to change at line 244
""" % DEFS """ % DEFS
impl += ' return AssertionFailure() << pred_text << "("' impl += ' return AssertionFailure() << pred_text << "("'
impl += Iter(n, """ impl += Iter(n, """
<< e%s""", sep=' << ", "') << e%s""", sep=' << ", "')
impl += ' << ") evaluates to false, where"' impl += ' << ") evaluates to false, where"'
impl += Iter(n, """ impl += Iter(
<< "\\n" << e%s << " evaluates to " << v%s""") n, """
<< "\\n" << e%s << " evaluates to " << ::testing::PrintToString(v%s)"""
)
impl += """; impl += """;
} }
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT%(n)s. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT%(n)s.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT%(n)s_(pred_format, %(vs)s, on_failure)\\ #define GTEST_PRED_FORMAT%(n)s_(pred_format, %(vs)s, on_failure)\\
GTEST_ASSERT_(pred_format(%(vts)s, %(vs)s), \\ GTEST_ASSERT_(pred_format(%(vts)s, %(vs)s), \\
on_failure) on_failure)
skipping to change at line 326 skipping to change at line 329
"""Returns the preamble for the unit test file.""" """Returns the preamble for the unit test file."""
# A map that defines the values used in the preamble template. # A map that defines the values used in the preamble template.
DEFS = { DEFS = {
'today' : time.strftime('%m/%d/%Y'), 'today' : time.strftime('%m/%d/%Y'),
'year' : time.strftime('%Y'), 'year' : time.strftime('%Y'),
'command' : '%s %s' % (os.path.basename(sys.argv[0]), sys.argv[1]), 'command' : '%s %s' % (os.path.basename(sys.argv[0]), sys.argv[1]),
} }
return ( return (
"""// Copyright 2006, Google Inc. """// Copyright 2006, Google Inc.
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
skipping to change at line 419 skipping to change at line 422
'tvs' : Iter(n, 'T%s v%s', sep=', '), 'tvs' : Iter(n, 'T%s v%s', sep=', '),
'int_vs' : Iter(n, 'int v%s', sep=', '), 'int_vs' : Iter(n, 'int v%s', sep=', '),
'Bool_vs' : Iter(n, 'Bool v%s', sep=', '), 'Bool_vs' : Iter(n, 'Bool v%s', sep=', '),
'types' : Iter(n, 'typename T%s', sep=', '), 'types' : Iter(n, 'typename T%s', sep=', '),
'v_sum' : Iter(n, 'v%s', sep=' + '), 'v_sum' : Iter(n, 'v%s', sep=' + '),
'arity' : Arity(n), 'arity' : Arity(n),
'Arity' : Title(Arity(n)), 'Arity' : Title(Arity(n)),
} }
tests = ( tests = (
"""// Sample functions/functors for testing %(arity)s predicate assertions. """// Sample functions/functors for testing %(arity)s predicate assertions.
// A %(arity)s predicate function. // A %(arity)s predicate function.
template <%(types)s> template <%(types)s>
bool PredFunction%(n)s(%(tvs)s) { bool PredFunction%(n)s(%(tvs)s) {
return %(v_sum)s > 0; return %(v_sum)s > 0;
} }
// The following two functions are needed to circumvent a bug in // The following two functions are needed because a compiler doesn't have
// gcc 2.95.3, which sometimes has problem with the above template // a context yet to know which template function must be instantiated.
// function.
bool PredFunction%(n)sInt(%(int_vs)s) { bool PredFunction%(n)sInt(%(int_vs)s) {
return %(v_sum)s > 0; return %(v_sum)s > 0;
} }
bool PredFunction%(n)sBool(%(Bool_vs)s) { bool PredFunction%(n)sBool(%(Bool_vs)s) {
return %(v_sum)s > 0; return %(v_sum)s > 0;
} }
""" % DEFS) """ % DEFS)
tests += """ tests += """
// A %(arity)s predicate functor. // A %(arity)s predicate functor.
skipping to change at line 502 skipping to change at line 504
return PredFormatFunction%(n)s(%(es)s, %(vs)s); return PredFormatFunction%(n)s(%(es)s, %(vs)s);
} }
}; };
""" % DEFS """ % DEFS
tests += """ tests += """
// Tests for {EXPECT|ASSERT}_PRED_FORMAT%(n)s. // Tests for {EXPECT|ASSERT}_PRED_FORMAT%(n)s.
class Predicate%(n)sTest : public testing::Test { class Predicate%(n)sTest : public testing::Test {
protected: protected:
virtual void SetUp() { void SetUp() override {
expected_to_finish_ = true; expected_to_finish_ = true;
finished_ = false;""" % DEFS finished_ = false;""" % DEFS
tests += """ tests += """
""" + Iter(n, 'n%s_ = ') + """0; """ + Iter(n, 'n%s_ = ') + """0;
} }
""" """
tests += """ tests += """
virtual void TearDown() { void TearDown() override {
// Verifies that each of the predicate's arguments was evaluated // Verifies that each of the predicate's arguments was evaluated
// exactly once.""" // exactly once."""
tests += ''.join([""" tests += ''.join(["""
EXPECT_EQ(1, n%s_) << EXPECT_EQ(1, n%s_) <<
"The predicate assertion didn't evaluate argument %s " "The predicate assertion didn't evaluate argument %s "
"exactly once.";""" % (i, i + 1) for i in OneTo(n)]) "exactly once.";""" % (i, i + 1) for i in OneTo(n)])
tests += """ tests += """
// Verifies that the control flow in the test function is expected. // Verifies that the control flow in the test function is expected.
if (expected_to_finish_ && !finished_) { if (expected_to_finish_ && !finished_) {
FAIL() << "The predicate assertion unexpactedly aborted the test."; FAIL() << "The predicate assertion unexpactedly aborted the test.";
} else if (!expected_to_finish_ && finished_) { } else if (!expected_to_finish_ && finished_) {
FAIL() << "The failed predicate assertion didn't abort the test " FAIL() << "The failed predicate assertion didn't abort the test "
"as expected."; "as expected.";
} }
} }
// true iff the test function is expected to run to finish. // true if and only if the test function is expected to run to finish.
static bool expected_to_finish_; static bool expected_to_finish_;
// true iff the test function did run to finish. // true if and only if the test function did run to finish.
static bool finished_; static bool finished_;
""" % DEFS """ % DEFS
tests += Iter(n, """ tests += Iter(n, """
static int n%s_;""") static int n%s_;""")
tests += """ tests += """
}; };
bool Predicate%(n)sTest::expected_to_finish_; bool Predicate%(n)sTest::expected_to_finish_;
skipping to change at line 564 skipping to change at line 566
typedef Predicate%(n)sTest ASSERT_PRED_FORMAT%(n)sTest; typedef Predicate%(n)sTest ASSERT_PRED_FORMAT%(n)sTest;
typedef Predicate%(n)sTest EXPECT_PRED%(n)sTest; typedef Predicate%(n)sTest EXPECT_PRED%(n)sTest;
typedef Predicate%(n)sTest ASSERT_PRED%(n)sTest; typedef Predicate%(n)sTest ASSERT_PRED%(n)sTest;
""" % DEFS """ % DEFS
def GenTest(use_format, use_assert, expect_failure, def GenTest(use_format, use_assert, expect_failure,
use_functor, use_user_type): use_functor, use_user_type):
"""Returns the test for a predicate assertion macro. """Returns the test for a predicate assertion macro.
Args: Args:
use_format: true iff the assertion is a *_PRED_FORMAT*. use_format: true if and only if the assertion is a *_PRED_FORMAT*.
use_assert: true iff the assertion is a ASSERT_*. use_assert: true if and only if the assertion is a ASSERT_*.
expect_failure: true iff the assertion is expected to fail. expect_failure: true if and only if the assertion is expected to fail.
use_functor: true iff the first argument of the assertion is use_functor: true if and only if the first argument of the assertion is
a functor (as opposed to a function) a functor (as opposed to a function)
use_user_type: true iff the predicate functor/function takes use_user_type: true if and only if the predicate functor/function takes
argument(s) of a user-defined type. argument(s) of a user-defined type.
Example: Example:
GenTest(1, 0, 0, 1, 0) returns a test that tests the behavior GenTest(1, 0, 0, 1, 0) returns a test that tests the behavior
of a successful EXPECT_PRED_FORMATn() that takes a functor of a successful EXPECT_PRED_FORMATn() that takes a functor
whose arguments have built-in types.""" whose arguments have built-in types."""
if use_assert: if use_assert:
assrt = 'ASSERT' # 'assert' is reserved, so we cannot use assrt = 'ASSERT' # 'assert' is reserved, so we cannot use
# that identifier here. # that identifier here.
else: else:
assrt = 'EXPECT' assrt = 'EXPECT'
assertion = assrt + '_PRED' assertion = assrt + '_PRED'
if use_format: if use_format:
pred_format = 'PredFormat' pred_format = 'PredFormat'
assertion += '_FORMAT' assertion += '_FORMAT'
else: else:
pred_format = 'Pred' pred_format = 'Pred'
 End of changes. 13 change blocks. 
18 lines changed or deleted 20 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)