t / t1502-rev-parse-parseopt.shon commit Merge "Move 'builtin-*' into a 'builtin/' subdirectory" (c444c16)
   1#!/bin/sh
   2
   3test_description='test git rev-parse --parseopt'
   4. ./test-lib.sh
   5
   6cat > expect.err <<EOF
   7usage: some-command [options] <args>...
   8
   9    some-command does foo and bar!
  10
  11    -h, --help            show the help
  12    --foo                 some nifty option --foo
  13    --bar ...             some cool option --bar with an argument
  14
  15An option group Header
  16    -C[...]               option C with an optional argument
  17
  18Extras
  19    --extra1              line above used to cause a segfault but no longer does
  20
  21EOF
  22
  23cat > optionspec << EOF
  24some-command [options] <args>...
  25
  26some-command does foo and bar!
  27--
  28h,help    show the help
  29
  30foo       some nifty option --foo
  31bar=      some cool option --bar with an argument
  32
  33 An option group Header
  34C?        option C with an optional argument
  35
  36Extras
  37extra1    line above used to cause a segfault but no longer does
  38EOF
  39
  40test_expect_success 'test --parseopt help output' '
  41        git rev-parse --parseopt -- -h 2> output.err < optionspec
  42        test_cmp expect.err output.err
  43'
  44
  45cat > expect <<EOF
  46set -- --foo --bar 'ham' -- 'arg'
  47EOF
  48
  49test_expect_success 'test --parseopt' '
  50        git rev-parse --parseopt -- --foo --bar=ham arg < optionspec > output &&
  51        test_cmp expect output
  52'
  53
  54test_expect_success 'test --parseopt with mixed options and arguments' '
  55        git rev-parse --parseopt -- --foo arg --bar=ham < optionspec > output &&
  56        test_cmp expect output
  57'
  58
  59cat > expect <<EOF
  60set -- --foo -- 'arg' '--bar=ham'
  61EOF
  62
  63test_expect_success 'test --parseopt with --' '
  64        git rev-parse --parseopt -- --foo -- arg --bar=ham < optionspec > output &&
  65        test_cmp expect output
  66'
  67
  68test_expect_success 'test --parseopt --stop-at-non-option' '
  69        git rev-parse --parseopt --stop-at-non-option -- --foo arg --bar=ham < optionspec > output &&
  70        test_cmp expect output
  71'
  72
  73cat > expect <<EOF
  74set -- --foo -- '--' 'arg' '--bar=ham'
  75EOF
  76
  77test_expect_success 'test --parseopt --keep-dashdash' '
  78        git rev-parse --parseopt --keep-dashdash -- --foo -- arg --bar=ham < optionspec > output &&
  79        test_cmp expect output
  80'
  81
  82test_done