#!/bin/sh global test_description := ''test git rev-parse --parseopt'' source ./test-lib.sh test_expect_success 'setup optionspec' ' sed -e "s/^|//" >optionspec <<\EOF |some-command [options] ... | |some-command does foo and bar! |-- |h,help show the help | |foo some nifty option --foo |bar= some cool option --bar with an argument |b,baz a short and long option | | An option group Header |C? option C with an optional argument |d,data? short and long option with an optional argument | | Argument hints |B=arg short option required argument |bar2=arg long option required argument |e,fuz=with-space short and long option required argument |s?some short option optional argument |long?data long option optional argument |g,fluf?path short and long option optional argument |longest=very-long-argument-hint a very long argument hint |pair=key=value with an equals sign in the hint |short-hint=a with a one symbol hint | |Extras |extra1 line above used to cause a segfault but no longer does EOF ' test_expect_success 'test --parseopt help output' ' sed -e "s/^|//" >expect <<\END_EXPECT && |cat <<\EOF |usage: some-command [options] ... | | some-command does foo and bar! | | -h, --help show the help | --foo some nifty option --foo | --bar ... some cool option --bar with an argument | -b, --baz a short and long option | |An option group Header | -C[...] option C with an optional argument | -d, --data[=...] short and long option with an optional argument | |Argument hints | -B short option required argument | --bar2 long option required argument | -e, --fuz | short and long option required argument | -s[] short option optional argument | --long[=] long option optional argument | -g, --fluf[=] short and long option optional argument | --longest | a very long argument hint | --pair with an equals sign in the hint | --short-hint with a one symbol hint | |Extras | --extra1 line above used to cause a segfault but no longer does | |EOF END_EXPECT test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec && test_i18ncmp expect output ' test_expect_success 'setup expect.1' " cat > expect < output && test_cmp expect output ' test_expect_success 'test --parseopt with mixed options and arguments' ' git rev-parse --parseopt -- --foo arg --bar=ham --baz < optionspec > output && test_cmp expect output ' test_expect_success 'setup expect.2' " cat > expect < output && test_cmp expect output ' test_expect_success 'test --parseopt --stop-at-non-option' ' git rev-parse --parseopt --stop-at-non-option -- --foo arg --bar=ham < optionspec > output && test_cmp expect output ' test_expect_success 'setup expect.3' " cat > expect < output && test_cmp expect output ' test_expect_success 'setup expect.4' " cat >expect <output && test_cmp expect output ' test_expect_success 'setup expect.5' " cat > expect <output && test_cmp expect output ' test_expect_success 'setup expect.6' " cat > expect <output && test_cmp expect output ' test_expect_success 'setup expect.7' " cat > expect <output && test_cmp expect output ' test_expect_success 'setup expect.8' " cat > expect <output && test_cmp expect output ' test_expect_success 'test --parseopt --stuck-long and short option with unset optional argument' ' git rev-parse --parseopt --stuck-long -- -d arg -b output && test_cmp expect output ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"test git rev-parse --parseopt">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ <"setup optionspec">)} { (SQ <"\n"> <"\tsed -e \"s/^|//\" >optionspec <<\\EOF\n"> <"|some-command [options] ...\n"> <"|\n"> <"|some-command does foo and bar!\n"> <"|--\n"> <"|h,help show the help\n"> <"|\n"> <"|foo some nifty option --foo\n"> <"|bar= some cool option --bar with an argument\n"> <"|b,baz a short and long option\n"> <"|\n"> <"| An option group Header\n"> <"|C? option C with an optional argument\n"> <"|d,data? short and long option with an optional argument\n"> <"|\n"> <"| Argument hints\n"> <"|B=arg short option required argument\n"> <"|bar2=arg long option required argument\n"> <"|e,fuz=with-space short and long option required argument\n"> <"|s?some short option optional argument\n"> <"|long?data long option optional argument\n"> <"|g,fluf?path short and long option optional argument\n"> <"|longest=very-long-argument-hint a very long argument hint\n"> <"|pair=key=value with an equals sign in the hint\n"> <"|short-hint=a with a one symbol hint\n"> <"|\n"> <"|Extras\n"> <"|extra1 line above used to cause a segfault but no longer does\n"> <"EOF\n"> ) } ) (C {(test_expect_success)} {(SQ <"test --parseopt help output">)} { (SQ <"\n"> <"\tsed -e \"s/^|//\" >expect <<\\END_EXPECT &&\n"> <"|cat <<\\EOF\n"> <"|usage: some-command [options] ...\n"> <"|\n"> <"| some-command does foo and bar!\n"> <"|\n"> <"| -h, --help show the help\n"> <"| --foo some nifty option --foo\n"> <"| --bar ... some cool option --bar with an argument\n"> <"| -b, --baz a short and long option\n"> <"|\n"> <"|An option group Header\n"> <"| -C[...] option C with an optional argument\n"> <"| -d, --data[=...] short and long option with an optional argument\n"> <"|\n"> <"|Argument hints\n"> <"| -B short option required argument\n"> <"| --bar2 long option required argument\n"> <"| -e, --fuz \n"> <"| short and long option required argument\n"> <"| -s[] short option optional argument\n"> <"| --long[=] long option optional argument\n"> <"| -g, --fluf[=] short and long option optional argument\n"> <"| --longest \n"> <"| a very long argument hint\n"> <"| --pair with an equals sign in the hint\n"> <"| --short-hint with a one symbol hint\n"> <"|\n"> <"|Extras\n"> <"| --extra1 line above used to cause a segfault but no longer does\n"> <"|\n"> <"|EOF\n"> <"END_EXPECT\n"> <"\ttest_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec &&\n"> <"\ttest_i18ncmp expect output\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup expect.1">)} {(DQ ("\n") ("\tcat > expect <)} { (SQ <"\n"> <"\tgit rev-parse --parseopt -- --foo --bar=ham --baz arg < optionspec > output &&\n"> <"\ttest_cmp expect output\n"> ) } ) (C {(test_expect_success)} {(SQ <"test --parseopt with mixed options and arguments">)} { (SQ <"\n"> <"\tgit rev-parse --parseopt -- --foo arg --bar=ham --baz < optionspec > output &&\n"> <"\ttest_cmp expect output\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup expect.2">)} {(DQ ("\n") ("\tcat > expect <)} { (SQ <"\n"> <"\tgit rev-parse --parseopt -- --foo -- arg --bar=ham < optionspec > output &&\n"> <"\ttest_cmp expect output\n"> ) } ) (C {(test_expect_success)} {(SQ <"test --parseopt --stop-at-non-option">)} { (SQ <"\n"> < "\tgit rev-parse --parseopt --stop-at-non-option -- --foo arg --bar=ham < optionspec > output &&\n" > <"\ttest_cmp expect output\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup expect.3">)} {(DQ ("\n") ("\tcat > expect <)} { (SQ <"\n"> < "\tgit rev-parse --parseopt --keep-dashdash -- --foo -- arg --bar=ham < optionspec > output &&\n" > <"\ttest_cmp expect output\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup expect.4">)} {(DQ ("\n") ("\tcat >expect <)} { (SQ <"\n"> < "\tgit rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo -- arg --spam=ham output &&\n" > <"\ttest_cmp expect output\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup expect.5">)} {(DQ ("\n") ("\tcat > expect <)} { (SQ <"\n"> < "\tgit rev-parse --parseopt --keep-dashdash --stop-at-non-option -- --foo arg --spam=ham output &&\n" > <"\ttest_cmp expect output\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup expect.6">)} { (DQ ("\n") ("\tcat > expect <)} { (SQ <"\n"> < "\tgit rev-parse --parseopt --stuck-long -- --foo --bar=z -b arg -CZ -dA output &&\n" > <"\ttest_cmp expect output\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup expect.7">)} {(DQ ("\n") ("\tcat > expect <)} { (SQ <"\n"> <"\tgit rev-parse --parseopt --stuck-long -- --data= arg -C -b output &&\n"> <"\ttest_cmp expect output\n"> ) } ) (C {(test_expect_success)} {(SQ <"setup expect.8">)} {(DQ ("\n") ("\tcat > expect <)} { (SQ <"\n"> <"\tgit rev-parse --parseopt --stuck-long -- --data arg -b output &&\n"> <"\ttest_cmp expect output\n"> ) } ) (C {(test_expect_success)} {(SQ <"test --parseopt --stuck-long and short option with unset optional argument">)} { (SQ <"\n"> <"\tgit rev-parse --parseopt --stuck-long -- -d arg -b output &&\n"> <"\ttest_cmp expect output\n"> ) } ) (C {(test_done)}) ] )