On Wed, 2017-07-26 at 18:00 +0200, Pierre-Marie de Rodat wrote:
[...snip...]

> diff --git a/gcc/testsuite/python/testutils.py
> b/gcc/testsuite/python/testutils.py
> new file mode 100644
> index 00000000000..503105ad9d0
> --- /dev/null
> +++ b/gcc/testsuite/python/testutils.py
> @@ -0,0 +1,45 @@
> +# Copyright (C) 2017 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or
> modify
> +# it under the terms of the GNU General Public License as published
> by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with GCC; see the file COPYING3.  If not see
> +# <http://www.gnu.org/licenses/>.
> +
> +# Helpers to drive a testcase
> +
> +def print_pass(message):
> +    """Emit a PASS message.
> +
> +    :param str message: Message to emit.
> +    """
> +    print('PASS: {}'.format(message))

str.format was introduced in Python 2.6, so presumably the minimum
python 2 version here is at least 2.6+; for Python 3 I believe it was
present in Python 3.0 onwards.

> +
> +def print_fail(message):
> +    """Emit a FAIL message.
> +
> +    :param str message: Message to emit.
> +    """
> +    print('FAIL: {}'.format(message))
> +
> +
> +def check(predicate, message):
> +    """
> +    If `predicate` is True, emit a PASS message, otherwise emit a
> FAIL one.

A very nitpicky nitpick: this comment should be spelled as "is true"
(lowercase), rather than "is True" since the requirement is that
predicate's "truth value" is true, rather than predicate *is* the
boolean "True" singleton; e.g. if someone passes in an int as
predicate, its nonzero-ness would be used, rather than always being
false (since no int *is* the boolean singleton "True").

> +
> +    :param bool predicate: Whether the test should pass.
> +    :param str message: Message to emit.
> +    """
> +    if predicate:
> +        print_pass(message)
> +    else:
> +        print_fail(message)

Reply via email to