From: Tom Tromey <tom@tromey.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFC 3/6] Move mkdir_recursive to common/filestuff.c
Date: Wed, 26 Sep 2018 23:16:00 -0000 [thread overview]
Message-ID: <8736tvkg0a.fsf@tromey.com> (raw)
In-Reply-To: <877ej7kixp.fsf@tromey.com> (Tom Tromey's message of "Wed, 26 Sep 2018 16:11:46 -0600")
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:
Tom> I forgot to git add this file.
Tom> I'll send it soon.
This is just the missing part of this patch.
Tom
commit 7c8093b561466131da4fd9ad30d93b3640615426
Author: Tom Tromey <tom@tromey.com>
Date: Wed Sep 26 16:16:55 2018 -0600
add the test
diff --git a/gdb/unittests/mkdir-recursive-selftests.c b/gdb/unittests/mkdir-recursive-selftests.c
new file mode 100644
index 0000000000..d501f8e081
--- /dev/null
+++ b/gdb/unittests/mkdir-recursive-selftests.c
@@ -0,0 +1,89 @@
+/* Self tests for scoped_fd for GDB, the GNU debugger.
+
+ Copyright (C) 2018 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 "defs.h"
+
+#include "common/filestuff.h"
+#include "selftest.h"
+
+namespace selftests {
+namespace mkdir_recursive {
+
+/* Try to create DIR using mkdir_recursive and make sure it exists. */
+
+static bool
+create_dir_and_check (const char *dir)
+{
+ ::mkdir_recursive (dir);
+
+ struct stat st;
+ if (stat (dir, &st) != 0)
+ perror_with_name (("stat"));
+
+ return (st.st_mode & S_IFDIR) != 0;
+}
+
+/* Test mkdir_recursive. */
+
+static void
+test ()
+{
+ char base[] = "/tmp/gdb-selftests-XXXXXX";
+
+ if (mkdtemp (base) == NULL)
+ perror_with_name (("mkdtemp"));
+
+ /* Try not to leave leftover directories. */
+ struct cleanup_dirs {
+ cleanup_dirs (const char *base)
+ : m_base (base)
+ {}
+
+ ~cleanup_dirs () {
+ rmdir (string_printf ("%s/a/b/c/d/e", m_base).c_str ());
+ rmdir (string_printf ("%s/a/b/c/d", m_base).c_str ());
+ rmdir (string_printf ("%s/a/b/c", m_base).c_str ());
+ rmdir (string_printf ("%s/a/b", m_base).c_str ());
+ rmdir (string_printf ("%s/a", m_base).c_str ());
+ rmdir (m_base);
+ }
+
+ private:
+ const char *m_base;
+ } cleanup_dirs (base);
+
+ std::string dir = string_printf ("%s/a/b", base);
+ SELF_CHECK (create_dir_and_check (dir.c_str ()));
+
+ dir = string_printf ("%s/a/b/c//d/e/", base);
+ SELF_CHECK (create_dir_and_check (dir.c_str ()));
+}
+
+}
+}
+
+void
+_initialize_mkdir_recursive_selftests ()
+{
+#if defined (HAVE_MKDTEMP)
+ selftests::register_test ("mkdir_recursive",
+ selftests::mkdir_recursive::test);
+#endif
+}
+
next prev parent reply other threads:[~2018-09-26 23:16 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-26 11:12 [RFC 0/6] A different approach to startup-with-shell on macOS Tom Tromey
2018-09-26 11:11 ` [RFC 1/6] Unify shell-finding logic Tom Tromey
2018-09-28 21:39 ` Simon Marchi
2018-09-26 11:12 ` [RFC 4/6] Use mkostemp, not mkstemp Tom Tromey
2018-09-29 3:09 ` Simon Marchi
2018-09-29 12:49 ` Tom Tromey
2018-09-29 14:04 ` Simon Marchi
2018-09-26 11:12 ` [RFC 2/6] Move make_temp_filename to common/pathstuff.c Tom Tromey
2018-09-26 11:12 ` [RFC 5/6] Do not reopen temporary files Tom Tromey
2018-09-26 14:12 ` Eli Zaretskii
2018-09-26 21:44 ` Tom Tromey
2018-09-29 3:22 ` Simon Marchi
2018-10-01 9:15 ` Tom Tromey
2018-09-26 11:20 ` [RFC 6/6] Cache a copy of the user's shell on macOS Tom Tromey
2018-09-29 3:37 ` Simon Marchi
2018-10-01 19:27 ` Tom Tromey
2018-10-01 19:31 ` Simon Marchi
2018-09-26 11:20 ` [RFC 3/6] Move mkdir_recursive to common/filestuff.c Tom Tromey
2018-09-26 22:11 ` Tom Tromey
2018-09-26 23:16 ` Tom Tromey [this message]
2018-09-28 21:21 ` [RFC 0/6] A different approach to startup-with-shell on macOS Simon Marchi
2018-09-29 18:43 ` Pedro Alves
2018-09-29 19:50 ` Simon Marchi
2018-09-29 20:38 ` Pedro Alves
2018-10-01 9:12 ` Tom Tromey
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=8736tvkg0a.fsf@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/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