| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include "gdbsupport/selftest.h" |
| 21 |
#include <cstdlib> |
| 22 |
|
| 23 |
#include "gdbsupport/gdb_tilde_expand.h" |
| 24 |
|
| 25 |
namespace selftests { |
| 26 |
namespace gdb_tilde_expand_tests { |
| 27 |
|
| 28 |
static void |
| 29 |
do_test () |
| 30 |
{ |
| 31 |
|
| 32 |
const char *c_home = std::getenv ("HOME"); |
| 33 |
|
| 34 |
|
| 35 |
if (c_home == nullptr) |
| 36 |
return; |
| 37 |
|
| 38 |
const std::string home (c_home); |
| 39 |
|
| 40 |
|
| 41 |
SELF_CHECK (home == gdb_tilde_expand ("~")); |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
SELF_CHECK (gdb_tilde_expand ("~/non/existent/directory") |
| 47 |
== home + "/non/existent/directory"); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
SELF_CHECK (gdb_tilde_expand ("~/*/a.out") == home + "/*/a.out"); |
| 52 |
|
| 53 |
|
| 54 |
SELF_CHECK (gdb_tilde_expand ("/some/abs/path") == "/some/abs/path"); |
| 55 |
SELF_CHECK (gdb_tilde_expand ("relative/path") == "relative/path"); |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
const char *c_user = std::getenv ("USER"); |
| 60 |
if (c_user != nullptr) |
| 61 |
{ |
| 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"); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
try |
| 71 |
{ |
| 72 |
gdb_tilde_expand ("~no_one_should_have_that_login/a"); |
| 73 |
SELF_CHECK (false); |
| 74 |
} |
| 75 |
catch (const gdb_exception_error &e) |
| 76 |
{ |
| 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'."); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
void _initialize_gdb_tilde_expand_selftests (); |
| 88 |
void |
| 89 |
_initialize_gdb_tilde_expand_selftests () |
| 90 |
{ |
| 91 |
selftests::register_test |
| 92 |
("gdb_tilde_expand", selftests::gdb_tilde_expand_tests::do_test); |
| 93 |
} |