1 /* Self tests for lookup_name_info for GDB, the GNU debugger.
3 Copyright (C) 2017-2019 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/>. */
21 #include "common/selftest.h"
25 namespace lookup_name
{
27 /* Check that removing parameter info out of NAME produces EXPECTED.
28 COMPLETION_MODE indicates whether we're testing normal and
29 completion mode. FILE and LINE are used to provide better test
30 location information in case the check fails. */
33 check_make_paramless (const char *file
, int line
,
35 const char *name
, const char *expected
,
38 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
,
39 completion_mode
, true /* ignore_parameters */);
40 const std::string
&result
= lookup_name
.language_lookup_name (lang
);
42 if (result
!= expected
)
44 error (_("%s:%d: make-paramless self-test failed: (completion=%d, lang=%d) "
45 "\"%s\" -> \"%s\", expected \"%s\""),
46 file
, line
, completion_mode
, lang
, name
,
47 result
.c_str (), expected
);
54 /* Helper for CHECK and CHECK_INCOMPL. */
55 #define CHECK_1(INCOMPLETE, LANG, NAME, EXPECTED) \
58 check_make_paramless (__FILE__, __LINE__, \
60 (INCOMPLETE) ? "" : (EXPECTED), false); \
61 check_make_paramless (__FILE__, __LINE__, \
62 LANG, NAME, EXPECTED, true); \
66 /* Check that removing parameter info out of NAME produces EXPECTED.
67 Checks both normal and completion modes. */
68 #define CHECK(LANG, NAME, EXPECTED) \
69 CHECK_1(false, LANG, NAME, EXPECTED)
71 /* Similar, but used when NAME is incomplete -- i.e., NAME has
72 unbalanced parentheses. In this case, looking for the exact name
73 should fail / return empty. */
74 #define CHECK_INCOMPL(LANG, NAME, EXPECTED) \
75 CHECK_1 (true, LANG, NAME, EXPECTED)
77 /* None of these languages support function overloading like C++
78 does, so building a nameless lookup name ends up being just the
79 same as any other lookup name. Mainly this serves as smoke test
80 that C++-specific code doesn't mess up with other languages that
81 use some other scoping character ('.' vs '::'). */
82 CHECK (language_ada
, "pck.ada_hello", "pck__ada_hello");
83 CHECK (language_go
, "pck.go_hello", "pck.go_hello");
84 CHECK (language_fortran
, "mod::func", "mod::func");
86 /* D does support function overloading similar to C++, but we're
87 missing support for stripping parameters. At least make sure the
88 input name is preserved unmodified. */
89 CHECK (language_d
, "pck.d_hello", "pck.d_hello");
91 /* Just a few basic tests to make sure
92 lookup_name_info::make_paramless is well integrated with
93 cp_remove_params_if_any. gdb/cp-support.c has comprehensive
94 testing of C++ specifics. */
95 CHECK (language_cplus
, "function()", "function");
96 CHECK (language_cplus
, "function() const", "function");
97 CHECK (language_cplus
, "A::B::C()", "A::B::C");
98 CHECK (language_cplus
, "A::B::C", "A::B::C");
104 }} // namespace selftests::lookup_name
107 _initialize_lookup_name_info_selftests ()
109 selftests::register_test ("lookup_name_info",
110 selftests::lookup_name::run_tests
);