aboutsummaryrefslogtreecommitdiff
path: root/t/t0040-parse-options.sh
Commit message (Collapse)AuthorAge
* t0040: convert a few tests to use test-parse-options --expectJunio C Hamano2016-05-10
| | | | | | | | As a small example of using "test-parse-options --expect", rewrite the "check" helper using it, instead of comparing the whole variable dump. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* t0040: remove unused test helpersJunio C Hamano2016-05-10
| | | | | | | | | | | | 9a001381 (Fix tests under GETTEXT_POISON on parseopt, 2012-08-27) introduced check_i18n, but the helper was never used from the beginning. The same commit also introduced check_unknown_i18n to replace the helper check_unknown and changed all users of the latter to use the former, but failed to remove check_unknown itself. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* test-parse-options: --expect=<string> option to simplify testsJunio C Hamano2016-05-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Existing tests in t0040 follow a rather verbose pattern: cat >expect <<\EOF boolean: 0 integer: 0 magnitude: 0 timestamp: 0 string: (not set) abbrev: 7 verbose: 0 quiet: 3 dry run: no file: (not set) EOF test_expect_success 'multiple quiet levels' ' test-parse-options -q -q -q >output 2>output.err && test_must_be_empty output.err && test_cmp expect output ' But the only thing this test cares about is if "quiet: 3" is in the output. We should be able to write the above 18 lines with just four lines, like this: test_expect_success 'multiple quiet levels' ' test-parse-options --expect="quiet: 3" -q -q -q ' Teach the new --expect=<string> option to test-parse-options helper. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* test-parse-options: fix output when callback option failsJunio C Hamano2016-05-10
| | | | | | | | | | | | | | | | | | | When test-parse-options detects an error on the command line, it gives the usage string just like any parse-options API users do, without showing any "variable dump". An exception is the callback test, where a "variable dump" for the option is done before the command line options are fully parsed. Do not expose this implementation detail by separating the handling of callback test into two phases, one to capture the fact that an option was given during the option parsing phase, and the other to show that fact as a part of normal "variable dump". The effect of this fix is seen in the patch to t/t0040 where it tried "test-parse-options --no-length" where "--length" is a callback that does not take a negative form. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options.c: make OPTION_COUNTUP respect "unspecified" valuesPranit Bauva2016-05-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | OPT_COUNTUP() merely increments the counter upon --option, and resets it to 0 upon --no-option, which means that there is no "unspecified" value with which a client can initialize the counter to determine whether or not --[no]-option was seen at all. Make OPT_COUNTUP() treat any negative number as an "unspecified" value to address this shortcoming. In particular, if a client initializes the counter to -1, then if it is still -1 after parse_options(), then neither --option nor --no-option was seen; if it is 0, then --no-option was seen last, and if it is 1 or greater, than --option was seen last. This change does not affect the behavior of existing clients because they all use the initial value of 0 (or more). Note that builtin/clean.c initializes the variable used with OPT__FORCE (which uses OPT_COUNTUP()) to a negative value, but it is set to either 0 or 1 by reading the configuration before the code calls parse_options(), i.e. as far as parse_options() is concerned, the initial value of the variable is not negative. To test this behavior, in test-parse-options.c, "verbose" is set to "unspecified" while quiet is set to 0 which will test the new behavior with all sets of values. Helped-by: Jeff King <peff@peff.net> Helped-by: Eric Sunshine <sunshine@sunshineco.com> Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* t0040-parse-options: improve test coveragePranit Bauva2016-05-05
| | | | | | | | | | | Include tests to check for multiple levels of quiet and to check the behavior of '--no-quiet'. Include tests to check for multiple levels of verbose and to check the behavior of '--no-verbose'. Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* test-parse-options: print quiet as integerPranit Bauva2016-04-19
| | | | | | | | | | We would want to see how multiple --quiet options affect the value of the underlying variable (we may want "--quiet --quiet" to still be 1, or we may want to see the value incremented to 2). Show the value as integer to allow us to inspect it. Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* t0040-test-parse-options.sh: fix style issuesPranit Bauva2016-04-19
| | | | | Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options: move unsigned long option parsing out of pack-objects.cCharles Bailey2015-06-22
| | | | | | | | | | | | | | | | | | | The unsigned long option parsing (including 'k'/'m'/'g' suffix parsing) is more widely applicable. Add support for OPT_MAGNITUDE to parse-options.h and change pack-objects.c use this support. The error behavior on parse errors follows that of OPT_INTEGER. The name of the option that failed to parse is reported with a brief message describing the expect format for the option argument and then the full usage message for the command invoked. This differs from the previous behavior for OPT_ULONG used in pack-objects for --max-pack-size and --window-memory which used to display the value supplied in the error message and did not display the full usage message. Signed-off-by: Charles Bailey <cbailey32@bloomberg.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* test-parse-options: update to handle negative intsCharles Bailey2015-06-22
| | | | | | | | | Fix the printf specification to treat 'integer' as the signed type that it is and add a test that checks that we parse negative option arguments. Signed-off-by: Charles Bailey <cbailey32@bloomberg.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* t: use test_expect_code instead of hand-rolled comparisonJeff King2015-03-20
| | | | | | | | This makes our output in the event of a failure slightly nicer, and it means that we do not break the &&-chain. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options: remove unused OPT_SET_PTRMarat Radchenko2014-03-31
| | | | | | | OPT_SET_PTR was never used since its creation at db7244bd (parse-options new features., 2007-11-07). Signed-off-by: Junio C Hamano <gitster@pobox.com>
* test: test_must_be_empty helperJunio C Hamano2013-06-09
| | | | | | | | | | | | | | | There are quite a lot places where an output file is expected to be empty, and we fail the test when it is not. The output from running the test script with -i -v can be helped if we showed the unexpected contents at that point. We could of course do >expected.empty && test_cmp expected.empty actual but this is commmon enough to be done with a dedicated helper. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Fix tests under GETTEXT_POISON on parseoptJiang Xin2012-08-27
| | | | | | | | | | | | | Use the i18n-specific test functions in test scripts for parseopt tests. This issue was was introduced in v1.7.10.1-488-g54e6d: 54e6d i18n: parseopt: lookup help and argument translations when showing usage and been broken under GETTEXT_POISON=YesPlease since. Signed-off-by: Jiang Xin <worldhello.net@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options: typo check for unknown switchesRené Scharfe2012-03-04
| | | | | | | | | | | | | | | The user specifies a long option but forgets to type the second leading dash, we currently detect and report that fact if its first letter is a valid short option. This is done for safety, to avoid ambiguity between short options (and their arguments) and a long option with a missing dash. This diagnostic message is also helpful for long options whose first letter is not a valid short option, however. Print it in that case, too, as a courtesy. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options: allow positivation of options starting, with no-René Scharfe2012-02-26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Long options can be negated by adding no- right after the leading two dashes. This is useful e.g. to override options set by aliases. For options that are defined to start with no- already, this looks a bit funny. Allow such options to also be negated by removing the prefix. The following thirteen options are affected: apply --no-add bisect--helper --no-checkout checkout-index --no-create clone --no-checkout --no-hardlinks commit --no-verify --no-post-rewrite format-patch --no-binary hash-object --no-filters read-tree --no-sparse-checkout revert --no-commit show-branch --no-name update-ref --no-deref The following five are NOT affected because they are defined with PARSE_OPT_NONEG or the non-negated version is defined as well: branch --no-merged format-patch --no-stat --no-numbered update-index --no-assume-unchanged --no-skip-worktree Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* test-parse-options: convert to OPT_BOOL()René Scharfe2012-02-26
| | | | | | | | | Introduce OPT_BOOL() to test-parse-options and add some tests for these "true" boolean options. Rename OPT_BOOLEAN to OPT_COUNTUP and OPTION_BOOLEAN to OPTION_COUNTUP as well. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parseopt: add OPT_NOOP_NOARGRené Scharfe2011-09-28
| | | | | | | | | | | | Add OPT_NOOP_NOARG, a helper macro to define deprecated options in a standard way. The help text is taken from the no-op option -r of git revert. The callback could be made to emit a (conditional?) warning later. And we could also add OPT_NOOP (requiring an argument) etc. as needed. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options: add OPT_STRING_LIST helperJeff King2011-06-22
| | | | | | | | | This just adds repeated invocations of an option to a list of strings. Using the "--no-<var>" form will reset the list to empty. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Make <identifier> lowercase as per CodingGuidelinesMichael J Gruber2011-02-15
| | | | | | | *.c part for matches with '<[A-Z]+>' (and affected test). Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* print the usage string on stdout instead of stderrGiuseppe Scrivano2010-05-31
| | | | | | | | When -h is used, print usage messages on stdout. If a command is invoked with wrong arguments then print the usage messages on stderr. Signed-off-by: Giuseppe Scrivano <gscrivano@gnu.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-opt: ignore negation of OPT_NONEG for ambiguity checksAndreas Schwab2009-09-29
| | | | | | | | | | | | | | | | parse_long_opt always matches both --opt and --no-opt for any option "opt", and only get_value checks whether --no-opt is actually valid. Since the options for git branch contains both "no-merged" and "merged" there are two matches for --no-merge, but no exact match. With this patch the negation of a NONEG option is rejected earlier, but it changes the error message from "option `no-opt' isn't available" to "unknown option `no-opt'". [jk: added test] Signed-off-by: Andreas Schwab <schwab@linux-m68k.org> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* parse-opts: add OPT_FILENAME and transition builtinsStephen Boyd2009-05-25
| | | | | | | | | | | | | | | | | | | | | | Commit dbd0f5c (Files given on the command line are relative to $cwd, 2008-08-06) introduced parse_options_fix_filename() as a minimal fix. OPT_FILENAME is intended to be a more robust fix for the same issue. OPT_FILENAME and its associated enum OPTION_FILENAME are used to represent filename options within the parse options API. This option is similar to OPTION_STRING. If --no is prefixed to the option the filename is unset. If no argument is given and the default value is set, the filename is set to the default value. The difference is that the filename is prefixed with the prefix passed to parse_options() (or parse_options_start()). Update git-apply, git-commit, git-fmt-merge-msg, and git-tag to use OPT_FILENAME with their filename options. Also, rename parse_options_fix_filename() to fix_filename() as it is no longer extern. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parseopt: add PARSE_OPT_NODASHRené Scharfe2009-05-09
| | | | | | | | | Add support for options that don't start with a dash. Initially, they don't accept arguments and can only be short options, i.e. consist of a single character. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parseopt: add OPT_NUMBER_CALLBACKRené Scharfe2009-05-09
| | | | | | | | Add a way to recognize numerical options. The number is passed to a callback function as a string. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parseopt: add OPT_NEGBITRené Scharfe2009-05-09
| | | | | | | | | | | | Add OPTION_NEGBIT and OPT_NEGBIT, mirroring OPTION_BIT and OPT_BIT. OPT_NEGBIT can be used together with OPT_BIT to define two options that cancel each other out. Note: this patch removes the reminder from the test script because it adds a test for --no-or4 and there already was one for --or4. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Fix test-parse-options "integer" testJunio C Hamano2008-07-30
| | | | | | | | | | OPT_INTEGER() works on an integer, not on an unsigned long. On a big endian architecture with long larger than int, integer test gives bogus results because of this bug. Reported by H.Merijn Brand in HP-UX 64-bit environment. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options: fix segmentation fault when a required value is missingOlivier Marin2008-07-21
| | | | | | | | | | p->argc represent the number of arguments that have not been parsed yet, _including_ the one we are currently parsing. If it is not greater than one then there is no more argument. Signed-off-by: Olivier Marin <dkr@freesurf.fr> Acked-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Extend parse-options test suiteStephan Beyer2008-06-22
| | | | | | | | | | | | This patch serves two purposes: 1. test-parse-option.c should be a more complete example for the parse-options API, and 2. there have been no tests for OPT_CALLBACK, OPT_DATE, OPT_BIT, OPT_SET_INT and OPT_SET_PTR before. Signed-off-by: Stephan Beyer <s-beyer@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* tests: do not use implicit "git diff --no-index"Junio C Hamano2008-05-24
| | | | | | | | | | | As a general principle, we should not use "git diff" to validate the results of what git command that is being tested has done. We would not know if we are testing the command in question, or locating a bug in the cute hack of "git diff --no-index". Rather use test_cmp for that purpose. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options: new option type to treat an option-like parameter as an argument.Pierre Habouzit2008-03-02
| | | | | | | This is meant to be used to keep --not and --all during revision parsing. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Sane use of test_expect_failureJunio C Hamano2008-02-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Originally, test_expect_failure was designed to be the opposite of test_expect_success, but this was a bad decision. Most tests run a series of commands that leads to the single command that needs to be tested, like this: test_expect_{success,failure} 'test title' ' setup1 && setup2 && setup3 && what is to be tested ' And expecting a failure exit from the whole sequence misses the point of writing tests. Your setup$N that are supposed to succeed may have failed without even reaching what you are trying to test. The only valid use of test_expect_failure is to check a trivial single command that is expected to fail, which is a minority in tests of Porcelain-ish commands. This large-ish patch rewrites all uses of test_expect_failure to use test_expect_success and rewrites the condition of what is tested, like this: test_expect_success 'test title' ' setup1 && setup2 && setup3 && ! this command should fail ' test_expect_failure is redefined to serve as a reminder that that test *should* succeed but due to a known breakage in git it currently does not pass. So if git-foo command should create a file 'bar' but you discovered a bug that it doesn't, you can write a test like this: test_expect_failure 'git-foo should create bar' ' rm -f bar && git foo && test -f bar ' This construct acts similar to test_expect_success, but instead of reporting "ok/FAIL" like test_expect_success does, the outcome is reported as "FIXED/still broken". Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options: catch likely typo in presense of aggregated options.Pierre Habouzit2008-01-26
| | | | | | | | | | | | | | | | | | | If options are aggregated, and that the whole token is an exact prefix of a long option that is longer than 2 letters, reject it. This is to prevent a common typo: $ git commit -amend to get interpreted as "commit all with message 'end'". The typo check isn't performed if there is no aggregation, because the stuck form is the recommended one. If we have `-o` being a valid short option that takes an argument, and --option a long one, then we _MUST_ accept -option as "'o' option with argument 'ption'", which is our official recommended form. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options: abbreviation engine fix.Johannes Schindelin2007-11-05
| | | | | | | | | | When an option could be an ambiguous abbreviation of two options, the code used to error out. Even if an exact match would have occured later. Test and original patch by Pierre Habouzit. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* parse-options: Allow abbreviated options when unambiguousJohannes Schindelin2007-10-29
| | | | | | | | | When there is an option "--amend", the option parser now recognizes "--am" for that option, provided that there is no other option beginning with "--am". Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Add tests for parse-options.cJohannes Schindelin2007-10-29
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>