fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
99d63c21f
master
1#RUN: %fish %s 2########## 3 4# NOTE: This uses argparse, which touches the local variables. 5# Any call that isn't an error should be enclosed in a begin/end block! 6 7# Start by verifying a bunch of error conditions. 8# These are *argparse* errors, and therefore bugs in the script, 9# so they print a stack trace. 10 11# No args (not even --) is an error 12argparse 13#CHECKERR: argparse: Missing -- separator 14#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 15#CHECKERR: argparse 16#CHECKERR: ^ 17#CHECKERR: (Type 'help argparse' for related documentation) 18 19# Missing -- is an error 20argparse h/help 21#CHECKERR: argparse: Missing -- separator 22#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 23#CHECKERR: argparse h/help 24#CHECKERR: ^ 25#CHECKERR: (Type 'help argparse' for related documentation) 26 27# Flags but no option specs is not an error 28begin 29argparse -s -- hello 30echo $status 31# CHECK: 0 32set -l 33# CHECK: argv hello 34# CHECK: argv_opts 35end 36 37# Invalid option specs 38argparse h- 39#CHECKERR: argparse: Invalid option spec 'h-' at char '-' 40#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 41#CHECKERR: argparse h- 42#CHECKERR: ^ 43#CHECKERR: (Type 'help argparse' for related documentation) 44argparse / 45#CHECKERR: argparse: Short flag '/' invalid, must be alphanum or '#' 46#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 47#CHECKERR: argparse / 48#CHECKERR: ^ 49#CHECKERR: (Type 'help argparse' for related documentation) 50argparse +help 51#CHECKERR: argparse: Short flag '+' invalid, must be alphanum or '#' 52#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 53#CHECKERR: argparse +help 54#CHECKERR: ^ 55#CHECKERR: (Type 'help argparse' for related documentation) 56argparse h/help: 57#CHECKERR: argparse: Invalid option spec 'h/help:' at char ':' 58#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 59#CHECKERR: argparse h/help: 60#CHECKERR: ^ 61#CHECKERR: (Type 'help argparse' for related documentation) 62argparse h-help:: 63#CHECKERR: argparse: Invalid option spec 'h-help::' at char ':' 64#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 65#CHECKERR: argparse h-help:: 66#CHECKERR: ^ 67#CHECKERR: (Type 'help argparse' for related documentation) 68argparse h-help=x 69#CHECKERR: argparse: Invalid option spec 'h-help=x' at char 'x' 70#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 71#CHECKERR: argparse h-help=x 72#CHECKERR: ^ 73#CHECKERR: (Type 'help argparse' for related documentation) 74argparse h/ 75#CHECKERR: argparse: Invalid option spec 'h/' at char '/' 76#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 77#CHECKERR: argparse h/ 78#CHECKERR: ^ 79#CHECKERR: (Type 'help argparse' for related documentation) 80 81# --max-args and --min-args work 82begin 83argparse --name min-max --min-args1 h/help -- 84#CHECKERR: min-max: expected >= 1 arguments; got 0 85argparse --name min-max --min-args1 -- 86#CHECKERR: min-max: expected >= 1 arguments; got 0 87argparse --name min-max --min-args1 --max-args3 h/help -- arg1 88argparse --name min-max --min-args1 --max-args3 -- arg1 89argparse --name min-max --min-args1 --max-args3 h/help -- arg1 arg2 90argparse --name min-max --min-args1 --max-args3 h/help -- --help arg1 arg2 arg3 91argparse --name min-max --min-args1 --max-args3 h/help -- arg1 arg2 -h arg3 arg4 92#CHECKERR: min-max: expected <= 3 arguments; got 4 93argparse --name min-max --max-args1 h/help -- 94argparse --name min-max --max-args1 h/help -- arg1 95argparse --name min-max --max-args1 h/help -- arg1 arg2 96#CHECKERR: min-max: expected <= 1 arguments; got 2 97argparse --name min-max --max-args1 -- arg1 arg2 98#CHECKERR: min-max: expected <= 1 arguments; got 2 99 100argparse --name min-max --min-args-1 -- 101#CHECKERR: argparse: Invalid --min-args value '-1' 102#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 103#CHECKERR: argparse --name min-max --min-args -1 -- 104#CHECKERR: ^ 105#CHECKERR: (Type 'help argparse' for related documentation) 106argparse --name min-max --max-args-1 -- 107#CHECKERR: argparse: Invalid --max-args value '-1' 108#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 109#CHECKERR: argparse --name min-max --max-args -1 -- 110#CHECKERR: ^ 111#CHECKERR: (Type 'help argparse' for related documentation) 112end 113 114# Invalid \"#-val\" spec 115begin 116argparse '#-val=' -- abc -x def 117# CHECKERR: argparse: Implicit int short flag '#' does not allow modifiers like '=' 118#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 119#CHECKERR: argparse '#-val=' -- abc -x def 120#CHECKERR: ^ 121#CHECKERR: (Type 'help argparse' for related documentation) 122end 123 124# Invalid arg in the face of a \"#-val\" spec 125begin 126argparse '#-val' -- abc -x def 127# CHECKERR: argparse: -x: unknown option 128end 129 130# Defining a short flag more than once 131begin 132argparse s/short x/xray s/long -- -s -x --long 133# CHECKERR: argparse: Short flag 's' already defined 134#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 135#CHECKERR: argparse s/short x/xray s/long -- -s -x --long 136#CHECKERR: ^ 137#CHECKERR: (Type 'help argparse' for related documentation) 138end 139 140# Defining a long flag more than once 141begin 142argparse s/short x/xray l/short -- -s -x --long 143# CHECKERR: argparse: Long flag 'short' already defined 144#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 145#CHECKERR: argparse s/short x/xray l/short -- -s -x --long 146#CHECKERR: ^ 147#CHECKERR: (Type 'help argparse' for related documentation) 148end 149 150# Defining an implicit int flag more than once 151begin 152argparse '#-val' x/xray'v#val' -- -s -x --long 153# CHECKERR: argparse: Implicit int flag '#' already defined 154#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 155#CHECKERR: argparse '#-val' x/xray 'v#val' -- -s -x --long 156#CHECKERR: ^ 157#CHECKERR: (Type 'help argparse' for related documentation) 158 159argparse 'v#val' x/xray'#-val' -- -s -x --long 160# CHECKERR: argparse: Implicit int flag 'v' already defined 161# CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 162# CHECKERR: argparse 'v#val' x/xray '#-val' -- -s -x --long 163# CHECKERR: ^ 164# CHECKERR: (Type 'help argparse' for related documentation) 165end 166 167# Defining an implicit int flag with modifiers 168begin 169argparse 'v#val=' -- 170# CHECKERR: argparse: Implicit int short flag 'v' does not allow modifiers like '=' 171#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 172#CHECKERR: argparse 'v#val=' -- 173#CHECKERR: ^ 174#CHECKERR: (Type 'help argparse' for related documentation) 175end 176 177########## 178# Now verify that validly formed invocations work as expected. 179 180# No args 181begin 182argparse h/help -- 183end 184 185# One arg and no matching flags 186begin 187argparse h/help -- help 188set -l 189# CHECK: argv help 190# CHECK: argv_opts 191end 192 193# Five args with two matching a flag 194begin 195argparse h/help -- help --help me -h'a lot more' 196set -l 197# CHECK: _flag_h '--help' '-h' 198# CHECK: _flag_help '--help' '-h' 199# CHECK: argv 'help' 'me' 'a lot more' 200# CHECK: argv_opts '--help' '-h' 201end 202 203# Required, optional, and multiple flags 204begin 205argparse h/help'a/abc=' 'd/def=?' 'g/ghk=+' -- help --help me --ghk=g1 --abc=ABC --ghk g2 -d -g g3 206set -lL 207# CHECK: _flag_a ABC 208# CHECK: _flag_abc ABC 209# CHECK: _flag_d 210# CHECK: _flag_def 211# CHECK: _flag_g 'g1' 'g2' 'g3' 212# CHECK: _flag_ghk 'g1' 'g2' 'g3' 213# CHECK: _flag_h --help 214# CHECK: _flag_help --help 215# CHECK: argv 'help' 'me' 216# CHECK: argv_opts '--help' '--ghk=g1' '--abc=ABC' '--ghk' 'g2' '-d' '-g' 'g3' 217end 218 219# --stop-nonopt works 220begin 221argparse --stop-nonopt h/help'a/abc=' -- -a A1 -h --abc A2 non-opt'second non-opt' --help 222set -l 223# CHECK: _flag_a A2 224# CHECK: _flag_abc A2 225# CHECK: _flag_h -h 226# CHECK: _flag_help -h 227# CHECK: argv 'non-opt' 'second non-opt' '--help' 228# CHECK: argv_opts '-a' 'A1' '-h' '--abc' 'A2' 229end 230 231# Implicit int flags work 232begin 233argparse '#-val' -- abc-123 def 234set -l 235# CHECK: _flag_val 123 236# CHECK: argv 'abc' 'def' 237# CHECK: argv_opts -123 238end 239begin 240argparse v/verbose'#-val' 't/token=' ---123 a1 --token woohoo --234 -v a2 --verbose 241set -l 242# CHECK: _flag_t woohoo 243# CHECK: _flag_token woohoo 244# CHECK: _flag_v '-v' '--verbose' 245# CHECK: _flag_val -234 246# CHECK: _flag_verbose '-v' '--verbose' 247# CHECK: argv 'a1' 'a2' 248# CHECK: argv_opts '-123' '--token' 'woohoo' '--234' '-v' '--verbose' 249end 250 251# Should be set to 987 252begin 253argparse 'm#max' -- argle-987 bargle 254set -l 255# CHECK: _flag_m 987 256# CHECK: _flag_max 987 257# CHECK: argv 'argle' 'bargle' 258# CHECK: argv_opts -987 259end 260 261# Should be set to 765 262begin 263argparse 'm#max' -- argle-987 bargle --max765 264set -l 265# CHECK: _flag_m 765 266# CHECK: _flag_max 765 267# CHECK: argv 'argle' 'bargle' 268# CHECK: argv_opts '-987' '--max' '765' 269end 270 271# Bool short flag only 272begin 273argparse C v -- -C -v arg1 -v arg2 274set -l 275# CHECK: _flag_C -C 276# CHECK: _flag_v '-v' '-v' 277# CHECK: argv 'arg1' 'arg2' 278# CHECK: argv_opts '-C' '-v' '-v' 279end 280 281# Value taking short flag only 282begin 283argparse 'x=' v/verbose -- --verbose arg1 -v -x arg2 284set -l 285# CHECK: _flag_v '--verbose' '-v' 286# CHECK: _flag_verbose '--verbose' '-v' 287# CHECK: _flag_x arg2 288# CHECK: argv arg1 289# CHECK: argv_opts '--verbose' '-v' '-x' 'arg2' 290end 291 292# Implicit int short flag only 293begin 294argparse 'x#' v/verbose -- -v -v argle -v -x321 bargle 295set -l 296# CHECK: _flag_v '-v' '-v' '-v' 297# CHECK: _flag_verbose '-v' '-v' '-v' 298# CHECK: _flag_x 321 299# CHECK: argv 'argle' 'bargle' 300# CHECK: argv_opts '-v' '-v' '-v' '-x' '321' 301end 302 303# Implicit int short flag only with custom validation passes 304begin 305argparse 'x#!_validate_int --max 500' v/verbose -- -v -v -x499 -v 306set -l 307# CHECK: _flag_v '-v' '-v' '-v' 308# CHECK: _flag_verbose '-v' '-v' '-v' 309# CHECK: _flag_x 499 310# CHECK: argv 311# CHECK: argv_opts '-v' '-v' '-x' '499' '-v' 312end 313 314# Implicit int short flag only with custom validation fails 315begin 316argparse 'x#!_validate_int --min 500' v/verbose -- -v -v -x499 -v 317set -l 318# CHECKERR: argparse: Value '499' for flag 'x' less than min allowed of '500' 319end 320 321########## 322# Verify that flag value validation works. 323 324# Implicit int flag validation fails 325argparse 'm#max' -- argle --max 765x bargle 326and echo unexpected argparse return status>&2 327argparse 'm#max' -- argle -ma1 bargle 328and echo unexpected argparse return status>&2 329# CHECKERR: argparse: Value '765x' for flag 'max' is not an integer 330# CHECKERR: argparse: Value 'a1' for flag 'm' is not an integer 331 332begin 333# Check the exit status from argparse validation 334argparse 'm#max!set -l | grep "^_flag_"; function x; return 57; end; x' -- argle --max=83 bargle2>&1 335set -l saved_status$status 336test $saved_status -eq 57 337and echo expected argparse return status$saved_status 338# CHECK: _flag_name max 339# CHECK: _flag_value 83 340# CHECK: expected argparse return status 57 341end 342 343begin 344# Explicit int flag validation 345# These should fail 346argparse 'm#max!_validate_int --min 1 --max 1' -- argle -m2 bargle 347and echo unexpected argparse return status$status >&2 348argparse 'm#max!_validate_int --min 0 --max 1' -- argle --max=-1 bargle 349and echo unexpected argparse return status$status >&2 350# CHECKERR: argparse: Value '2' for flag 'm' greater than max allowed of '1' 351# CHECKERR: argparse: Value '-1' for flag 'max' less than min allowed of '0' 352# These should succeed 353argparse 'm/max=!_validate_int --min 0 --max 1' -- argle --max=0 bargle 354or echo unexpected argparse return status$status >&2 355argparse 'm/max=!_validate_int --min 0 --max 1' -- argle --max=1 bargle 356or echo unexpected argparse return status$status >&2 357end 358 359# Errors use function name by default 360function notargparse 361argparse a/alpha -- --banana 362end 363notargparse 364# CHECKERR: notargparse: --banana: unknown option 365 366true 367 368begin 369# Ignoring unknown options 370argparse -i a=+ b=+ -- -a alpha -b bravo -t tango -a aaaa --wurst 371or echo unexpected argparse return status$status >&2 372# The unknown options are removed _entirely_. 373echo $argv 374echo $argv_opts 375echo $_flag_a 376# CHECK: -t tango --wurst 377# CHECK: -a alpha -b bravo -a aaaa 378# CHECK: alpha aaaa 379end 380 381begin 382# Ignoring unknown long options that share a character with a known short options 383argparse -i o -- --long=value --long 384or echo unexpected argparse return status$status >&2 385set -l 386# CHECK: argv '--long=value' '--long' 387# CHECK: argv_opts 388end 389 390begin 391# Check for crash when last option is unknown 392# Note that because of the quotation marks, there is a single argument 393# starting with the known short option '-b', and continuing with an unknown short option 394# that starts with a space 395argparse -i b/break --"-b kubectl get pods -l name=foo" 396set -l 397# CHECK: _flag_b -b 398# CHECK: _flag_break -b 399# CHECK: argv '- kubectl get pods -l name=foo' 400# CHECK: argv_opts -b 401end 402 403begin 404# Ignore unknown and move unknown are mutually exclusive 405argparse -i --move-unknown -- 406#CHECKERR: argparse: --ignore-unknown --move-unknown: options cannot be used together 407#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 408#CHECKERR: argparse -i --move-unknown -- 409#CHECKERR: ^ 410#CHECKERR: (Type 'help argparse' for related documentation) 411end 412 413begin 414# Moving unknown options 415argparse --move-unknown --unknown-arguments=optional h i -- -hoa -oia 416echo --$argv 417#CHECK: 418echo --$argv_opts 419#CHECK: -hoa -oia 420echo $_flag_h 421#CHECK: -h 422set -q _flag_i 423or echo No flag I 424#CHECK: No flag I 425end 426 427begin 428# Moving unknown options 429argparse -u a=+ b=+ -- -a alpha -b bravo -t tango -a aaaa --wurst 430or echo unexpected argparse return status$status >&2 431# The unknown options are removed _entirely_. 432echo $argv 433echo $argv_opts 434echo $_flag_a 435# CHECK: tango 436# CHECK: -a alpha -b bravo -t -a aaaa --wurst 437# CHECK: alpha aaaa 438end 439 440begin 441# Move unknown long options that share a character with a known short options 442argparse -u o -- --long=value --long 443or echo unexpected argparse return status$status >&2 444set -l 445# CHECK: argv 446# CHECK: argv_opts '--long=value' '--long' 447end 448 449begin 450argparse -u b/break --"-b kubectl get pods -l name=foo" 451set -l 452# CHECK: _flag_b -b 453# CHECK: _flag_break -b 454# CHECK: argv 455# CHECK: argv_opts '-b kubectl get pods -l name=foo' 456end 457 458begin 459# Checking unknown-arguments, with errors 460argparse -i -U none -- --long=value 461# CHECKERR: argparse: --long=value: option does not take an argument 462argparse -i -U required -- -u 463# CHECKERR: argparse: -u: option requires an argument 464argparse -i -U required -- --long 465# CHECKERR: argparse: --long: option requires an argument 466end 467 468begin 469argparse -U none -i b= -- -abv=val in --long between -u 470set -l 471# CHECK: _flag_b v=val 472# CHECK: argv '-a' 'in' '--long' 'between' '-u' 473# CHECK: argv_opts -bv=val 474end 475 476begin 477argparse -U none b= -- -abv in --long between -u 478set -l 479# CHECK: _flag_b v 480# CHECK: argv 'in' 'between' 481# CHECK: argv_opts '-abv' '--long' '-u' 482end 483 484begin 485argparse -iU required b= -- -abv -b -b --long -b -u -b 486set -l 487# CHECK: _flag_b -b 488# CHECK: argv '-abv' '--long' '-b' '-u' '-b' 489# CHECK: argv_opts '-b' '-b' 490end 491 492begin 493argparse -uU required b= -- -abv -b -b --long -b -u -b 494set -l 495# CHECK: _flag_b -b 496# CHECK: argv 497# CHECK: argv_opts '-abv' '-b' '-b' '--long' '-b' '-u' '-b' 498end 499 500begin 501# Checking arguments after "--" 502argparse a/alpha -- a --alpha -- b -a 503printf '%s\n' $argv 504# CHECK: a 505# CHECK: b 506printf '%s\n' $argv_opts 507# CHECK: -a 508# CHECK: --alpha 509end 510 511begin 512# #5864 - short flag only with same validation function. 513# Checking validation for short flags only 514argparse 'i=!_validate_int' 'o=!_validate_int' -- -i2 -o banana 515argparse 'i=!_validate_int' 'o=!_validate_int' -- -i -o banana 516# CHECKERR: argparse: Value 'banana' for flag 'o' is not an integer 517# CHECKERR: argparse: Value '-o' for flag 'i' is not an integer 518argparse 'i=!_validate_int' 'o=!_validate_int' -- -i2 -o3 519set -l 520# CHECK: _flag_i 2 521# CHECK: _flag_o 3 522# CHECK: argv 523# CHECK: argv_opts '-i' '2' '-o' '3' 524end 525 526# long-only flags 527begin 528argparse installed= foo -- --installed=no --foo 529set -l 530# CHECK: _flag_foo --foo 531# CHECK: _flag_installed no 532# CHECK: argv 533# CHECK: argv_opts '--installed=no' '--foo' 534end 535 536# long-only flags with one letter 537begin 538argparse i-i= /f -- --i=no --f 539set -l 540# CHECK: _flag_f --f 541# CHECK: _flag_i no 542# CHECK: argv 543# CHECK: argv_opts '--i=no' '--f' 544end 545 546begin 547argparse installed='!_validate_int --max 12' foo -- --installed=5 --foo 548set -l 549# CHECK: _flag_foo --foo 550# CHECK: _flag_installed 5 551# CHECK: argv 552# CHECK: argv_opts '--installed=5' '--foo' 553end 554 555begin 556argparse '#num' installed= -- --installed=5-5 557set -l 558# CHECK: _flag_installed 5 559# CHECK: _flag_num 5 560# CHECK: argv 561# CHECK: argv_opts '--installed=5' '-5' 562end 563 564begin 565argparse installed='!_validate_int --max 12' foo -- --foo --installed=error --foo 566# CHECKERR: argparse: Value 'error' for flag 'installed' is not an integer 567end 568 569# #6483 - error messages for missing arguments 570argparse -n foo q r/required= -- foo -qr 571# CHECKERR: foo: -r: option requires an argument 572 573argparse r/required= -- foo --required 574# CHECKERR: argparse: --required: option requires an argument 575 576### The fish_opt wrapper: 577# No args is an error 578fish_opt 579and echo unexpected status$status 580#CHECKERR: fish_opt: Either the --short or --long flag must be provided 581 582# Long-only with no long makes no sense 583fish_opt -s h --long-only 584and echo unexpected status$status 585#CHECKERR: fish_opt: The --long-only flag requires the --long flag 586 587fish_opt -s help 588and echo unexpected status$status 589#CHECKERR: fish_opt: The --short flag must be a single character 590 591# A required and optional arg makes no sense 592fish_opt -s h -l help -r --optional-val 593and echo unexpected status$status 594#CHECKERR: fish_opt: o/optional-val r/required-val: options cannot be used together 595# XXX FIXME the error should output -r and --optional-val: what the user used 596 597# An unexpected arg not associated with a flag is an error 598fish_opt -s h -l help hello 599and echo unexpected status$status 600#CHECKERR: fish_opt: Extra non-option arguments were provided 601 602# A -v / --validate without any arguments is an error 603fish_opt -s h -l help -rv 604and echo unexpected status$status 605#CHECKERR: fish_opt: The --validate flag requires subsequent arguments 606 607# A -v / --validate for boolean options is an error 608fish_opt -s h -l help -v echo hello 609and echo unexpected status$status 610#CHECKERR: fish_opt: The --validate flag requires the --required-val, --optional-value, or --multiple-vals flag 611 612# Now verify that valid combinations of options produces the correct output. 613 614# Bool, short only 615fish_opt -s h 616or echo unexpected status$status 617#CHECK: h 618 619# Long flag only 620fish_opt -l help 621or echo unexpected status$status 622#CHECK: /help 623 624# One character long flag 625fish_opt -l h 626or echo unexpected status$status 627#CHECK: /h 628 629# Bool, short and long 630fish_opt --short h --long help 631or echo unexpected status$status 632#CHECK: h/help 633 634# Bool, short and long but the short var cannot be used 635fish_opt --short h --long help --long-only 636#CHECK: h-help 637 638# Required val and long 639fish_opt --long help -r 640or echo unexpected status$status 641#CHECK: /help= 642 643# Optional val, short and long valid, and delete 644fish_opt --short h -l help --optional-val --delete 645or echo unexpected status$status 646#CHECK: h/help=?& 647 648# Optional val, short and long but the short var cannot be used 649fish_opt --short h -l help --optional-val --long-only 650or echo unexpected status$status 651#CHECK: h-help=? 652 653# Repeated val, short and long valid, with validate 654fish_opt --short h -l help --multiple-vals --validate _validate_int --max500 655or echo unexpected status$status 656#CHECK: h/help=+!_validate_int --max 500 657 658# Repeated and optional val, short and long valid 659fish_opt --short h -l help --optional-val -m 660or echo unexpected status$status 661#CHECK: h/help=* 662 663# Repeated val and short, with validate 664fish_opt -ml help --long-only -v test\$ _flag_value !="' '" 665or echo unexpected status$status 666#CHECK: /help=+!test $_flag_value != ' ' 667 668# Repeated and optional val, short and long but short not valid 669fish_opt --short h -l help --long-only -mo 670or echo unexpected status$status 671#CHECK: h-help=* 672 673# Repeated val, short only, and deleted 674fish_opt -ms h -md 675or echo unexpected status$status 676#CHECK: h=+& 677 678# Repeated and optional val, short only 679fish_opt -s h -om 680or echo unexpected status$status 681#CHECK: h=* 682 683function wrongargparse 684argparse -foo -- banana 685argparse a-b 686argparse 687end 688 689begin 690argparse '' 691#CHECKERR: argparse: An option spec must have at least a short or a long flag 692#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 693#CHECKERR: argparse '' 694#CHECKERR: ^ 695#CHECKERR: (Type 'help argparse' for related documentation) 696end 697 698begin 699argparse -U 700#CHECKERR: argparse: -U: option requires an argument 701#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 702#CHECKERR: argparse -U 703#CHECKERR: ^ 704#CHECKERR: (Type 'help argparse' for related documentation) 705end 706 707begin 708argparse --unknown-arguments what -- 709#CHECKERR: argparse: Invalid --unknown-arguments value 'what' 710#CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 711#CHECKERR: argparse --unknown-arguments what -- 712#CHECKERR: ^ 713#CHECKERR: (Type 'help argparse' for related documentation) 714end 715 716begin 717argparse f!echo hello -- -f 718#CHECKERR: argparse: Invalid option spec 'f!echo' at char '!' 719end 720 721begin 722argparse --ignore-unknown h i -- -hoa -oia 723echo --$argv 724#CHECK: -oa -oia 725echo --$argv_opts 726#CHECK: -h 727echo $_flag_h 728#CHECK: -h 729set -q _flag_i 730or echo No flag I 731#CHECK: No flag I 732end 733 734# Tests for --delete 735begin 736argparse 'a/long&' -- before -a inbetween --long after 737set -l 738# CHECK: _flag_a '-a' '--long' 739# CHECK: _flag_long '-a' '--long' 740# CHECK: argv 'before' 'inbetween' 'after' 741# CHECK: argv_opts 742end 743 744begin 745argparse 'a/long=+&' '#int&' ---123 before -a -a inbetween -astuck ater -long=long 746set -l 747# CHECK: _flag_a '-a' 'stuck' 'long' 748# CHECK: _flag_int 123 749# CHECK: _flag_long '-a' 'stuck' 'long' 750# CHECK: argv 'before' 'inbetween' 'ater' 751# CHECK: argv_opts 752end 753 754begin 755argparse 'd=?&' a b -- -d -d3 -ad -bd345 756set -l 757# CHECK: _flag_a -a 758# CHECK: _flag_b -b 759# CHECK: _flag_d 345 760# CHECK: argv 761# CHECK: argv_opts '-a' '-b' 762end 763 764begin 765argparse 'd&' a b'v=' --0 -adbv1241 -abdv1252 -dabv1243 -vd3 766set -l 767# CHECK: _flag_a '-a' '-a' '-a' 768# CHECK: _flag_b '-b' '-b' '-b' 769# CHECK: _flag_d '-d' '-d' '-d' 770# CHECK: _flag_v d3 771# CHECK: argv '0' '1' '2' '3' 772# CHECK: argv_opts '-abv124' '-abv125' '-abv124' '-vd3' 773end 774 775argparse a/alpha -- --banna=value 776# CHECKERR: argparse: --banna=value: unknown option 777# But this gives a better message 778argparse a/alpha -- --alpha=value --banna=value 779# CHECKERR: argparse: --alpha=value: option does not take an argument 780 781# Check behaviour without -S/--strict-longopts option 782begin 783argparse long value=+ -- --lon -long -lon -valu=3 -valu4 -val=3 -val4 784set -lL 785# CHECK: _flag_long '--long' '--long' '--long' 786# CHECK: _flag_value '3' '4' '3' '4' 787# CHECK: argv 788# CHECK: argv_opts '--lon' '-long' '-lon' '-valu=3' '-valu' '4' '-val=3' '-val' '4' 789argparse amb ambig -- -am 790# CHECKERR: argparse: -am: unknown option 791argparse a ambig -- -ambig 792# CHECKERR: argparse: -ambig: unknown option 793argparse long -- -long3 794# CHECKERR: argparse: -long3: unknown option 795end 796 797# Check behaviour with -S/--strict-longopts option 798begin 799argparse -S long -- --lon 800# CHECKERR: argparse: --lon: unknown option 801argparse -S long -- -long 802# CHECKERR: argparse: -long: unknown option 803argparse --strict-longopts long -- -lon 804# CHECKERR: argparse: -lon: unknown option 805argparse -S value=+ -- -valu=3 806# CHECKERR: argparse: -valu=3: unknown option 807argparse --strict-longopts value=+ -- -valu4 808# CHECKERR: argparse: -valu: unknown option 809end 810 811# Check =* options 812begin 813set -l _flag_o previous value 814argparse 'o/opt=*' -- -o non-value -oval --opt arg --opt=456 815set -l 816# CHECK: _flag_o '' 'val' '' '456' 817# CHECK: _flag_opt '' 'val' '' '456' 818# CHECK: argv 'non-value' 'arg' 819# CHECK: argv_opts '-o' '-oval' '--opt' '--opt=456' 820end 821 822# Check --exclusive 823begin 824argparse --exclusive=a a/abc b/bcd -- 825# CHECKERR: argparse: exclusive flag string 'a' is not valid 826 827argparse --exclusive=a,bcd a/abc b/bcd -- 828argparse -x a,bcd a/abc b/bcd -- 829 830argparse --exclusive=a,bcd,e a/abc b/bcd -- 831# CHECKERR: argparse: exclusive flag 'e' is not valid 832end 833 834begin 835# Many, many long options 836argparse ( for iin ( seq 0 6400 ) ;echo "o $i " ;end ) -- 837# CHECKERR: argparse: Too many long-only options 838# CHECKERR: {{.*}}checks/argparse.fish (line {{\d+}}): 839# CHECKERR: argparse (for i in (seq 0 6400); echo "o$i"; end) -- 840# CHECKERR: ^ 841# CHECKERR: (Type 'help argparse' for related documentation) 842set -l 843end 844 845# Check that the argparse's are properly wrapped in begin blocks 846set -l