Skip to content

Commit c4aca9c

Browse files
committed
Fix test-parse-options "integer" test
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>
1 parent 5354a56 commit c4aca9c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

t/t0040-parse-options.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ test_expect_success 'test help' '
4747
cat > expect << EOF
4848
boolean: 2
4949
integer: 1729
50+
timestamp: 0
5051
string: 123
5152
abbrev: 7
5253
verbose: 2
@@ -63,6 +64,7 @@ test_expect_success 'short options' '
6364
cat > expect << EOF
6465
boolean: 2
6566
integer: 1729
67+
timestamp: 0
6668
string: 321
6769
abbrev: 10
6870
verbose: 2
@@ -88,6 +90,7 @@ test_expect_success 'missing required value' '
8890
cat > expect << EOF
8991
boolean: 1
9092
integer: 13
93+
timestamp: 0
9194
string: 123
9295
abbrev: 7
9396
verbose: 0
@@ -108,6 +111,7 @@ test_expect_success 'intermingled arguments' '
108111
cat > expect << EOF
109112
boolean: 0
110113
integer: 2
114+
timestamp: 0
111115
string: (not set)
112116
abbrev: 7
113117
verbose: 0
@@ -135,6 +139,7 @@ test_expect_success 'ambiguously abbreviated option' '
135139
cat > expect << EOF
136140
boolean: 0
137141
integer: 0
142+
timestamp: 0
138143
string: 123
139144
abbrev: 7
140145
verbose: 0
@@ -161,6 +166,7 @@ test_expect_success 'detect possible typos' '
161166
cat > expect <<EOF
162167
boolean: 0
163168
integer: 0
169+
timestamp: 0
164170
string: (not set)
165171
abbrev: 7
166172
verbose: 0
@@ -177,7 +183,8 @@ test_expect_success 'keep some options as arguments' '
177183

178184
cat > expect <<EOF
179185
boolean: 0
180-
integer: 1
186+
integer: 0
187+
timestamp: 1
181188
string: default
182189
abbrev: 7
183190
verbose: 0
@@ -197,6 +204,7 @@ cat > expect <<EOF
197204
Callback: "four", 0
198205
boolean: 5
199206
integer: 4
207+
timestamp: 0
200208
string: (not set)
201209
abbrev: 7
202210
verbose: 0
@@ -223,6 +231,7 @@ test_expect_success 'OPT_CALLBACK() and callback errors work' '
223231
cat > expect <<EOF
224232
boolean: 1
225233
integer: 23
234+
timestamp: 0
226235
string: (not set)
227236
abbrev: 7
228237
verbose: 0

test-parse-options.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#include "parse-options.h"
33

44
static int boolean = 0;
5-
static unsigned long integer = 0;
5+
static int integer = 0;
6+
static unsigned long timestamp;
67
static int abbrev = 7;
78
static int verbose = 0, dry_run = 0, quiet = 0;
89
static char *string = NULL;
@@ -32,7 +33,7 @@ int main(int argc, const char **argv)
3233
OPT_INTEGER('i', "integer", &integer, "get a integer"),
3334
OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
3435
OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23),
35-
OPT_DATE('t', NULL, &integer, "get timestamp of <time>"),
36+
OPT_DATE('t', NULL, &timestamp, "get timestamp of <time>"),
3637
OPT_CALLBACK('L', "length", &integer, "str",
3738
"get length of <str>", length_callback),
3839
OPT_GROUP("String options"),
@@ -56,7 +57,8 @@ int main(int argc, const char **argv)
5657
argc = parse_options(argc, argv, options, usage, 0);
5758

5859
printf("boolean: %d\n", boolean);
59-
printf("integer: %lu\n", integer);
60+
printf("integer: %u\n", integer);
61+
printf("timestamp: %lu\n", timestamp);
6062
printf("string: %s\n", string ? string : "(not set)");
6163
printf("abbrev: %d\n", abbrev);
6264
printf("verbose: %d\n", verbose);

0 commit comments

Comments
 (0)