Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
59f1e477
Commit
59f1e477
authored
Jul 27, 2018
by
Etienne Samson
Committed by
Edward Thomson
Sep 06, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Barebones JUnit XML output
parent
3a9b9631
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
1 deletions
+111
-1
tests/clar.c
+13
-1
tests/clar/summary.h
+98
-0
No files found.
tests/clar.c
View file @
59f1e477
...
...
@@ -138,6 +138,7 @@ static struct {
int
report_errors_only
;
int
exit_on_error
;
int
report_suite_names
;
int
write_summary
;
struct
clar_explicit
*
explicit
;
struct
clar_explicit
*
last_explicit
;
...
...
@@ -353,6 +354,7 @@ clar_usage(const char *arg)
printf
(
" -q
\t
Only report tests that had an error
\n
"
);
printf
(
" -Q
\t
Quit as soon as a test fails
\n
"
);
printf
(
" -l
\t
Print suite names
\n
"
);
printf
(
" -r
\t
Write summary file
\n
"
);
exit
(
-
1
);
}
...
...
@@ -366,7 +368,7 @@ clar_parse_args(int argc, char **argv)
char
*
argument
=
argv
[
i
];
if
(
argument
[
0
]
!=
'-'
||
argument
[
1
]
==
'\0'
||
strchr
(
"sixvqQl"
,
argument
[
1
])
==
NULL
)
{
||
strchr
(
"sixvqQl
r
"
,
argument
[
1
])
==
NULL
)
{
clar_usage
(
argv
[
0
]);
}
}
...
...
@@ -462,6 +464,10 @@ clar_parse_args(int argc, char **argv)
_clar
.
report_suite_names
=
1
;
break
;
case
'r'
:
_clar
.
write_summary
=
1
;
break
;
default:
assert
(
!
"Unexpected commandline argument!"
);
}
...
...
@@ -503,6 +509,8 @@ clar_test_run(void)
return
_clar
.
total_errors
;
}
static
void
clar_summary_write
(
void
);
void
clar_test_shutdown
(
void
)
{
...
...
@@ -517,6 +525,9 @@ clar_test_shutdown(void)
clar_unsandbox
();
if
(
_clar
.
write_summary
)
clar_summary_write
();
for
(
explicit
=
_clar
.
explicit
;
explicit
;
explicit
=
explicit_next
)
{
explicit_next
=
explicit
->
next
;
free
(
explicit
);
...
...
@@ -730,3 +741,4 @@ void cl_set_cleanup(void (*cleanup)(void *), void *opaque)
#include "clar/fixtures.h"
#include "clar/fs.h"
#include "clar/print.h"
#include "clar/summary.h"
tests/clar/summary.h
0 → 100644
View file @
59f1e477
#include <stdio.h>
#include <time.h>
static
FILE
*
summary
;
int
clar_summary_close_tag
(
const
char
*
tag
,
int
indent
)
{
const
char
*
indt
;
if
(
indent
==
0
)
indt
=
""
;
else
if
(
indent
==
1
)
indt
=
"
\t
"
;
else
indt
=
"
\t\t
"
;
return
fprintf
(
summary
,
"%s</%s>
\n
"
,
indt
,
tag
);
}
int
clar_summary_testsuites
(
void
)
{
return
fprintf
(
summary
,
"<testsuites>
\n
"
);
}
int
clar_summary_testsuite
(
int
idn
,
const
char
*
name
,
const
char
*
pkg
,
time_t
timestamp
,
double
time
,
int
test_count
,
int
fail_count
,
int
error_count
)
{
struct
tm
*
tm
=
localtime
(
&
timestamp
);
char
iso_dt
[
20
];
if
(
strftime
(
iso_dt
,
sizeof
(
iso_dt
),
"%FT%T"
,
tm
)
==
0
)
return
-
1
;
return
fprintf
(
summary
,
"
\t
<testsuite "
" id=
\"
%d
\"
"
" name=
\"
%s
\"
"
" package=
\"
%s
\"
"
" hostname=
\"
localhost
\"
"
" timestamp=
\"
%s
\"
"
" time=
\"
%.2f
\"
"
" tests=
\"
%d
\"
"
" failures=
\"
%d
\"
"
" errors=
\"
%d
\"
>
\n
"
,
idn
,
name
,
pkg
,
iso_dt
,
time
,
test_count
,
fail_count
,
error_count
);
}
int
clar_summary_testcase
(
const
char
*
name
,
const
char
*
classname
,
double
time
)
{
return
fprintf
(
summary
,
"
\t\t
<testcase name=
\"
%s
\"
classname=
\"
%s
\"
time=
\"
%.2f
\"
>
\n
"
,
name
,
classname
,
time
);
}
int
clar_summary_failure
(
const
char
*
type
,
const
char
*
message
,
const
char
*
desc
)
{
return
fprintf
(
summary
,
"
\t\t\t
<failure type=
\"
%s
\"
><![CDATA[%s
\n
%s]]></failure>
\n
"
,
type
,
message
,
desc
);
}
void
clar_summary_write
(
void
)
{
struct
clar_report
*
report
;
const
char
*
last_suite
=
NULL
;
char
wd
[
1024
];
summary
=
fopen
(
"summary.xml"
,
"w"
);
if
(
!
summary
)
{
printf
(
"failed to open summary.xml for writing
\n
"
);
return
;
}
clar_summary_testsuites
();
report
=
_clar
.
reports
;
while
(
report
!=
NULL
)
{
struct
clar_error
*
error
=
report
->
errors
;
if
(
last_suite
==
NULL
||
strcmp
(
last_suite
,
report
->
suite
)
!=
0
)
{
clar_summary_testsuite
(
0
,
report
->
suite
,
""
,
time
(
NULL
),
0
,
_clar
.
tests_ran
,
_clar
.
total_errors
,
0
);
}
last_suite
=
report
->
suite
;
clar_summary_testcase
(
report
->
test
,
"what"
,
0
);
while
(
error
!=
NULL
)
{
clar_summary_failure
(
"assert"
,
error
->
error_msg
,
error
->
description
);
error
=
error
->
next
;
}
clar_summary_close_tag
(
"testcase"
,
2
);
report
=
report
->
next
;
if
(
!
report
||
strcmp
(
last_suite
,
report
->
suite
)
!=
0
)
clar_summary_close_tag
(
"testsuite"
,
1
);
}
clar_summary_close_tag
(
"testsuites"
,
0
);
fclose
(
summary
);
printf
(
"written summary file to %s
\n
"
,
getcwd
((
char
*
)
&
wd
,
sizeof
(
wd
)));
}
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