fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
2c17c96e5
master
1#RUN: fish=%fish %fish %s 2 3function complete_test_alpha1 4echo $argv 5end 6 7complete -c complete_test_alpha1 --no-files -a'(commandline)' 8complete -c complete_test_alpha2 --no-files -w'complete_test_alpha1 extra1' 9complete -c complete_test_alpha3 --no-files -w'complete_test_alpha2 extra2' 10 11complete -C'complete_test_alpha1 arg1 ' 12# CHECK: complete_test_alpha1 arg1 13complete --escape -C'complete_test_alpha1 arg1 ' 14# CHECK: complete_test_alpha1\ arg1\{{ }} 15complete -C'complete_test_alpha2 arg2 ' 16# CHECK: complete_test_alpha1 extra1 arg2 17complete -C'complete_test_alpha3 arg3 ' 18# CHECK: complete_test_alpha1 extra1 extra2 arg3 19# Works even with the argument as a separate token. 20complete -C'complete_test_alpha3 arg3 ' 21# CHECK: complete_test_alpha1 extra1 extra2 arg3 22 23alias myalias1'complete_test_alpha1 arg1' 24alias myalias2='complete_test_alpha1 arg2' 25 26myalias1 call1 27myalias2 call2 28# CHECK: arg1 call1 29# CHECK: arg2 call2 30complete -C'myalias1 call3 ' 31complete -C'myalias2 call3 ' 32# CHECK: complete_test_alpha1 arg1 call3 33# CHECK: complete_test_alpha1 arg2 call3 34 35# Ensure that commands can't wrap themselves - if this did, 36# the completion would be executed a bunch of times. 37function t --wraps t 38echo t 39end 40complete -c t -fa'(t)' 41complete -C't ' 42# CHECK: t 43 44touch test.fish 45 46# Ensure file completion happens even though it was disabled above. 47complete -c t -l fileoption -rF 48# Only match one file because I don't want to touch this any time we add a test file. 49complete -C't --fileoption ' | string match test.fish 50# CHECK: test.fish 51 52# See that an empty command gets files 53complete -C'"" t' | string match test.fish 54# CHECK: test.fish 55 56# Make sure bare `complete` is reasonable, 57complete -p'/complete test/beta1' -d'desc, desc' -sZ 58complete -c'complete test beta2' -r -d'desc \' desc2 [' -a'foo bar' 59complete -c complete_test_beta2 -x -n false -A -o test 60complete 61 62# CHECK: complete --no-files complete_test_alpha1 -a '(commandline)' 63# CHECK: complete --no-files complete_test_alpha2 64# CHECK: complete --no-files complete_test_alpha3 65# CHECK: complete --force-files t -l fileoption 66# CHECK: complete --no-files t -a '(t)' 67# CHECK: complete -p '/complete test/beta1' -s Z -d 'desc, desc' 68# CHECK: complete --require-parameter 'complete test beta2' -d "desc ' desc2 [" -a 'foo bar' 69# CHECK: complete --exclusive complete_test_beta2 -o test -n false 70# CHECK: complete {{.*}} 71# CHECK: complete {{.*}} 72# CHECK: complete {{.*}} 73# CHECK: complete {{.*}} 74 75# Recursive calls to complete (see #3474) 76complete -c complete_test_recurse1 -xa'(echo recursing 1>&2; complete -C"complete_test_recurse1 ")' 77LANG=C complete -C'complete_test_recurse1 ' 78# CHECKERR: recursing 79# CHECKERR: recursing 80# CHECKERR: recursing 81# CHECKERR: recursing 82# CHECKERR: recursing 83# CHECKERR: recursing 84# CHECKERR: recursing 85# CHECKERR: recursing 86# CHECKERR: recursing 87# CHECKERR: recursing 88# CHECKERR: recursing 89# CHECKERR: recursing 90# CHECKERR: recursing 91# CHECKERR: recursing 92# CHECKERR: recursing 93# CHECKERR: recursing 94# CHECKERR: recursing 95# CHECKERR: recursing 96# CHECKERR: recursing 97# CHECKERR: recursing 98# CHECKERR: recursing 99# CHECKERR: recursing 100# CHECKERR: recursing 101# CHECKERR: recursing 102# CHECKERR: error: completion reached maximum recursion depth, possible cycle? 103 104# short options 105complete -c foo -f -a non-option-argument 106complete -c foo -f --short-option x 107complete -c foo -f --short-option y -a ARGY 108complete -c foo -f --short-option z -a ARGZ -r 109complete -c foo -f --old-option single-long-ending-in-z 110complete -c foo -f --old-option x-single-long 111complete -c foo -f --old-option y-single-long 112complete -c foo -f --old-option z-single-long 113complete -c foo -f --long-option x-long -a ARGLONG 114# Make sure that arguments of concatenated short options are expanded (#332) 115complete -C'foo -xy' 116# CHECK: -xyARGY 117# CHECK: -xyz 118# A required parameter means we don't want more short options. 119complete -C'foo -yz' 120# CHECK: -yzARGZ 121# Required parameter with space: complete only the parameter (no non-option arguments). 122complete -C'foo -xz ' 123# CHECK: ARGZ 124# Optional parameter with space: complete only non-option arguments. 125complete -C'foo -xy ' 126# CHECK: non-option-argument 127complete -C'foo -single-long-ending-in-z' 128# CHECK: -single-long-ending-in-z 129complete -C'foo -single-long-ending-in-z ' 130# CHECK: non-option-argument 131# CHECK: -x-single-long 132complete -C'foo -x' | string match -- -x-single-long 133# CHECK: -y-single-long 134complete -C'foo -y' | string match -- -y-single-long 135# This does NOT suggest -z-single-long, but will probably not occur in practise. 136# CHECK: -zARGZ 137complete -C'foo -z' 138 139function conditional_short_options 140end 141complete -c conditional_short_options -f -n false -s x 142complete -c conditional_short_options -f -s h 143complete -c conditional_short_options -f -s v 144complete -C'conditional_short_options -x' | count 145# CHECK: 0 146complete -C'conditional_short_options -xv' | count 147# CHECK: 0 148complete -C'conditional_short_options -v' 149# CHECK: -vh 150 151function repeated_short_options 152end 153complete -c repeated_short_options -f -s h 154complete -c repeated_short_options -f -s v 155complete -c repeated_short_options -f -s x 156complete -C'repeated_short_options -xx' 157# CHECK: -xxh 158# CHECK: -xxv 159complete -C'repeated_short_options -xxh' 160# CHECK: -xxhv 161complete -C'repeated_short_options -x' 162# CHECK: -xh 163# CHECK: -xv 164 165function foo2 166end 167complete -c foo2 -s s -l long -xa"hello-world goodbye-friend" 168complete -C"foo2 -sfrie" 169# CHECK: -sgoodbye-friend 170complete -C"foo2 --long=frien" 171# CHECK: --long=goodbye-friend 172 173# Builtins (with subcommands; #2705) 174complete -c complete_test_subcommand -n'test (commandline -xp)[1] = complete_test_subcommand' -xa ok 175complete -C'not complete_test_subcommand ' 176# CHECK: ok 177complete -C'echo; and complete_test_subcommand ' 178# CHECK: ok 179complete -C'or complete_test_subcommand ' 180# CHECK: ok 181complete -C'echo && command complete_test_subcommand ' 182# CHECK: ok 183complete -C'echo || exec complete_test_subcommand ' 184# CHECK: ok 185complete -C'echo | builtin complete_test_subcommand ' 186# CHECK: ok 187complete -C'echo & complete_test_subcommand ' 188# CHECK: ok 189complete -C'if while begin begin complete_test_subcommand ' 190# CHECK: ok 191 192complete -C'for _ in ' | string collect>&- && echo completed some files 193# CHECK: completed some files 194 195# function; #5415 196complete -C'function : --arg' 197# CHECK: --argument-names {{.*}} 198 199complete -C'echo > /' | string length -q&& echo ok 200# CHECK: ok 201 202function some_function 203echo line1 204echo line2 205end 206complete -c complete_test_function_desc -xa'(complete -Csome_function)' 207complete -C'complete_test_function_desc ' | count 208# CHECK: 1 209 210complete -c prev-arg-variable -f 211complete -C'prev-arg-variable $HOME ' 212 213# Regression test for issue #3129. In previous versions these statements would 214# cause an `assert()` to fire thus killing the shell. 215complete -c pkill -o'' 216#CHECKERR: complete: -o requires a non-empty string 217complete -c pkill -l'' 218#CHECKERR: complete: -l requires a non-empty string 219complete -c pkill -s'' 220#CHECKERR: complete: -s requires a non-empty string 221 222# Test that conditions that add or remove completions don't deadlock, etc. 223# We actually encountered some case that was effectively like this (Issue 2 in github) 224 225complete --command AAAA -l abcd --condition'complete -c AAAA -l efgh' 226echo "AAAA:" 227complete -C'AAAA -' | sort 228#CHECK: AAAA: 229#CHECK: --abcd 230echo "AAAA:" 231complete -C'AAAA -' | sort 232#CHECK: AAAA: 233#CHECK: --abcd 234#CHECK: --efgh 235 236complete --command BBBB -l abcd --condition'complete -e --command BBBB -l abcd' 237echo "BBBB:" 238complete -C'BBBB -' 239#CHECK: BBBB: 240#CHECK: --abcd 241echo "BBBB:" 242complete -C'BBBB -' 243#CHECK: BBBB: 244#CHECK: 245 246# Test that erasing completions works correctly 247echo 248 249function sort 250# GNU sort is really stupid, a non-C locale seems to make it assume --dictionary-order 251# If I wanted --dictionary-order, I would have specified --dictionary-order! 252env LC_ALL=C sort$argv 253end 254 255complete -c CCCC -l bar 256complete -c CCCC -l baz 257complete -c CCCC -o bar 258complete -c CCCC -o foo 259complete -c CCCC -s a 260complete -c CCCC -s b 261echo "CCCC:" 262complete -C'CCCC -' | sort 263complete -c CCCC -l bar -e 264#CHECK: CCCC: 265#CHECK: --bar 266#CHECK: --baz 267#CHECK: -a 268#CHECK: -b 269#CHECK: -bar 270#CHECK: -foo 271echo "CCCC:" 272complete -C'CCCC -' | sort 273complete -c CCCC -o foo -e 274#CHECK: CCCC: 275#CHECK: --baz 276#CHECK: -a 277#CHECK: -b 278#CHECK: -bar 279#CHECK: -foo 280echo "CCCC:" 281complete -C'CCCC -' | sort 282complete -c CCCC -s a -e 283#CHECK: CCCC: 284#CHECK: --baz 285#CHECK: -a 286#CHECK: -b 287#CHECK: -bar 288echo "CCCC:" 289complete -C'CCCC -' | sort 290complete -c CCCC -e 291#CHECK: CCCC: 292#CHECK: --baz 293#CHECK: -b 294#CHECK: -bar 295echo "CCCC:" 296complete -C'CCCC -' | sort 297#CHECK: CCCC: 298 299echo "Test that -- suppresses option completions" 300complete -c TestDoubleDash -l TestDoubleDashOption 301complete -C'TestDoubleDash -' | sort 302#CHECK: Test that -- suppresses option completions 303#CHECK: --TestDoubleDashOption 304echo "Expect no output:" ( complete -C'TestDoubleDash -- -' | sort ) 305#CHECK: Expect no output: 306 307# fish seems to have always handled "exclusive" options strangely 308# It seems to treat them the same as "old-style" (single-dash) long options 309echo "Testing exclusive options" 310#CHECK: Testing exclusive options 311complete -c TestExclusive -x -s Q 312complete -c TestExclusive -x -s W 313complete -c TestExclusive -s A 314echo "Expect -A -Q -W:" ( complete -C'TestExclusive -' | sort | string join' ' ) 315#CHECK: Expect -A -Q -W: -A -Q -W 316echo "Expect -AQ -AW:" ( complete -C'TestExclusive -A' | sort | string join' ' ) 317#CHECK: Expect -AQ -AW: -AQ -AW 318echo "Expect no output 1:" ( complete -C'TestExclusive -Q' ) 319#CHECK: Expect no output 1: 320echo "Expect no output 2:" ( complete -C'TestExclusive -W' ) 321#CHECK: Expect no output 2: 322 323# Test for optional arguments, like cp's --backup 324complete -c TestOptionalArgument -l backup -f -a'none all simple' 325echo "Expect --backup --backup=:" ( complete -C'TestOptionalArgument -' | sort | string join' ' ) 326#CHECK: Expect --backup --backup=: --backup --backup= 327echo "Expect --backup=all --backup=none --backup=simple:" ( complete -C'TestOptionalArgument --backup=' | sort | string join' ' ) 328#CHECK: Expect --backup=all --backup=none --backup=simple: --backup=all --backup=none --backup=simple 329 330# Test that directory completions work correctly 331if begin 332rm -rf test6.tmp.dir;and mkdir test6.tmp.dir 333end 334pushd test6.tmp.dir 335# The "incorrect implicit cd from PATH" fails if mktemp returns an absolute path and 336# `realpath --relative-to` is not available on macOS. 337# set dir (realpath --relative-to="$PWD" (mktemp -d XXXXXXXX)) 338set dir( basename ( mktemp -d XXXXXXXX)) 339mkdir -p$dir 340if complete -C$dir | string match -r"^ $dir /.*dir" > /dev/null 341echo "implicit cd complete works" 342else 343echo "no implicit cd complete" 344end 345#CHECK: implicit cd complete works 346if complete -C"command $dir " | string match -r"^ $dir /.*dir" > /dev/null 347echo "implicit cd complete after 'command'" 348else 349echo "no implicit cd complete after 'command'" 350end 351#CHECK: implicit cd complete after 'command' 352popd 353if begin 354set -l PATH$PWD /test6.tmp.dir$PATH 2> /dev/null 355complete -C$dir | string match -r"^ $dir /.*dir" > /dev/null 356end 357echo "incorrect implicit cd from PATH" 358else 359echo "PATH does not cause incorrect implicit cd" 360end 361#CHECK: PATH does not cause incorrect implicit cd 362rm -rf test6.tmp.dir 363else 364echo "error: could not create temp environment" >&2 365end 366 367# Test command expansion with parened PATHs (#952) 368begin 369set -l parened_path$PWD /'test6.tmp2.(paren).dir' 370set -l parened_subpath$parened_path /subdir 371if not begin 372rm -rf$parened_path 373and mkdir $parened_path 374and mkdir $parened_subpath 375and ln -s( command -v ls) $parened_path /'__test6_(paren)_command' 376and ln -s( command -v ls) $parened_subpath /'__test6_subdir_(paren)_command' 377end 378echo "error: could not create command expansion temp environment" >&2 379end 380 381# Verify that we can expand commands when PATH has parens 382set -l PATH$parened_path $PATH 383set -l completed( complete -C__test6_| cut -f1 -d\t ) 384if test " $completed " = '__test6_(paren)_command' 385echo "Command completion with parened PATHs test passed" 386else 387echo "Command completion with parened PATHs test failed. Expected __test6_(paren)_command, got $completed " >&2 388end 389#CHECK: Command completion with parened PATHs test passed 390 391# Verify that commands with intermediate slashes do NOT expand with respect to PATH 392set -l completed( complete -Csubdir/__test6_subdir) 393if test -z " $completed " 394echo "Command completion with intermediate slashes passed" 395else 396echo "Command completion with intermediate slashes: should output nothing, instead got $completed " >&2 397end 398#CHECK: Command completion with intermediate slashes passed 399 400rm -rf$parened_path 401end 402 403# This should only list the completions for `banana` 404complete -c banana -a'1 2 3' 405complete -c banana 406#CHECK: complete banana -a '1 2 3' 407 408# "-c" is optional 409complete banana -a bar 410complete banana 411#CHECK: complete banana -a bar 412#CHECK: complete banana -a '1 2 3' 413 414# "-a" ain't 415complete banana bar 416#CHECKERR: complete: too many arguments 417#CHECKERR: 418#CHECKERR: {{.*}}checks/complete.fish (line {{\d+}}): 419#CHECKERR: complete banana bar 420#CHECKERR: ^ 421#CHECKERR: 422#CHECKERR: (Type 'help complete' for related documentation) 423 424# Multiple commands can be specified, in that case "-c" (or "-p") is mandatory. 425complete -c kapstachelbeere -c physalis -a arg 426complete -c kapstachelbeere -c physalis 427# CHECK: complete kapstachelbeere -a arg 428# CHECK: complete physalis -a arg 429 430set -l dir( mktemp -d) 431echo > $dir /target 432complete -C': $dir/' 433# CHECK: $dir/target 434rm $dir /target 435 436cd $dir 437touch yummyinmytummy 438complete -c fudge -f 439complete -c fudge -n'__fish_seen_subcommand_from eat' -F 440complete -C'fudge eat yummyin' 441# CHECK: yummyinmytummy 442complete -C"echo no completion inside comment # " 443cd - 444 445rm -r$dir 446 447set -l dir( mktemp -d) 448cd $dir 449 450if cygwin_noacl ./ 451echo "#!/bin/sh" > command-not-in-path 452else 453: > command-not-in-path 454chmod +x command-not-in-path 455end 456complete -p$PWD /command-not-in-path -xa relative-path 457complete -C'./command-not-in-path ' 458# CHECK: relative-path 459 460# Expand variables and tildes in command. 461complete -C'$PWD/command-not-in-path ' 462# CHECK: relative-path 463HOME=$PWD complete -C'~/command-not-in-path ' 464# CHECK: relative-path 465 466# Non-canonical command path 467mkdir -p subdir 468if cygwin_noacl ./ 469echo "#!/bin/sh" > subdir/command-in-subdir 470else 471: > subdir/command-in-subdir 472chmod +x subdir/command-in-subdir 473end 474complete -p" $PWD /subdir/command-in-subdir" -xa custom-completions 475complete -C'./subdir/../subdir/command-in-subdir ' 476# CHECK: custom-completions 477 478# Relative $PATH 479begin 480set -lx PATH subdir$PATH 481complete -C'command-in-subdir ' 482# CHECK: custom-completions 483end 484 485cd - 486rm -r$dir 487 488# Expand variables and tildes in command. 489complete cat -xa +pet 490set -l path_to_cat( command -v cat) 491complete -C'$path_to_cat ' 492# CHECK: +pet 493HOME=$path_to_cat /.. complete -C'~/cat ' 494# CHECK: +pet 495 496# Do not expand command substitutions. 497complete -C'(echo cat) ' | string match +pet 498# Give up if we expand to multiple arguments (we'd need to handle the arguments). 499complete -C'{cat,arg1,arg2} ' | string match +pet 500# Don't expand wildcards though we could. 501complete -C'$path_to_cat* ' | string match +pet 502 503# Also expand wrap targets. 504function crookshanks --wraps'$path_to_cat' 505end 506complete -C'crookshanks ' 507# CHECK: +pet 508 509# Custom completion works with variable overrides and redirections. 510complete cmd_with_fancy_completion -xa'(commandline -xpc | count)' 511complete -C"a=1 b=2 cmd_with_fancy_completion " 512# CHECK: 1 513complete -C"a=1 b=2 cmd_with_fancy_completion 1 " 514# CHECK: 2 515complete -C"cmd_with_fancy_completion </dev/null >/dev/null 2>>/dev/null >?/dev/null &>/dev/null " 516# CHECK: 1 517 518complete -c thing -x -F 519# CHECKERR: complete: invalid option combination, '--exclusive' and '--force-files' 520complete -c thing -F -f 521# CHECKERR: complete: invalid option combination, '--no-files' and '--force-files' 522# Multiple conditions 523complete -f -c shot 524complete -fc shot -n'test (count (commandline -xpc) -eq 1' -n'test (commandline -xpc)[-1] = shot' -a through 525# CHECKERR: complete: -n 'test (count (commandline -xpc) -eq 1': Unexpected end of string, expecting ')' 526# CHECKERR: test (count (commandline -xpc) -eq 1 527# CHECKERR: ^ 528complete -fc shot -n'test (count (commandline -xpc)) -eq 1' -n'test (commandline -xpc)[-1] = shot' -a through 529complete -fc shot -n'test (count (commandline -xpc)) -eq 2' -n'test (commandline -xpc)[-1] = through' -a the 530complete -fc shot -n'test (count (commandline -xpc)) -eq 3' -n'test (commandline -xpc)[-1] = the' -a heart 531complete -fc shot -n'test (count (commandline -xpc)) -eq 4' -n'test (commandline -xpc)[-1] = heart' -a and 532complete -fc shot -n'test (count (commandline -xpc)) -eq 5' -n'test (commandline -xpc)[-1] = and' -a"you\'re" 533complete -fc shot -n'test (count (commandline -xpc)) -eq 6' -n'test (commandline -xpc)[-1] = "you\'re"' -a to 534complete -fc shot -n'test (count (commandline -xpc)) -eq 7' -n'test (commandline -xpc)[-1] = to' -a blame 535 536complete -C"shot " 537# CHECK: through 538complete -C"shot through " 539# CHECK: the 540 541# See that conditions after a failing one aren't executed. 542set -g oops0 543complete -fc oooops 544complete -fc oooops -n true -n true -n true -n false -n'set -g oops 1' -a oops 545complete -C'oooops ' 546echo $oops 547# CHECK: 0 548 549complete -fc oooops -n true -n'set -g oops 1' -a oops 550complete -C'oooops ' 551# CHECK: oops 552echo $oops 553# CHECK: 1 554 555# See that we load completions only if the command exists in $PATH, 556# as a workaround for #3117. 557 558# We need a completion script that runs the command, 559# and prints something simple, and isn't already used above. 560# 561# Currently, tr fits the bill (it does `tr --version` to check for GNUisms) 562begin 563$fish -c"complete -C'tr -'" | string match --'-d*' 564# CHECK: -d{{\t.*}} 565end 566 567set -l tmpdir( mktemp -d) 568cd $tmpdir 569begin 570touch tr 571chmod +x tr 572set -l PATH 573complete -C'./tr -' | string match -- -d 574or echo No match for relative 575# CHECK: No match for relative 576complete -c tr| string length -q 577or echo Empty completions 578# CHECK: Empty completions 579end 580 581rm $tmpdir /* 582 583# Leading dots are not completed for default file completion, 584# but may be for custom command (e.g. git add). 585function dotty 586end 587function notty 588end 589complete -c dotty --no-files -a'(echo .a*)' 590touch .abc .def 591complete -C'notty ' 592echo "Should be nothing" 593# CHECK: Should be nothing 594complete -C'dotty ' 595# CHECK: .abc 596 597complete -C'complete --command=mktemp' | string replace -rf'=mktemp\t.*' '=mktemp' 598# (one "--command=" is okay, we used to get "--command=--command=" 599# CHECK: --command=mktemp 600 601## Test token expansion in commandline -x 602 603complete complete_make -f -a'(argparse C/directory= -- (commandline -xpc)[2..]; 604echo Completing targets in directory $_flag_C)' 605var=path/to complete -C'complete_make -C "$var/build-directory" ' 606# CHECK: Completing targets in directory path/to/build-directory 607var1=path complete -C'var2=to complete_make -C "$var1/$var2/other-build-directory" ' 608# CHECK: Completing targets in directory path/to/other-build-directory 609 610complete complete_existing_argument -f -a'(commandline -xpc)[2..]' 611var=a_value complete -C'complete_existing_argument "1 2" $var \'quoted (foo bar)\' unquoted(baz qux) ' 612# CHECK: 1 2 613# CHECK: a_value 614# CHECK: quoted (foo bar) 615# CHECK: unquoted(baz qux) 616 617complete complete_first_argument_and_count -f -a'(set -l args (commandline -xpc)[2..] 618echo (count $args) arguments, first argument is $args[1])' 619list=arg( seq 10 ) begin 620complete -C'complete_first_argument_and_count $list$list ' 621# CHECK: 100 arguments, first argument is arg1arg1 622complete -C'complete_first_argument_and_count $list$list$list ' 623# CHECK: 1 arguments, first argument is $list$list$list 624end 625 626## Test commandline --tokens-raw 627complete complete_raw_tokens -f -ka'(commandline --tokens-raw)' 628complete -C'complete_raw_tokens "foo" bar\\ baz (qux) ' 629# CHECK: complete_raw_tokens 630# CHECK: "foo" 631# CHECK: bar\ baz 632# CHECK: (qux) 633 634## Test deprecated commandline -o 635complete complete_unescaped_tokens -f -ka'(commandline -o)' 636complete -C'complete_unescaped_tokens "foo" bar\\ baz (qux) ' 637# CHECK: complete_unescaped_tokens 638# CHECK: foo 639# CHECK: bar baz 640# CHECK: (qux) 641 642## Fuzzy completion of options 643complete complete_long_option -f -l some-long-option 644complete -C'complete_long_option --slo' 645# CHECK: --some-long-option 646complete complete_long_option -f -o an-old-option 647complete -C'complete_long_option -ao' 648# CHECK: -an-old-option 649# But only if the user typed a dash 650complete -C'complete_long_option lo' 651 652# Check that descriptions are correctly generated for commands. 653# Override __fish_describe_command to prevent missing man pages or broken __fish_apropos on macOS 654# from failing this test. (TODO: Test the latter separately.) 655function __fish_describe_command 656echo -e"whereis\twhere is it" 657echo -e"whoami\twho am i" 658echo -e"which\which is it" 659end 660test ( count ( complete -C"wh" | string match -rv"\tcommand|^while" )) -gt 0 && echo found|| echo fail 661# CHECK: found 662 663set -l commands check search show 664complete -c testcommand -n"not __fish_seen_subcommand_from $commands " -a'check\t"Check the frobnicator" search\t"Search for frobs" show\t"Show all frobs"' 665complete -C'testcommand ' 666# CHECK: check{{\t}}Check the frobnicator 667# CHECK: search{{\t}}Search for frobs 668# CHECK: show{{\t}}Show all frobs 669 670abbr cat cat 671complete -C ca| string match -r'^cat(?:\t.*)?$' 672# CHECK: cat{{\t}}Abbreviation: cat 673 674touch somefile 675abbr --position anywhere gr'| grep -i' 676complete -C'rm ' 677# CHECK: somefile 678 679complete complete-list -xa'(__fish_complete_list , "seq 2")' 680complete -C"complete-list 1," 681# CHECK: 1,1 682# CHECK: 1,2 683complete complete-list -s l -l number-list -xa'(__fish_stripprefix="^(--number-list=|-\w*l)" __fish_complete_list , "seq 2")' 684complete -C"complete-list --number-list=1," 685# CHECK: --number-list=1,1 686# CHECK: --number-list=1,2 687complete -C"complete-list -abcl1," 688# CHECK: -abcl1,1 689# CHECK: -abcl1,2 690 691function esc_in_description 692echo completion\t'escaped \n newline' 693end 694complete complete-list -l desc -xa'(__fish_complete_list , esc_in_description)' 695complete -C'complete-list --desc ' 696# CHECK: completion{{\t}}escaped {{\\n}} newline 697 698# Tests for #11880 699complete -C"set -S fish_killri" 700# CHECK: fish_killring 701# Currently, the check below behaves the same as above. Ideally, a 702# feature would be added to skip read-only variables here. 703complete -C"set fish_killri" 704# CHECK: fish_killring 705 706# Erasing completions for a command also erases wraps. 707complete somewrapper1 --wraps wrapped 708complete somewrapper1 -l long 709complete somewrapper1 -e 710complete somewrapper1 711 712# Erasing the wrapper erases nothing else. 713complete somewrapper2 --wraps wrapped 714complete somewrapper2 -l long 715complete somewrapper2 -e --wraps wrapped 716complete somewrapper2 717# CHECK: complete somewrapper2 -l long 718# CHECK: complete somewrapper2 719 720# Erasing one out of two wrappers leaves the other. 721complete somewrapper3 --wraps wrapped1 722complete somewrapper3 --wraps wrapped2 723complete somewrapper3 -l long2 724complete somewrapper3 -e --wraps wrapped2 725complete somewrapper3 726# CHECK: complete somewrapper3 -l long2 727# TODO: here's a stale entry. 728# CHECK: complete somewrapper3 729# CHECK: complete somewrapper3 730# CHECK: complete somewrapper3 --wraps wrapped1 731 732complete command-line-aware-completions -xa"(commandline --cursor; commandline --current-process)" 733complete -C"command-line-aware-completions " 734# CHECK: 31 735# CHECK: command-line-aware-completions 736 737begin 738if cygwin_noacl ./ 739echo "#!/bin/sh" > " $TMPDIR /-command-starting-with-dash" 740else 741: > " $TMPDIR /-command-starting-with-dash" 742chmod +x" $TMPDIR /-command-starting-with-dash" 743end 744 745set -l PATH" $TMPDIR " $PATH 746complete -C-command-starting-with 747# CHECK: -command-starting-with-dash{{\t}}command 748end 749 750complete -c foo -a"foo\\" 751# CHECKERR: complete: foo\: contains a syntax error 752# CHECKERR: complete: Expected a string, but found an incomplete token 753# CHECKERR: foo\ 754# CHECKERR: ^ 755 756complete -C 757# CHECKERR: complete: Can not get commandline in non-interactive mode 758 759if string match -rq --'^[a-z]+$' $USER 760set -l first_letter_wrong_case( string sub -l1 --$USER | string upper) 761string match -rq --" $USER \t.*" ( complete -C"echo ~ $first_letter_wrong_case " ) 762or echo "`complete -C'echo ~ $first_letter_wrong_case '` did not yield $USER " 763end