Home | History | Annotate | Line # | Download | only in gdb.cp
maint.exp revision 1.10
      1  1.10  christos # Copyright 2003-2023 Free Software Foundation, Inc.
      2   1.1  christos 
      3   1.1  christos # This program is free software; you can redistribute it and/or modify
      4   1.1  christos # it under the terms of the GNU General Public License as published by
      5   1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6   1.1  christos # (at your option) any later version.
      7   1.1  christos #
      8   1.1  christos # This program is distributed in the hope that it will be useful,
      9   1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10   1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11   1.1  christos # GNU General Public License for more details.
     12   1.1  christos #
     13   1.1  christos # You should have received a copy of the GNU General Public License
     14   1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15   1.1  christos 
     16   1.1  christos 
     17   1.1  christos # This file tests C++-specific maintenance commands and help on those.
     18   1.1  christos 
     19   1.1  christos # Currently, no source file is used.
     20   1.1  christos 
     21   1.1  christos # Test the help messages.
     22   1.1  christos 
     23   1.1  christos proc test_help {} {
     24   1.1  christos     set first_component_help "Print the first class/namespace component of NAME"
     25   1.1  christos     set namespace_help "Deprecated placeholder for removed functionality."
     26   1.1  christos 
     27   1.1  christos     test_prefix_command_help {"maintenance cplus"} {
     28   1.1  christos         "C\\+\\+ maintenance commands\.\[\r\n\]+"
     29   1.1  christos     }
     30   1.1  christos 
     31   1.1  christos     test_prefix_command_help {"maint cp" "maintenance cplus"} {
     32   1.1  christos         "C\\+\\+ maintenance commands.\r\n\r\n"
     33   1.1  christos     }
     34   1.1  christos 
     35   1.9  christos     set multiple_help_body "List of maintenance cplus subcommands:.*Command name abbreviations are allowed if unambiguous."
     36   1.1  christos 
     37   1.9  christos     gdb_test "maint cp" $multiple_help_body
     38   1.1  christos 
     39   1.1  christos     gdb_test "help maint cp first_component" "${first_component_help}."
     40   1.1  christos     gdb_test "help maint cp namespace" "${namespace_help}."
     41   1.1  christos }
     42   1.1  christos 
     43   1.1  christos # This is used when NAME should contain only a single component.  Be
     44   1.1  christos # careful to make sure that parentheses get escaped properly.
     45   1.1  christos proc test_single_component {name} {
     46   1.1  christos     set matchname [string_to_regexp "$name"]
     47   1.1  christos     gdb_test "maint cp first_component $name" "$matchname"
     48   1.1  christos }
     49   1.1  christos 
     50   1.1  christos # This is used when NAME is invalid.
     51   1.1  christos proc test_invalid_name {name} {
     52   1.1  christos     set matchname [string_to_regexp "$name"]
     53   1.1  christos     gdb_test "maint cp first_component $name" \
     54   1.8  christos 	"During symbol reading: unexpected demangled name '$matchname'\r\n$matchname"
     55   1.1  christos }
     56   1.1  christos 
     57   1.1  christos proc test_first_component {} {
     58   1.1  christos     # The function in question might complain; make sure that we see
     59   1.1  christos     # all complaints.
     60   1.1  christos 
     61   1.1  christos     gdb_test_no_output "set complaints 1000"
     62   1.1  christos 
     63   1.1  christos     test_single_component "foo"
     64  1.10  christos 
     65  1.10  christos     foreach spc [list "" " " "  "] {
     66  1.10  christos 	test_single_component "operator${spc}<<"
     67  1.10  christos 	test_single_component "operator${spc}>>"
     68  1.10  christos 	test_single_component "operator${spc}->"
     69  1.10  christos 	test_single_component "operator${spc}()"
     70  1.10  christos 	test_single_component "operator${spc}>"
     71  1.10  christos 	test_single_component "operator${spc}<"
     72  1.10  christos 
     73  1.10  christos 	test_single_component "foo${spc}()"
     74  1.10  christos 	test_single_component "foo${spc}(int)"
     75  1.10  christos 	test_single_component "foo${spc}(X::Y)"
     76  1.10  christos 	test_single_component "foo${spc}(X::Y, A::B)"
     77  1.10  christos 	test_single_component "foo${spc}(std::basic_streambuf<wchar_t,std::char_traits<wchar_t> >)"
     78  1.10  christos 	test_single_component "operator>${spc}(X::Y)"
     79  1.10  christos     }
     80   1.1  christos 
     81   1.1  christos     # Operator names can show up in weird places.
     82   1.1  christos 
     83   1.1  christos     test_single_component "int operator<< <char>()"
     84   1.1  christos     test_single_component "T<Cooperator>"
     85   1.1  christos 
     86   1.1  christos     # NOTE: carlton/2003-04-23: I've only seen the first of these
     87   1.1  christos     # produced by the demangler, but I'm including two more just to be
     88   1.1  christos     # on the safe side.
     89   1.1  christos     test_single_component "int foo<&(operator<<(C, C))>()"
     90   1.1  christos     test_single_component "int foo<&operator<<(C, C)>()"
     91   1.1  christos     test_single_component "int foo<operator<<(C, C)>()"
     92   1.1  christos 
     93   1.1  christos     gdb_test "maint cp first_component foo::bar" "foo"
     94   1.1  christos     gdb_test "maint cp first_component foo::bar::baz" "foo"
     95   1.1  christos     gdb_test "maint cp first_component C<A>::bar" "C<A>"
     96   1.1  christos     gdb_test "maint cp first_component C<std::basic_streambuf<wchar_t,std::char_traits<wchar_t> > >::bar" "C<std::basic_streambuf<wchar_t,std::char_traits<wchar_t> > >"
     97   1.1  christos 
     98   1.1  christos     # Make sure we behave appropriately on invalid input.
     99   1.1  christos 
    100   1.1  christos     # NOTE: carlton/2003-06-25: As of today, the demangler can in fact
    101   1.1  christos     # produce examples like the third case below: there really should
    102   1.1  christos     # be a space between the two <'s.  See PR gdb/1245.
    103   1.1  christos 
    104   1.1  christos     test_invalid_name "foo<"
    105   1.1  christos     test_invalid_name "foo("
    106   1.1  christos     test_invalid_name "bool operator<<char>"
    107   1.1  christos }
    108   1.1  christos 
    109   1.1  christos proc test_namespace {} {
    110   1.1  christos     gdb_test "maint cp namespace" "The `maint namespace' command was removed."
    111   1.1  christos }
    112   1.1  christos 
    113   1.1  christos gdb_exit
    114   1.1  christos gdb_start
    115   1.1  christos 
    116   1.1  christos test_help
    117   1.1  christos test_first_component
    118   1.1  christos test_namespace
    119   1.1  christos 
    120   1.1  christos gdb_exit
    121   1.1  christos return 0
    122