Skip to content

Commit

Permalink
Fix test-parse-options "integer" test
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Jul 30, 2008
1 parent 5354a56 commit c4aca9c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 10 additions & 1 deletion t/t0040-parse-options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ test_expect_success 'test help' '
cat > expect << EOF
boolean: 2
integer: 1729
timestamp: 0
string: 123
abbrev: 7
verbose: 2
Expand All @@ -63,6 +64,7 @@ test_expect_success 'short options' '
cat > expect << EOF
boolean: 2
integer: 1729
timestamp: 0
string: 321
abbrev: 10
verbose: 2
Expand All @@ -88,6 +90,7 @@ test_expect_success 'missing required value' '
cat > expect << EOF
boolean: 1
integer: 13
timestamp: 0
string: 123
abbrev: 7
verbose: 0
Expand All @@ -108,6 +111,7 @@ test_expect_success 'intermingled arguments' '
cat > expect << EOF
boolean: 0
integer: 2
timestamp: 0
string: (not set)
abbrev: 7
verbose: 0
Expand Down Expand Up @@ -135,6 +139,7 @@ test_expect_success 'ambiguously abbreviated option' '
cat > expect << EOF
boolean: 0
integer: 0
timestamp: 0
string: 123
abbrev: 7
verbose: 0
Expand All @@ -161,6 +166,7 @@ test_expect_success 'detect possible typos' '
cat > expect <<EOF
boolean: 0
integer: 0
timestamp: 0
string: (not set)
abbrev: 7
verbose: 0
Expand All @@ -177,7 +183,8 @@ test_expect_success 'keep some options as arguments' '

cat > expect <<EOF
boolean: 0
integer: 1
integer: 0
timestamp: 1
string: default
abbrev: 7
verbose: 0
Expand All @@ -197,6 +204,7 @@ cat > expect <<EOF
Callback: "four", 0
boolean: 5
integer: 4
timestamp: 0
string: (not set)
abbrev: 7
verbose: 0
Expand All @@ -223,6 +231,7 @@ test_expect_success 'OPT_CALLBACK() and callback errors work' '
cat > expect <<EOF
boolean: 1
integer: 23
timestamp: 0
string: (not set)
abbrev: 7
verbose: 0
Expand Down
8 changes: 5 additions & 3 deletions test-parse-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#include "parse-options.h"

static int boolean = 0;
static unsigned long integer = 0;
static int integer = 0;
static unsigned long timestamp;
static int abbrev = 7;
static int verbose = 0, dry_run = 0, quiet = 0;
static char *string = NULL;
Expand Down Expand Up @@ -32,7 +33,7 @@ int main(int argc, const char **argv)
OPT_INTEGER('i', "integer", &integer, "get a integer"),
OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23),
OPT_DATE('t', NULL, &integer, "get timestamp of <time>"),
OPT_DATE('t', NULL, &timestamp, "get timestamp of <time>"),
OPT_CALLBACK('L', "length", &integer, "str",
"get length of <str>", length_callback),
OPT_GROUP("String options"),
Expand All @@ -56,7 +57,8 @@ int main(int argc, const char **argv)
argc = parse_options(argc, argv, options, usage, 0);

printf("boolean: %d\n", boolean);
printf("integer: %lu\n", integer);
printf("integer: %u\n", integer);
printf("timestamp: %lu\n", timestamp);
printf("string: %s\n", string ? string : "(not set)");
printf("abbrev: %d\n", abbrev);
printf("verbose: %d\n", verbose);
Expand Down

0 comments on commit c4aca9c

Please sign in to comment.