Home | History | Annotate | Line # | Download | only in gdb.base
filename-completion.exp revision 1.1.1.1
      1 # Copyright 2024 Free Software Foundation, Inc.
      2 
      3 # This program is free software; you can redistribute it and/or modify
      4 # it under the terms of the GNU General Public License as published by
      5 # the Free Software Foundation; either version 3 of the License, or
      6 # (at your option) any later version.
      7 #
      8 # This program is distributed in the hope that it will be useful,
      9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11 # GNU General Public License for more details.
     12 #
     13 # You should have received a copy of the GNU General Public License
     14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15 
     16 # Tests for filename completion.  Create a directory tree on the test
     17 # machine and try completing filenames within the tree.
     18 
     19 load_lib completion-support.exp
     20 
     21 # Setup a directory tree in which completion tests can be run.  The
     22 # structure is:
     23 #
     24 # root/			[ DIRECTORY ]
     25 #   aaa/		[ DIRECTORY ]
     26 #   bb1/		[ DIRECTORY ]
     27 #   bb2/		[ DIRECTORY ]
     28 #   cc1/		[ DIRECTORY ]
     29 #   cc2			[ FILE ]
     30 proc setup_directory_tree {} {
     31     set root [standard_output_file "root"]
     32 
     33     remote_exec host "mkdir -p ${root}"
     34     remote_exec host "mkdir -p ${root}/aaa"
     35     remote_exec host "mkdir -p ${root}/bb1"
     36     remote_exec host "mkdir -p ${root}/bb2"
     37     remote_exec host "mkdir -p ${root}/cc1"
     38     remote_exec host "touch ${root}/cc2"
     39 
     40     remote_exec host "touch \"${root}/aaa/aa bb\""
     41     remote_exec host "touch \"${root}/aaa/aa cc\""
     42 
     43     return $root
     44 }
     45 
     46 # Run filename completetion tests.  ROOT is the base directory as
     47 # returned from setup_directory_tree, though, if ROOT is a
     48 # sub-directory of the user's home directory ROOT might have been
     49 # modified to replace the $HOME prefix with a single "~" character.
     50 proc run_tests { root } {
     51 
     52     # Completing 'thread apply all ...' commands uses a custom word
     53     # point.  At one point we had a bug where doing this would break
     54     # completion of quoted filenames that contained white space.
     55     test_gdb_complete_unique "thread apply all hel" \
     56 	"thread apply all help" " " false \
     57 	"complete a 'thread apply all' command"
     58 
     59     foreach_with_prefix qc [list "" "'" "\""] {
     60 	test_gdb_complete_none "file ${qc}${root}/xx" \
     61 	    "expand a non-existent filename"
     62 
     63 	test_gdb_complete_unique "file ${qc}${root}/a" \
     64 	    "file ${qc}${root}/aaa/" "" false \
     65 	    "expand a unique filename"
     66 
     67 	test_gdb_complete_multiple "file ${qc}${root}/" \
     68 	    "b" "b" {
     69 		"bb1/"
     70 		"bb2/"
     71 	    } "" "${qc}" false \
     72 	    "expand multiple directory names"
     73 
     74 	test_gdb_complete_multiple "file ${qc}${root}/" \
     75 	    "c" "c" {
     76 		"cc1/"
     77 		"cc2"
     78 	    } "" "${qc}" false \
     79 	    "expand mixed directory and file names"
     80 
     81 	# GDB does not currently escape word break characters
     82 	# (e.g. white space) correctly in unquoted filenames.
     83 	if { $qc ne "" } {
     84 	    set sp " "
     85 
     86 	    test_gdb_complete_multiple "file ${qc}${root}/aaa/" \
     87 		"a" "a${sp}" {
     88 		    "aa bb"
     89 		    "aa cc"
     90 		} "" "${qc}" false \
     91 		"expand filenames containing spaces"
     92 	}
     93     }
     94 }
     95 
     96 gdb_start
     97 
     98 set root [setup_directory_tree]
     99 
    100 run_tests $root
    101 
    102 # This test relies on using the $HOME directory.  We could make this
    103 # work for remote hosts, but right now, this isn't supported.
    104 if {![is_remote host]} {
    105 
    106     # The users home directory.
    107     set home $::env(HOME)
    108 
    109     # Check if ROOT is within the $HOME directory.  If it is then we can
    110     # rerun the tests, but replacing the $HOME part with "~".
    111     if { [string compare -length [string length $home] $root $home] == 0 } {
    112 	# Convert the $HOME prefix in to ~.
    113 	set tilde_root "~[string range $root [string length $home] end]"
    114 
    115 	with_test_prefix "with tilde" {
    116 	    # And rerun the tests.
    117 	    run_tests $tilde_root
    118 	}
    119     }
    120 }
    121