1 1.1 christos # Copyright 2024 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 # Tests for filename completion. Create a directory tree on the test 17 1.1 christos # machine and try completing filenames within the tree. 18 1.1 christos 19 1.1 christos load_lib completion-support.exp 20 1.1 christos 21 1.1 christos # Setup a directory tree in which completion tests can be run. The 22 1.1 christos # structure is: 23 1.1 christos # 24 1.1 christos # root/ [ DIRECTORY ] 25 1.1 christos # aaa/ [ DIRECTORY ] 26 1.1 christos # bb1/ [ DIRECTORY ] 27 1.1 christos # bb2/ [ DIRECTORY ] 28 1.1 christos # cc1/ [ DIRECTORY ] 29 1.1 christos # cc2 [ FILE ] 30 1.1 christos proc setup_directory_tree {} { 31 1.1 christos set root [standard_output_file "root"] 32 1.1 christos 33 1.1 christos remote_exec host "mkdir -p ${root}" 34 1.1 christos remote_exec host "mkdir -p ${root}/aaa" 35 1.1 christos remote_exec host "mkdir -p ${root}/bb1" 36 1.1 christos remote_exec host "mkdir -p ${root}/bb2" 37 1.1 christos remote_exec host "mkdir -p ${root}/cc1" 38 1.1 christos remote_exec host "touch ${root}/cc2" 39 1.1 christos 40 1.1 christos remote_exec host "touch \"${root}/aaa/aa bb\"" 41 1.1 christos remote_exec host "touch \"${root}/aaa/aa cc\"" 42 1.1 christos 43 1.1 christos return $root 44 1.1 christos } 45 1.1 christos 46 1.1 christos # Run filename completetion tests. ROOT is the base directory as 47 1.1 christos # returned from setup_directory_tree, though, if ROOT is a 48 1.1 christos # sub-directory of the user's home directory ROOT might have been 49 1.1 christos # modified to replace the $HOME prefix with a single "~" character. 50 1.1 christos proc run_tests { root } { 51 1.1 christos 52 1.1 christos # Completing 'thread apply all ...' commands uses a custom word 53 1.1 christos # point. At one point we had a bug where doing this would break 54 1.1 christos # completion of quoted filenames that contained white space. 55 1.1 christos test_gdb_complete_unique "thread apply all hel" \ 56 1.1 christos "thread apply all help" " " false \ 57 1.1 christos "complete a 'thread apply all' command" 58 1.1 christos 59 1.1 christos foreach_with_prefix qc [list "" "'" "\""] { 60 1.1 christos test_gdb_complete_none "file ${qc}${root}/xx" \ 61 1.1 christos "expand a non-existent filename" 62 1.1 christos 63 1.1 christos test_gdb_complete_unique "file ${qc}${root}/a" \ 64 1.1 christos "file ${qc}${root}/aaa/" "" false \ 65 1.1 christos "expand a unique filename" 66 1.1 christos 67 1.1 christos test_gdb_complete_multiple "file ${qc}${root}/" \ 68 1.1 christos "b" "b" { 69 1.1 christos "bb1/" 70 1.1 christos "bb2/" 71 1.1 christos } "" "${qc}" false \ 72 1.1 christos "expand multiple directory names" 73 1.1 christos 74 1.1 christos test_gdb_complete_multiple "file ${qc}${root}/" \ 75 1.1 christos "c" "c" { 76 1.1 christos "cc1/" 77 1.1 christos "cc2" 78 1.1 christos } "" "${qc}" false \ 79 1.1 christos "expand mixed directory and file names" 80 1.1 christos 81 1.1 christos # GDB does not currently escape word break characters 82 1.1 christos # (e.g. white space) correctly in unquoted filenames. 83 1.1 christos if { $qc ne "" } { 84 1.1 christos set sp " " 85 1.1 christos 86 1.1 christos test_gdb_complete_multiple "file ${qc}${root}/aaa/" \ 87 1.1 christos "a" "a${sp}" { 88 1.1 christos "aa bb" 89 1.1 christos "aa cc" 90 1.1 christos } "" "${qc}" false \ 91 1.1 christos "expand filenames containing spaces" 92 1.1 christos } 93 1.1 christos } 94 1.1 christos } 95 1.1 christos 96 1.1 christos gdb_start 97 1.1 christos 98 1.1 christos set root [setup_directory_tree] 99 1.1 christos 100 1.1 christos run_tests $root 101 1.1 christos 102 1.1 christos # This test relies on using the $HOME directory. We could make this 103 1.1 christos # work for remote hosts, but right now, this isn't supported. 104 1.1 christos if {![is_remote host]} { 105 1.1 christos 106 1.1 christos # The users home directory. 107 1.1 christos set home $::env(HOME) 108 1.1 christos 109 1.1 christos # Check if ROOT is within the $HOME directory. If it is then we can 110 1.1 christos # rerun the tests, but replacing the $HOME part with "~". 111 1.1 christos if { [string compare -length [string length $home] $root $home] == 0 } { 112 1.1 christos # Convert the $HOME prefix in to ~. 113 1.1 christos set tilde_root "~[string range $root [string length $home] end]" 114 1.1 christos 115 1.1 christos with_test_prefix "with tilde" { 116 1.1 christos # And rerun the tests. 117 1.1 christos run_tests $tilde_root 118 1.1 christos } 119 1.1 christos } 120 1.1 christos } 121