From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id u/QcEoES+V94QAAAWB0awg (envelope-from ) for ; Fri, 08 Jan 2021 21:18:41 -0500 Received: by simark.ca (Postfix, from userid 112) id 39F071E99A; Fri, 8 Jan 2021 21:18:41 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [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 C75741E940 for ; Fri, 8 Jan 2021 21:18:40 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 49C7C3842439; Sat, 9 Jan 2021 02:18:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49C7C3842439 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1610158720; bh=wkOHLSrJXuTsbGpPxxQEFni3xqrZ7UbqviDrrWN2AcY=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=lSCezb9uEkbG03bHX7J8JwL1ezkWgdpmEdTRbuMuViZDs6rDmv/Tphov+FpBkaDlg ug5ymIEdZOOeQBtz6I32mCKi7opvv/9L/3NMA1TypKqIibpJvfXhr1GA7Z1JnWHHSc cLgnMrWiTF6YEdGyp1uteQF8BmrK6zhUZAdB95xc= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 51B0A3857818 for ; Sat, 9 Jan 2021 02:18:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 51B0A3857818 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 1092HRsr022862 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 8 Jan 2021 21:17:32 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 1092HRsr022862 Received: from [10.0.0.213] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 2E8AB1E940; Fri, 8 Jan 2021 21:17:27 -0500 (EST) Subject: Re: [PATCH] Improve gdb_tilde_expand logic To: Lancelot SIX , Andrew Burgess References: <20210108001337.29164-1-lsix@lancelotsix.com> <20210108093058.GR2945@embecosm.com> <58a88de1-6c5d-98ec-62d2-860f9ad7a8a8@polymtl.ca> <8fdb8080-ae0b-70ae-20ab-e84329590bea@lancelotsix.com> Message-ID: <4016e225-2024-3f95-5be8-d0970f166193@polymtl.ca> Date: Fri, 8 Jan 2021 21:17:26 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <8fdb8080-ae0b-70ae-20ab-e84329590bea@lancelotsix.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sat, 9 Jan 2021 02:17:27 +0000 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: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 2021-01-08 8:33 p.m., Lancelot SIX wrote: > The option I have in mind is inspired by gdb.gdb/selftest.exp (if I understand it correctly): once I have a gdb session debugging gdb, I can have something like: > >     gdb_test {print gdb_tilde_expand ("~/most/probably/non/existing").c_str ()} \ >              {= .*"/.*/most/probably/non/existing"} > > or something similar. If I go for something like that, can it be added directly in selftest.expr (under gdb.gdb) or do it require an entire new testcase (probably in gdb.base)?  It might be an overkill approach to unit-testing, but it should work. Well, we now have a "selftest" framework integrated in the GDB binary itself, which makes it much more convenient to unit test functions. It's also called selftest, but it's not related to gdb.gdb/selftest.exp. I mislead you in my previous message when I said you could place the test in gdbsupport. Well, the test could be in gdbsupport, but there needs to be something that registers the test, which is usually done in an _initialize_* function in GDB. So there are already some tests for gdbsupport stuff placed in gdb/unittest. You can use the patch below as a starting point. You can run it like this: (gdb) maintenance selftest tilde Running selftest gdb_tilde_expand. Self test failed: Could not find a match for '~/non/existent/directory'. Ran 1 unit tests, 1 failed With your fix, there shouldn't be an exception thrown. And it would be a good idea to add a SELF_CHECK (i.e. an assert) to check the result, for example we expect it to contain "/non/existent/directory" somewhere. Simon >From 65013bf368ca127ff51d96c6efb053209afc0ad5 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 8 Jan 2021 21:12:19 -0500 Subject: [PATCH] gdb: add selftest for gdb_tilde_expand Change-Id: Icfcbc761a9b39c9b66634985a23b92e9a65ca761 --- gdb/Makefile.in | 1 + gdb/unittests/gdb_tilde_expand-selftests.c | 44 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 gdb/unittests/gdb_tilde_expand-selftests.c diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 9267bea7beb6..c8979fe2760b 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -446,6 +446,7 @@ SELFTESTS_SRCS = \ unittests/filtered_iterator-selftests.c \ unittests/format_pieces-selftests.c \ unittests/function-view-selftests.c \ + unittests/gdb_tilde_expand-selftests.c \ unittests/gmp-utils-selftests.c \ unittests/lookup_name_info-selftests.c \ unittests/memory-map-selftests.c \ diff --git a/gdb/unittests/gdb_tilde_expand-selftests.c b/gdb/unittests/gdb_tilde_expand-selftests.c new file mode 100644 index 000000000000..c68ea99dac83 --- /dev/null +++ b/gdb/unittests/gdb_tilde_expand-selftests.c @@ -0,0 +1,44 @@ +/* Self tests for gdb_tilde_expand + + Copyright (C) 2021 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 this program. If not, see . */ + +#include "gdbsupport/common-defs.h" +#include "gdbsupport/selftest.h" + +#include "gdbsupport/gdb_tilde_expand.h" + +namespace selftests { +namespace gdb_tilde_expand_tests { + +static void +do_test () +{ + std::string ret = gdb_tilde_expand ("~"); + ret = gdb_tilde_expand ("~/non/existent/directory"); +} + +} /* namespace gdb_tilde_expand_tests */ +} /* namespace selftests */ + +void _initialize_gdb_tilde_expand_selftests (); +void +_initialize_gdb_tilde_expand_selftests () +{ + selftests::register_test + ("gdb_tilde_expand", selftests::gdb_tilde_expand_tests::do_test); +} -- 2.29.2