|
60 | 60 | # Some versions of readline inspect LS_COLORS, so for luck unset that too.
|
61 | 61 | delete $ENV{LS_COLORS};
|
62 | 62 |
|
| 63 | +# In a VPATH build, we'll be started in the source directory, but we want |
| 64 | +# to run in the build directory so that we can use relative paths to |
| 65 | +# access the tmp_check subdirectory; otherwise the output from filename |
| 66 | +# completion tests is too variable. |
| 67 | +if ($ENV{TESTDIR}) |
| 68 | +{ |
| 69 | + chdir $ENV{TESTDIR} or die "could not chdir to \"$ENV{TESTDIR}\": $!"; |
| 70 | +} |
| 71 | + |
| 72 | +# Create some junk files for filename completion testing. |
| 73 | +my $FH; |
| 74 | +open $FH, ">", "tmp_check/somefile" |
| 75 | + or die("could not create file \"tmp_check/somefile\": $!"); |
| 76 | +print $FH "some stuff\n"; |
| 77 | +close $FH; |
| 78 | +open $FH, ">", "tmp_check/afile123" |
| 79 | + or die("could not create file \"tmp_check/afile123\": $!"); |
| 80 | +print $FH "more stuff\n"; |
| 81 | +close $FH; |
| 82 | +open $FH, ">", "tmp_check/afile456" |
| 83 | + or die("could not create file \"tmp_check/afile456\": $!"); |
| 84 | +print $FH "other stuff\n"; |
| 85 | +close $FH; |
| 86 | + |
63 | 87 | # fire up an interactive psql session
|
64 | 88 | my $in = '';
|
65 | 89 | my $out = '';
|
@@ -104,6 +128,15 @@ sub clear_query
|
104 | 128 | return;
|
105 | 129 | }
|
106 | 130 |
|
| 131 | +# Clear current line to start over |
| 132 | +# (this will work in an incomplete string literal, but it's less desirable |
| 133 | +# than clear_query because we lose evidence in the history file) |
| 134 | +sub clear_line |
| 135 | +{ |
| 136 | + check_completion("\025\n", qr/postgres=# /, "control-U works"); |
| 137 | + return; |
| 138 | +} |
| 139 | + |
107 | 140 | # check basic command completion: SEL<tab> produces SELECT<space>
|
108 | 141 | check_completion("SEL\t", qr/SELECT /, "complete SEL<tab> to SELECT");
|
109 | 142 |
|
@@ -142,6 +175,47 @@ sub clear_query
|
142 | 175 |
|
143 | 176 | clear_query();
|
144 | 177 |
|
| 178 | +# check filename completion |
| 179 | +check_completion( |
| 180 | + "\\lo_import tmp_check/some\t", |
| 181 | + qr|tmp_check/somefile |, |
| 182 | + "filename completion with one possibility"); |
| 183 | + |
| 184 | +clear_query(); |
| 185 | + |
| 186 | +# note: readline might print a bell before the completion |
| 187 | +check_completion( |
| 188 | + "\\lo_import tmp_check/af\t", |
| 189 | + qr|tmp_check/af\a?ile|, |
| 190 | + "filename completion with multiple possibilities"); |
| 191 | + |
| 192 | +clear_query(); |
| 193 | + |
| 194 | +# COPY requires quoting |
| 195 | +# note: broken versions of libedit want to backslash the closing quote; |
| 196 | +# not much we can do about that |
| 197 | +check_completion( |
| 198 | + "COPY foo FROM tmp_check/some\t", |
| 199 | + qr|'tmp_check/somefile\\?' |, |
| 200 | + "quoted filename completion with one possibility"); |
| 201 | + |
| 202 | +clear_line(); |
| 203 | + |
| 204 | +check_completion( |
| 205 | + "COPY foo FROM tmp_check/af\t", |
| 206 | + <
8E05
span class="pl-pds">qr|'tmp_check/afile|, |
| 207 | + "quoted filename completion with multiple possibilities"); |
| 208 | + |
| 209 | +# some versions of readline/libedit require two tabs here, some only need one |
| 210 | +# also, some will offer the whole path name and some just the file name |
| 211 | +# the quotes might appear, too |
| 212 | +check_completion( |
| 213 | + "\t\t", |
| 214 | + qr|afile123'? +'?(tmp_check/)?afile456|, |
| 215 | + "offer multiple file choices"); |
| 216 | + |
| 217 | +clear_line(); |
| 218 | + |
145 | 219 | # send psql an explicit \q to shut it down, else pty won't close properly
|
146 | 220 | $timer->start(5);
|
147 | 221 | $in .= "\\q\n";
|
|
0 commit comments