@matheusbsbs / matheus-bagliano / commits / c4aca9ccda
Fork 0

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>

Junio C Hamano committed Jul 30, 2008 at 12:53 UTC c4aca9ccda51badb672ab70099863072d1567267
2 files changed +15 -4
t/t0040-parse-options.sh
+10 -1
@@ -47,6 +47,7 @@ test_expect_success 'test help' '
47 cat > expect << EOF
48 boolean: 2
49 integer: 1729
50 +timestamp: 0
51 string: 123
52 abbrev: 7
53 verbose: 2
@@ -63,6 +64,7 @@ test_expect_success 'short options' '
64 cat > expect << EOF
65 boolean: 2
66 integer: 1729
67 +timestamp: 0
68 string: 321
69 abbrev: 10
70 verbose: 2
@@ -88,6 +90,7 @@ test_expect_success 'missing required value' '
90 cat > expect << EOF
91 boolean: 1
92 integer: 13
93 +timestamp: 0
94 string: 123
95 abbrev: 7
96 verbose: 0
@@ -108,6 +111,7 @@ test_expect_success 'intermingled arguments' '
111 cat > expect << EOF
112 boolean: 0
113 integer: 2
114 +timestamp: 0
115 string: (not set)
116 abbrev: 7
117 verbose: 0
@@ -135,6 +139,7 @@ test_expect_success 'ambiguously abbreviated option' '
139 cat > expect << EOF
140 boolean: 0
141 integer: 0
142 +timestamp: 0
143 string: 123
144 abbrev: 7
145 verbose: 0
@@ -161,6 +166,7 @@ test_expect_success 'detect possible typos' '
166 cat > expect <<EOF
167 boolean: 0
168 integer: 0
169 +timestamp: 0
170 string: (not set)
171 abbrev: 7
172 verbose: 0
@@ -177,7 +183,8 @@ test_expect_success 'keep some options as arguments' '
183
184 cat > expect <<EOF
185 boolean: 0
180 -integer: 1
186 +integer: 0
187 +timestamp: 1
188 string: default
189 abbrev: 7
190 verbose: 0
@@ -197,6 +204,7 @@ cat > expect <<EOF
204 Callback: "four", 0
205 boolean: 5
206 integer: 4
207 +timestamp: 0
208 string: (not set)
209 abbrev: 7
210 verbose: 0
@@ -223,6 +231,7 @@ test_expect_success 'OPT_CALLBACK() and callback errors work' '
231 cat > expect <<EOF
232 boolean: 1
233 integer: 23
234 +timestamp: 0
235 string: (not set)
236 abbrev: 7
237 verbose: 0
test-parse-options.c
+5 -3
@@ -2,7 +2,8 @@
2 #include "parse-options.h"
3
4 static int boolean = 0;
5 -static unsigned long integer = 0;
5 +static int integer = 0;
6 +static unsigned long timestamp;
7 static int abbrev = 7;
8 static int verbose = 0, dry_run = 0, quiet = 0;
9 static char *string = NULL;
@@ -32,7 +33,7 @@ int main(int argc, const char **argv)
33 OPT_INTEGER('i', "integer", &integer, "get a integer"),
34 OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
35 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>"),
37 OPT_CALLBACK('L', "length", &integer, "str",
38 "get length of <str>", length_callback),
39 OPT_GROUP("String options"),
@@ -56,7 +57,8 @@ int main(int argc, const char **argv)
57 argc = parse_options(argc, argv, options, usage, 0);
58
59 printf("boolean: %d\n", boolean);
59 - printf("integer: %lu\n", integer);
60 + printf("integer: %u\n", integer);
61 + printf("timestamp: %lu\n", timestamp);
62 printf("string: %s\n", string ? string : "(not set)");
63 printf("abbrev: %d\n", abbrev);
64 printf("verbose: %d\n", verbose);