From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 64579 invoked by alias); 26 Jul 2017 16:25:25 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 64564 invoked by uid 89); 26 Jul 2017 16:25:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2323, nitpick X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 26 Jul 2017 16:25:22 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C156277350; Wed, 26 Jul 2017 16:25:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C156277350 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=dmalcolm@redhat.com Received: from ovpn-116-58.phx2.redhat.com (ovpn-116-58.phx2.redhat.com [10.3.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 444E85D978; Wed, 26 Jul 2017 16:25:20 +0000 (UTC) Message-ID: <1501086319.10760.56.camel@redhat.com> Subject: Re: [PATCH 1/2] Introduce testsuite support to run Python tests From: David Malcolm To: Pierre-Marie de Rodat , gcc-patches@gcc.gnu.org Date: Wed, 26 Jul 2017 16:25:00 -0000 In-Reply-To: <20170726160040.6516-2-derodat@adacore.com> References: <20170726160040.6516-1-derodat@adacore.com> <20170726160040.6516-2-derodat@adacore.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2017-07/txt/msg01683.txt.bz2 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 > +# . > + > +# 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)