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
2d6e39ce
Commit
2d6e39ce
authored
Aug 23, 2011
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
opt: neaten tests with helpers.
parent
13f96138
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
20 deletions
+16
-20
ccan/opt/test/run-helpers.c
ccan/opt/test/run-helpers.c
+16
-20
No files found.
ccan/opt/test/run-helpers.c
View file @
2d6e39ce
...
...
@@ -72,6 +72,18 @@ static void *saved_malloc(size_t size)
return
last_allocation
=
malloc
(
size
);
}
static
void
set_args
(
int
*
argc
,
char
***
argv
,
...)
{
va_list
ap
;
*
argv
=
malloc
(
sizeof
(
**
argv
)
*
20
);
va_start
(
ap
,
argv
);
for
(
*
argc
=
0
;
((
*
argv
)[
*
argc
]
=
va_arg
(
ap
,
char
*
))
!=
NULL
;
(
*
argc
)
++
);
va_end
(
ap
);
}
/* Test helpers. */
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -985,11 +997,7 @@ int main(int argc, char *argv[])
/* parse_args allocates argv */
free
(
argv
);
argc
=
2
;
argv
=
malloc
(
sizeof
(
argv
[
0
])
*
3
);
argv
[
0
]
=
(
char
*
)
"thisprog"
;
argv
[
1
]
=
(
char
*
)
"-a"
;
argv
[
2
]
=
NULL
;
set_args
(
&
argc
,
&
argv
,
"thisprog"
,
"-a"
,
NULL
);
exitval
=
setjmp
(
exited
);
if
(
exitval
==
0
)
{
...
...
@@ -1011,11 +1019,7 @@ int main(int argc, char *argv[])
opt_register_noarg
(
"-a"
,
opt_usage_and_exit
,
"[args]"
,
""
);
argc
=
2
;
argv
=
malloc
(
sizeof
(
argv
[
0
])
*
3
);
argv
[
0
]
=
(
char
*
)
"thisprog"
;
argv
[
1
]
=
(
char
*
)
"-a"
;
argv
[
2
]
=
NULL
;
set_args
(
&
argc
,
&
argv
,
"thisprog"
,
"-a"
,
NULL
);
exitval
=
setjmp
(
exited
);
if
(
exitval
==
0
)
{
...
...
@@ -1150,11 +1154,7 @@ int main(int argc, char *argv[])
opt_register_noarg
(
"-a"
,
opt_usage_and_exit
,
"[args]"
,
""
);
argc
=
2
;
argv
=
malloc
(
sizeof
(
argv
[
0
])
*
3
);
argv
[
0
]
=
(
char
*
)
"thisprog"
;
argv
[
1
]
=
(
char
*
)
"--garbage"
;
argv
[
2
]
=
NULL
;
set_args
(
&
argc
,
&
argv
,
"thisprog"
,
"--garbage"
,
NULL
);
ok1
(
!
opt_parse
(
&
argc
,
argv
,
opt_log_stderr
));
ok1
(
!
strcmp
(
output
,
"thisprog: --garbage: unrecognized option
\n
"
));
...
...
@@ -1169,11 +1169,7 @@ int main(int argc, char *argv[])
reset_options
();
opt_register_noarg
(
"-a"
,
opt_usage_and_exit
,
"[args]"
,
""
);
argc
=
2
;
argv
=
malloc
(
sizeof
(
argv
[
0
])
*
3
);
argv
[
0
]
=
(
char
*
)
"thisprog"
;
argv
[
1
]
=
(
char
*
)
"--garbage"
;
argv
[
2
]
=
NULL
;
set_args
(
&
argc
,
&
argv
,
"thisprog"
,
"--garbage"
,
NULL
);
exitval
=
setjmp
(
exited
);
if
(
exitval
==
0
)
{
opt_parse
(
&
argc
,
argv
,
opt_log_stderr_exit
);
...
...
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