arm, objdump: print obsolote warning when 26-bit set in instructions
[binutils-gdb.git] / gdb / unittests / gdb_tilde_expand-selftests.c
blob165885f361b94feffdab6955ea9c5ec108c5fbb0
1 /* Self tests for gdb_tilde_expand
3 Copyright (C) 2021-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "gdbsupport/selftest.h"
21 #include <cstdlib>
23 #include "gdbsupport/gdb_tilde_expand.h"
25 namespace selftests {
26 namespace gdb_tilde_expand_tests {
28 static void
29 do_test ()
31 /* Home directory of the user running the test. */
32 const char *c_home = std::getenv ("HOME");
34 /* Skip the test if $HOME is not available in the environment. */
35 if (c_home == nullptr)
36 return;
38 const std::string home (c_home);
40 /* Basic situation. */
41 SELF_CHECK (home == gdb_tilde_expand ("~"));
43 /* When given a path that begins by a tilde and refers to a file that
44 does not exist, gdb_tilde expand must still be able to do the tilde
45 expansion. */
46 SELF_CHECK (gdb_tilde_expand ("~/non/existent/directory")
47 == home + "/non/existent/directory");
49 /* gdb_tilde_expand only expands tilde and does not try to do any other
50 substitution. */
51 SELF_CHECK (gdb_tilde_expand ("~/*/a.out") == home + "/*/a.out");
53 /* gdb_tilde_expand does no modification to a non tilde leading path. */
54 SELF_CHECK (gdb_tilde_expand ("/some/abs/path") == "/some/abs/path");
55 SELF_CHECK (gdb_tilde_expand ("relative/path") == "relative/path");
57 /* If $USER is available in the env variables, check the '~user'
58 expansion. */
59 const char *c_user = std::getenv ("USER");
60 if (c_user != nullptr)
62 const std::string user (c_user);
63 SELF_CHECK (gdb_tilde_expand (("~" + user).c_str ()) == home);
64 SELF_CHECK (gdb_tilde_expand (("~" + user + "/a/b").c_str ())
65 == home + "/a/b");
68 /* Check that an error is thrown when trying to expand home of a unknown
69 user. */
70 try
72 gdb_tilde_expand ("~no_one_should_have_that_login/a");
73 SELF_CHECK (false);
75 catch (const gdb_exception_error &e)
77 SELF_CHECK (e.error == GENERIC_ERROR);
78 SELF_CHECK
79 (*e.message
80 == "Could not find a match for '~no_one_should_have_that_login'.");
84 } /* namespace gdb_tilde_expand_tests */
85 } /* namespace selftests */
87 void _initialize_gdb_tilde_expand_selftests ();
88 void
89 _initialize_gdb_tilde_expand_selftests ()
91 selftests::register_test
92 ("gdb_tilde_expand", selftests::gdb_tilde_expand_tests::do_test);