From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: Lancelot SIX <lsix@lancelotsix.com>,
Andrew Burgess <andrew.burgess@embecosm.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Improve gdb_tilde_expand logic
Date: Fri, 8 Jan 2021 21:17:26 -0500 [thread overview]
Message-ID: <4016e225-2024-3f95-5be8-d0970f166193@polymtl.ca> (raw)
In-Reply-To: <8fdb8080-ae0b-70ae-20ab-e84329590bea@lancelotsix.com>
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 <simon.marchi@polymtl.ca>
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 <http://www.gnu.org/licenses/>. */
+
+#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
next prev parent reply other threads:[~2021-01-09 2:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-08 0:13 Lancelot SIX via Gdb-patches
2021-01-08 9:30 ` Andrew Burgess
2021-01-08 15:59 ` Simon Marchi via Gdb-patches
2021-01-09 1:33 ` Lancelot SIX via Gdb-patches
2021-01-09 2:17 ` Simon Marchi via Gdb-patches [this message]
2021-01-09 18:29 ` [PATCH v2] " Lancelot SIX via Gdb-patches
2021-01-10 23:20 ` Sergio Durigan Junior via Gdb-patches
2021-01-11 0:23 ` Lancelot SIX via Gdb-patches
2021-01-11 1:00 ` [PATCH v3] " Lancelot SIX via Gdb-patches
2021-01-11 17:11 ` Simon Marchi via Gdb-patches
2021-01-11 22:40 ` [PATCH v4] " Lancelot SIX via Gdb-patches
2021-01-11 23:36 ` Simon Marchi via Gdb-patches
2021-01-14 23:04 ` Lancelot SIX via Gdb-patches
2021-01-23 17:40 ` Lancelot SIX via Gdb-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4016e225-2024-3f95-5be8-d0970f166193@polymtl.ca \
--to=gdb-patches@sourceware.org \
--cc=andrew.burgess@embecosm.com \
--cc=lsix@lancelotsix.com \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox