(command.CommandList children: [ (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:test_description) op: Equal rhs: {(SQ <'our own option parser'>)} ) ] ) (C {(.)} {(./test-lib.sh)}) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(expect)}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\E'>) (OF)} here_end_span_id: 72 stdin_parts: [ ('usage: test-parse-options <options>\n') ('\n') (' --yes get a boolean\n') (" -D, --no-doubt begins with 'no-'\n") (' -B, --no-fear be brave\n') (' -b, --boolean increment by one\n') (' -4, --or4 bitwise-or boolean with ...0100\n') (' --neg-or4 same as --no-or4\n') ('\n') (' -i, --integer <n> get a integer\n') (' -j <n> get a integer, too\n') (' -m, --magnitude <n> get a magnitude\n') (' --set23 set integer to 23\n') (' -t <time> get timestamp of <time>\n') (' -L, --length <str> get length of <str>\n') (' -F, --file <file> set file to <file>\n') ('\n') ('String options\n') (' -s, --string <string>\n') (' get a string\n') (' --string2 <str> get another string\n') (' --st <st> get another string (pervert ordering)\n') (' -o <str> get another string\n') (' --list <str> add str to list\n') ('\n') ('Magic arguments\n') (' --quux means --quux\n') (' -NUM set integer to NUM\n') (' + same as -b\n') (' --ambiguous positive ambiguity\n') (' --no-ambiguous negative ambiguity\n') ('\n') ('Standard options\n') (' --abbrev[=<n>] use <n> digits to display SHA-1s\n') (' -v, --verbose be verbose\n') (' -n, --dry-run dry run\n') (' -q, --quiet be quiet\n') (' --expect <string> expected output in the variable dump\n') ('\n') ] ) ] ) (C {(test_expect_success)} {(SQ <'test help'>)} { (SQ <'\n'> <'\ttest_must_fail test-parse-options -h >output 2>output.err &&\n'> <'\ttest_must_be_empty output.err &&\n'> <'\ttest_i18ncmp expect output\n'> ) } ) (C {(mv)} {(expect)} {(expect.err)}) (command.FuncDef name: check body: (command.BraceGroup children: [ (command.AndOr ops: [Op_DAmp Op_DAmp Op_DAmp Op_DAmp] children: [ (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:what) op: Equal rhs: {(DQ ($ VSub_Number '$1'))} ) ] ) (C {(shift)}) (command.Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (lhs_expr.LhsName name:expect) op: Equal rhs: {(DQ ($ VSub_Number '$1'))} ) ] ) (C {(shift)}) (C {(test-parse-options)} {(--expect) (Lit_Other '=') (DQ ($ VSub_DollarName '$what') (' ') ($ VSub_DollarName '$expect')) } {(DQ ($ VSub_At '$@'))} ) ] ) ] ) ) (command.FuncDef name: check_unknown_i18n body: (command.BraceGroup children: [ (command.AndOr ops: [Op_DAmp Op_DAmp Op_DAmp Op_DAmp] children: [ (command.Case to_match: {(DQ ($ VSub_Number '$1'))} arms: [ (case_arm pat_list: [{(--) (Lit_Other '*')}] action: [ (command.SimpleCommand words: [ {(echo)} {(error) (Lit_Other ':')} {(unknown)} {(option)} {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\`'>) (word_part.BracedVarSub token: <VSub_Number 1> suffix_op: (suffix_op.StringUnary op_id:VOp1_Pound arg_word:{(--)}) ) (word_part.EscapedLiteralPart token:<Lit_EscapedChar "\\'">) } ] redirects: [ (redir.Redir op: <Redir_Great '>'> fd: 16777215 arg_word: {(expect)} ) ] ) ] ) (case_arm pat_list: [{(-) (Lit_Other '*')}] action: [ (command.SimpleCommand words: [ {(echo)} {(error) (Lit_Other ':')} {(unknown)} {(switch)} {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\`'>) (word_part.BracedVarSub token: <VSub_Number 1> suffix_op: (suffix_op.StringUnary op_id:VOp1_Pound arg_word:{(-)}) ) (word_part.EscapedLiteralPart token:<Lit_EscapedChar "\\'">) } ] redirects: [ (redir.Redir op: <Redir_Great '>'> fd: 16777215 arg_word: {(expect)} ) ] ) ] ) ] ) (command.SimpleCommand words: [{(cat)} {(expect.err)}] redirects: [(redir.Redir op:<Redir_DGreat '>>'> fd:16777215 arg_word:{(expect)})] ) (command.SimpleCommand words: [{(test_must_fail)} {(test-parse-options)} {($ VSub_Star '$*')}] redirects: [ (redir.Redir op: <Redir_Great '>'> fd: 16777215 arg_word: {(output)} ) (redir.Redir op: <Redir_Great '2>'> fd: 2 arg_word: {(output.err)} ) ] ) (C {(test_must_be_empty)} {(output)}) (C {(test_i18ncmp)} {(expect)} {(output.err)}) ] ) ] ) ) (C {(test_expect_success)} {(SQ <'OPT_BOOL() #1'>)} {(SQ <'check boolean: 1 --yes'>)}) (C {(test_expect_success)} {(SQ <'OPT_BOOL() #2'>)} {(SQ <'check boolean: 1 --no-doubt'>)}) (C {(test_expect_success)} {(SQ <'OPT_BOOL() #3'>)} {(SQ <'check boolean: 1 -D'>)}) (C {(test_expect_success)} {(SQ <'OPT_BOOL() #4'>)} {(SQ <'check boolean: 1 --no-fear'>)}) (C {(test_expect_success)} {(SQ <'OPT_BOOL() #5'>)} {(SQ <'check boolean: 1 -B'>)}) (C {(test_expect_success)} {(SQ <'OPT_BOOL() is idempotent #1'>)} {(SQ <'check boolean: 1 --yes --yes'>)} ) (C {(test_expect_success)} {(SQ <'OPT_BOOL() is idempotent #2'>)} {(SQ <'check boolean: 1 -DB'>)}) (C {(test_expect_success)} {(SQ <'OPT_BOOL() negation #1'>)} {(SQ <'check boolean: 0 -D --no-yes'>)}) (C {(test_expect_success)} {(SQ <'OPT_BOOL() negation #2'>)} {(SQ <'check boolean: 0 -D --no-no-doubt'>)} ) (C {(test_expect_success)} {(SQ <'OPT_BOOL() no negation #1'>)} {(SQ <'check_unknown_i18n --fear'>)}) (C {(test_expect_success)} {(SQ <'OPT_BOOL() no negation #2'>)} {(SQ <'check_unknown_i18n --no-no-fear'>)} ) (C {(test_expect_success)} {(SQ <'OPT_BOOL() positivation'>)} {(SQ <'check boolean: 0 -D --doubt'>)}) (C {(test_expect_success)} {(SQ <'OPT_INT() negative'>)} {(SQ <'check integer: -2345 -i -2345'>)}) (C {(test_expect_success)} {(SQ <'OPT_MAGNITUDE() simple'>)} {(SQ <'\n'> <'\tcheck magnitude: 2345678 -m 2345678\n'>)} ) (C {(test_expect_success)} {(SQ <'OPT_MAGNITUDE() kilo'>)} {(SQ <'\n'> <'\tcheck magnitude: 239616 -m 234k\n'>)} ) (C {(test_expect_success)} {(SQ <'OPT_MAGNITUDE() mega'>)} {(SQ <'\n'> <'\tcheck magnitude: 104857600 -m 100m\n'>)} ) (C {(test_expect_success)} {(SQ <'OPT_MAGNITUDE() giga'>)} {(SQ <'\n'> <'\tcheck magnitude: 1073741824 -m 1g\n'>)} ) (C {(test_expect_success)} {(SQ <'OPT_MAGNITUDE() 3giga'>)} {(SQ <'\n'> <'\tcheck magnitude: 3221225472 -m 3g\n'>)} ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(expect)}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\E'>) (OF)} here_end_span_id: 479 stdin_parts: [ ('boolean: 2\n') ('integer: 1729\n') ('magnitude: 16384\n') ('timestamp: 0\n') ('string: 123\n') ('abbrev: 7\n') ('verbose: 2\n') ('quiet: 0\n') ('dry run: yes\n') ('file: prefix/my.file\n') ] ) ] ) (C {(test_expect_success)} {(SQ <'short options'>)} { (SQ <'\n'> <'\ttest-parse-options -s123 -b -i 1729 -m 16k -b -vv -n -F my.file \\\n'> <'\t>output 2>output.err &&\n'> <'\ttest_cmp expect output &&\n'> <'\ttest_must_be_empty output.err\n'> ) } ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(expect)}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\E'>) (OF)} here_end_span_id: 515 stdin_parts: [ ('boolean: 2\n') ('integer: 1729\n') ('magnitude: 16384\n') ('timestamp: 0\n') ('string: 321\n') ('abbrev: 10\n') ('verbose: 2\n') ('quiet: 0\n') ('dry run: no\n') ('file: prefix/fi.le\n') ] ) ] ) (C {(test_expect_success)} {(SQ <'long options'>)} { (SQ <'\n'> <'\ttest-parse-options --boolean --integer 1729 --magnitude 16k \\\n'> <'\t\t--boolean --string2=321 --verbose --verbose --no-dry-run \\\n'> <'\t\t--abbrev=10 --file fi.le --obsolete \\\n'> <'\t\t>output 2>output.err &&\n'> <'\ttest_must_be_empty output.err &&\n'> <'\ttest_cmp expect output\n'> ) } ) (C {(test_expect_success)} {(SQ <'missing required value'>)} { (SQ <'\n'> <'\ttest_expect_code 129 test-parse-options -s &&\n'> <'\ttest_expect_code 129 test-parse-options --string &&\n'> <'\ttest_expect_code 129 test-parse-options --file\n'> ) } ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(expect)}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\E'>) (OF)} here_end_span_id: 570 stdin_parts: [ ('boolean: 1\n') ('integer: 13\n') ('magnitude: 0\n') ('timestamp: 0\n') ('string: 123\n') ('abbrev: 7\n') ('verbose: -1\n') ('quiet: 0\n') ('dry run: no\n') ('file: (not set)\n') ('arg 00: a1\n') ('arg 01: b1\n') ('arg 02: --boolean\n') ] ) ] ) (C {(test_expect_success)} {(SQ <'intermingled arguments'>)} { (SQ <'\n'> <'\ttest-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \\\n'> <'\t\t>output 2>output.err &&\n'> <'\ttest_must_be_empty output.err &&\n'> <'\ttest_cmp expect output\n'> ) } ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(expect)}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\E'>) (OF)} here_end_span_id: 606 stdin_parts: [ ('boolean: 0\n') ('integer: 2\n') ('magnitude: 0\n') ('timestamp: 0\n') ('string: (not set)\n') ('abbrev: 7\n') ('verbose: -1\n') ('quiet: 0\n') ('dry run: no\n') ('file: (not set)\n') ] ) ] ) (C {(test_expect_success)} {(SQ <'unambiguously abbreviated option'>)} { (SQ <'\n'> <'\ttest-parse-options --int 2 --boolean --no-bo >output 2>output.err &&\n'> <'\ttest_must_be_empty output.err &&\n'> <'\ttest_cmp expect output\n'> ) } ) (C {(test_expect_success)} {(SQ <'unambiguously abbreviated option with "="'>)} {(SQ <'\n'> <'\ttest-parse-options --expect="integer: 2" --int=2\n'>)} ) (C {(test_expect_success)} {(SQ <'ambiguously abbreviated option'>)} {(SQ <'\n'> <'\ttest_expect_code 129 test-parse-options --strin 123\n'>)} ) (C {(test_expect_success)} {(SQ <'non ambiguous option (after two options it abbreviates)'>)} {(SQ <'\n'> <'\ttest-parse-options --expect="string: 123" --st 123\n'>)} ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(typo.err)}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\E'>) (OF)} here_end_span_id: 668 stdin_parts: [('error: did you mean `--boolean` (with two dashes ?)\n')] ) ] ) (C {(test_expect_success)} {(SQ <'detect possible typos'>)} { (SQ <'\n'> <'\ttest_must_fail test-parse-options -boolean >output 2>output.err &&\n'> <'\ttest_must_be_empty output &&\n'> <'\ttest_cmp typo.err output.err\n'> ) } ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(typo.err)}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\E'>) (OF)} here_end_span_id: 694 stdin_parts: [('error: did you mean `--ambiguous` (with two dashes ?)\n')] ) ] ) (C {(test_expect_success)} {(SQ <'detect possible typos'>)} { (SQ <'\n'> <'\ttest_must_fail test-parse-options -ambiguous >output 2>output.err &&\n'> <'\ttest_must_be_empty output &&\n'> <'\ttest_cmp typo.err output.err\n'> ) } ) (C {(test_expect_success)} {(SQ <'keep some options as arguments'>)} {(SQ <'\n'> <'\ttest-parse-options --expect="arg 00: --quux" --quux\n'>)} ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(expect)}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\E'>) (OF)} here_end_span_id: 742 stdin_parts: [ ('boolean: 0\n') ('integer: 0\n') ('magnitude: 0\n') ('timestamp: 1\n') ('string: (not set)\n') ('abbrev: 7\n') ('verbose: -1\n') ('quiet: 1\n') ('dry run: no\n') ('file: (not set)\n') ('arg 00: foo\n') ] ) ] ) (C {(test_expect_success)} {(SQ <'OPT_DATE() works'>)} { (SQ <'\n'> <'\ttest-parse-options -t "1970-01-01 00:00:01 +0000" \\\n'> <'\t\tfoo -q >output 2>output.err &&\n'> <'\ttest_must_be_empty output.err &&\n'> <'\ttest_cmp expect output\n'> ) } ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(expect)}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\E'>) (OF)} here_end_span_id: 779 stdin_parts: [ ('Callback: "four", 0\n') ('boolean: 5\n') ('integer: 4\n') ('magnitude: 0\n') ('timestamp: 0\n') ('string: (not set)\n') ('abbrev: 7\n') ('verbose: -1\n') ('quiet: 0\n') ('dry run: no\n') ('file: (not set)\n') ] ) ] ) (C {(test_expect_success)} {(SQ <'OPT_CALLBACK() and OPT_BIT() work'>)} { (SQ <'\n'> <'\ttest-parse-options --length=four -b -4 >output 2>output.err &&\n'> <'\ttest_must_be_empty output.err &&\n'> <'\ttest_cmp expect output\n'> ) } ) (command.SimpleCommand redirects: [(redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(expect)})] ) (C {(test_expect_success)} {(SQ <'OPT_CALLBACK() and callback errors work'>)} { (SQ <'\n'> <'\ttest_must_fail test-parse-options --no-length >output 2>output.err &&\n'> <'\ttest_i18ncmp expect output &&\n'> <'\ttest_i18ncmp expect.err output.err\n'> ) } ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(expect)}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\E'>) (OF)} here_end_span_id: 832 stdin_parts: [ ('boolean: 1\n') ('integer: 23\n') ('magnitude: 0\n') ('timestamp: 0\n') ('string: (not set)\n') ('abbrev: 7\n') ('verbose: -1\n') ('quiet: 0\n') ('dry run: no\n') ('file: (not set)\n') ] ) ] ) (C {(test_expect_success)} {(SQ <'OPT_BIT() and OPT_SET_INT() work'>)} { (SQ <'\n'> <'\ttest-parse-options --set23 -bbbbb --no-or4 >output 2>output.err &&\n'> <'\ttest_must_be_empty output.err &&\n'> <'\ttest_cmp expect output\n'> ) } ) (C {(test_expect_success)} {(SQ <'OPT_NEGBIT() and OPT_SET_INT() work'>)} { (SQ <'\n'> <'\ttest-parse-options --set23 -bbbbb --neg-or4 >output 2>output.err &&\n'> <'\ttest_must_be_empty output.err &&\n'> <'\ttest_cmp expect output\n'> ) } ) (C {(test_expect_success)} {(SQ <'OPT_BIT() works'>)} {(SQ <'\n'> <'\ttest-parse-options --expect="boolean: 6" -bb --or4\n'>)} ) (C {(test_expect_success)} {(SQ <'OPT_NEGBIT() works'>)} {(SQ <'\n'> <'\ttest-parse-options --expect="boolean: 6" -bb --no-neg-or4\n'>)} ) (C {(test_expect_success)} {(SQ <'OPT_COUNTUP() with PARSE_OPT_NODASH works'>)} {(SQ <'\n'> <'\ttest-parse-options --expect="boolean: 6" + + + + + +\n'>)} ) (C {(test_expect_success)} {(SQ <'OPT_NUMBER_CALLBACK() works'>)} {(SQ <'\n'> <'\ttest-parse-options --expect="integer: 12345" -12345\n'>)} ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_Great '>'> fd:16777215 arg_word:{(expect)}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\E'>) (OF)} here_end_span_id: 929 stdin_parts: [ ('boolean: 0\n') ('integer: 0\n') ('magnitude: 0\n') ('timestamp: 0\n') ('string: (not set)\n') ('abbrev: 7\n') ('verbose: -1\n') ('quiet: 0\n') ('dry run: no\n') ('file: (not set)\n') ] ) ] ) (C {(test_expect_success)} {(SQ <'negation of OPT_NONEG flags is not ambiguous'>)} { (SQ <'\n'> <'\ttest-parse-options --no-ambig >output 2>output.err &&\n'> <'\ttest_must_be_empty output.err &&\n'> <'\ttest_cmp expect output\n'> ) } ) (command.SimpleCommand words: [{(cat)}] redirects: [ (redir.Redir op:<Redir_DGreat '>>'> fd:16777215 arg_word:{(expect)}) (redir.HereDoc op: <Redir_DLess '<<'> fd: 16777215 here_begin: {(word_part.EscapedLiteralPart token:<Lit_EscapedChar '\\E'>) (OF)} here_end_span_id: 957 stdin_parts: [('list: foo\n') ('list: bar\n') ('list: baz\n')] ) ] ) (C {(test_expect_success)} {(SQ <'--list keeps list of strings'>)} { (SQ <'\n'> <'\ttest-parse-options --list foo --list=bar --list=baz >output &&\n'> <'\ttest_cmp expect output\n'> ) } ) (C {(test_expect_success)} {(SQ <'--no-list resets list'>)} { (SQ <'\n'> <'\ttest-parse-options --list=other --list=irrelevant --list=options \\\n'> <'\t\t--no-list --list=foo --list=bar --list=baz >output &&\n'> <'\ttest_cmp expect output\n'> ) } ) (C {(test_expect_success)} {(SQ <'multiple quiet levels'>)} {(SQ <'\n'> <'\ttest-parse-options --expect="quiet: 3" -q -q -q\n'>)} ) (C {(test_expect_success)} {(SQ <'multiple verbose levels'>)} {(SQ <'\n'> <'\ttest-parse-options --expect="verbose: 3" -v -v -v\n'>)} ) (C {(test_expect_success)} {(SQ <'--no-quiet sets --quiet to 0'>)} {(SQ <'\n'> <'\ttest-parse-options --expect="quiet: 0" --no-quiet\n'>)} ) (C {(test_expect_success)} {(SQ <'--no-quiet resets multiple -q to 0'>)} {(SQ <'\n'> <'\ttest-parse-options --expect="quiet: 0" -q -q -q --no-quiet\n'>)} ) (C {(test_expect_success)} {(SQ <'--no-verbose sets verbose to 0'>)} {(SQ <'\n'> <'\ttest-parse-options --expect="verbose: 0" --no-verbose\n'>)} ) (C {(test_expect_success)} {(SQ <'--no-verbose resets multiple verbose to 0'>)} {(SQ <'\n'> <'\ttest-parse-options --expect="verbose: 0" -v -v -v --no-verbose\n'>)} ) (C {(test_done)}) ] )