From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id A565JBdxP2HPKAAAWB0awg (envelope-from ) for ; Mon, 13 Sep 2021 11:41:11 -0400 Received: by simark.ca (Postfix, from userid 112) id 827071EE25; Mon, 13 Sep 2021 11:41:11 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 0BE101EDDB for ; Mon, 13 Sep 2021 11:41:10 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7B7763858003 for ; Mon, 13 Sep 2021 15:41:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B7763858003 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1631547669; bh=4zm2r2x+jTUS3cA4bHUAFISAhq8hfCsvH3VqiOnJ/H4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=njwo2gjT70u6VXpaYKzhsttUrRIkXblwPUKhclJv064yAvfU/avPQ60lmukAbxbtO exzqvzhNAcIavsXfqHsq47VmMEryUPzAF8bprzSRQknZWv5BnghjsGMAHt9SEppbKk 1NJSitGxUKEvnFU8vEOKcAB0dNfPpXzqB7SqMI+w= Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 73276385781B for ; Mon, 13 Sep 2021 15:40:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 73276385781B Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9C5D821FFF for ; Mon, 13 Sep 2021 15:40:03 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8B38613AB5 for ; Mon, 13 Sep 2021 15:40:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qvfzINNwP2FxDQAAMHmgww (envelope-from ) for ; Mon, 13 Sep 2021 15:40:03 +0000 Date: Mon, 13 Sep 2021 17:40:02 +0200 To: gdb-patches@sourceware.org Subject: [PATCH][gdb] Add register_test variant with std::function arg Message-ID: <20210913154000.GA3078@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi, Add register_test variant with std::function arg, such that we can do: ... register_test (test_name, [=] () { SELF_CHECK (...); }); ... Any comments? Thanks, - Tom [gdb] Add register_test variant with std::function arg --- gdbsupport/selftest.cc | 25 +++++++++++++++++++++++++ gdbsupport/selftest.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/gdbsupport/selftest.cc b/gdbsupport/selftest.cc index d0511abe654..6d92844880f 100644 --- a/gdbsupport/selftest.cc +++ b/gdbsupport/selftest.cc @@ -21,6 +21,7 @@ #include "common-debug.h" #include "selftest.h" #include +#include namespace selftests { @@ -57,6 +58,30 @@ register_test (const std::string &name, selftest *test) tests[name] = std::unique_ptr (test); } +struct lambda_selftest : public selftest +{ + lambda_selftest (std::function function_) + { + function = function_; + } + + void operator() () const override + { + function (); + } + + std::function function; +}; + +/* See selftest.h. */ + +void +register_test (const std::string &name, + std::function function) +{ + register_test (name, new lambda_selftest (function)); +} + /* See selftest.h. */ void diff --git a/gdbsupport/selftest.h b/gdbsupport/selftest.h index 13441b05a21..d2fa07228e8 100644 --- a/gdbsupport/selftest.h +++ b/gdbsupport/selftest.h @@ -46,6 +46,9 @@ extern void register_test (const std::string &name, selftest *test); extern void register_test (const std::string &name, self_test_function *function); +extern void register_test (const std::string &name, + std::function function); + /* Run all the self tests. This print a message describing the number of test and the number of failures.