Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
f20e4f23
Commit
f20e4f23
authored
Oct 05, 2010
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
opt: remove unused debug function and code, test a few more corner cases.
parent
b2d126ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
10 deletions
+19
-10
ccan/opt/opt.c
ccan/opt/opt.c
+0
-9
ccan/opt/test/run-helpers.c
ccan/opt/test/run-helpers.c
+19
-1
No files found.
ccan/opt/opt.c
View file @
f20e4f23
...
...
@@ -41,8 +41,6 @@ static const char *first_opt(unsigned *i, unsigned *len)
static
const
char
*
next_opt
(
const
char
*
p
,
unsigned
*
i
,
unsigned
*
len
)
{
if
(
!
p
)
(
*
i
)
++
;
for
(;
*
i
<
opt_count
;
(
*
i
)
++
)
{
if
(
opt_table
[
*
i
].
flags
==
OPT_SUBTABLE
)
continue
;
...
...
@@ -259,13 +257,6 @@ static void parse_fail(void (*errlog)(const char *fmt, ...),
strcspn
(
longopt
,
"/"
),
longopt
,
problem
);
}
void
dump_optstate
(
void
);
void
dump_optstate
(
void
)
{
printf
(
"opterr = %i, optind = %i, optopt = %i, optarg = %s
\n
"
,
opterr
,
optind
,
optopt
,
optarg
);
}
/* Parse your arguments. */
bool
opt_parse
(
int
*
argc
,
char
*
argv
[],
void
(
*
errlog
)(
const
char
*
fmt
,
...))
{
...
...
ccan/opt/test/run-helpers.c
View file @
f20e4f23
...
...
@@ -3,6 +3,7 @@
#include <ccan/tap/tap.h>
#include <setjmp.h>
#include <stdlib.h>
#include <limits.h>
#include "utils.h"
/* We don't actually want it to exit... */
...
...
@@ -48,7 +49,7 @@ static int saved_printf(const char *fmt, ...)
/* Test helpers. */
int
main
(
int
argc
,
char
*
argv
[])
{
plan_tests
(
88
);
plan_tests
(
96
);
/* opt_set_bool */
{
...
...
@@ -66,6 +67,9 @@ int main(int argc, char *argv[])
ok1
(
!
arg
);
ok1
(
parse_args
(
&
argc
,
&
argv
,
"-b"
,
"true"
,
NULL
));
ok1
(
arg
);
ok1
(
!
parse_args
(
&
argc
,
&
argv
,
"-b"
,
"unknown"
,
NULL
));
ok1
(
arg
);
ok1
(
strstr
(
err_output
,
": -b: Invalid argument 'unknown'"
));
}
/* opt_set_invbool */
{
...
...
@@ -84,6 +88,9 @@ int main(int argc, char *argv[])
ok1
(
arg
);
ok1
(
parse_args
(
&
argc
,
&
argv
,
"-b"
,
"true"
,
NULL
));
ok1
(
!
arg
);
ok1
(
!
parse_args
(
&
argc
,
&
argv
,
"-b"
,
"unknown"
,
NULL
));
ok1
(
!
arg
);
ok1
(
strstr
(
err_output
,
": -b: Invalid argument 'unknown'"
));
}
/* opt_set_charp */
{
...
...
@@ -122,6 +129,17 @@ int main(int argc, char *argv[])
ok1
(
arg
==
0
);
ok1
(
!
parse_args
(
&
argc
,
&
argv
,
"-a"
,
"100crap"
,
NULL
));
ok1
(
!
parse_args
(
&
argc
,
&
argv
,
"-a"
,
"4294967296"
,
NULL
));
if
(
ULONG_MAX
==
UINT_MAX
)
{
pass
(
"Can't test overflow"
);
pass
(
"Can't test error message"
);
}
else
{
char
buf
[
30
];
sprintf
(
buf
,
"%lu"
,
ULONG_MAX
);
ok1
(
!
parse_args
(
&
argc
,
&
argv
,
"-a"
,
buf
,
NULL
));
ok1
(
strstr
(
err_output
,
": -a: value '"
)
&&
strstr
(
err_output
,
buf
)
&&
strstr
(
err_output
,
"' does not fit into an integer"
));
}
}
/* opt_set_longval */
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment