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
05e58576
Commit
05e58576
authored
May 18, 2011
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #194 from schu/must-pass-ret
test_lib: add return value to git_test
parents
ba9cc91f
6628c256
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
4 deletions
+17
-4
tests/test_lib.c
+15
-3
tests/test_lib.h
+2
-1
No files found.
tests/test_lib.c
View file @
05e58576
...
@@ -16,6 +16,8 @@ struct git_test {
...
@@ -16,6 +16,8 @@ struct git_test {
char
*
failed_pos
;
char
*
failed_pos
;
char
*
description
;
char
*
description
;
int
ret_value
;
git_testfunc
function
;
git_testfunc
function
;
unsigned
failed
:
1
,
ran
:
1
;
unsigned
failed
:
1
,
ran
:
1
;
jmp_buf
*
jump
;
jmp_buf
*
jump
;
...
@@ -60,6 +62,7 @@ static git_test *create_test(git_testfunc function)
...
@@ -60,6 +62,7 @@ static git_test *create_test(git_testfunc function)
t
->
ran
=
0
;
t
->
ran
=
0
;
t
->
description
=
NULL
;
t
->
description
=
NULL
;
t
->
message
=
NULL
;
t
->
message
=
NULL
;
t
->
ret_value
=
0
;
t
->
failed_pos
=
NULL
;
t
->
failed_pos
=
NULL
;
t
->
function
=
function
;
t
->
function
=
function
;
t
->
jump
=
NULL
;
t
->
jump
=
NULL
;
...
@@ -78,7 +81,7 @@ void git_test__init(git_test *t, const char *name, const char *description)
...
@@ -78,7 +81,7 @@ void git_test__init(git_test *t, const char *name, const char *description)
* Public assert methods
* Public assert methods
*-------------------------------------------------------------------------*/
*-------------------------------------------------------------------------*/
static
void
fail_test
(
git_test
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
)
static
void
fail_test
(
git_test
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
int
ret_value
)
{
{
char
buf
[
1024
];
char
buf
[
1024
];
...
@@ -86,6 +89,7 @@ static void fail_test(git_test *tc, const char *file, int line, const char *mess
...
@@ -86,6 +89,7 @@ static void fail_test(git_test *tc, const char *file, int line, const char *mess
tc
->
failed
=
1
;
tc
->
failed
=
1
;
tc
->
message
=
strdup
(
message
);
tc
->
message
=
strdup
(
message
);
tc
->
ret_value
=
ret_value
;
tc
->
failed_pos
=
strdup
(
buf
);
tc
->
failed_pos
=
strdup
(
buf
);
if
(
tc
->
jump
!=
0
)
if
(
tc
->
jump
!=
0
)
...
@@ -94,13 +98,19 @@ static void fail_test(git_test *tc, const char *file, int line, const char *mess
...
@@ -94,13 +98,19 @@ static void fail_test(git_test *tc, const char *file, int line, const char *mess
void
git_test__fail
(
git_test
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
)
void
git_test__fail
(
git_test
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
)
{
{
fail_test
(
tc
,
file
,
line
,
message
);
fail_test
(
tc
,
file
,
line
,
message
,
0
);
}
}
void
git_test__assert
(
git_test
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
int
condition
)
void
git_test__assert
(
git_test
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
int
condition
)
{
{
if
(
condition
==
0
)
if
(
condition
==
0
)
fail_test
(
tc
,
file
,
line
,
message
);
fail_test
(
tc
,
file
,
line
,
message
,
0
);
}
void
git_test__assert_pass
(
git_test
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
int
ret_value
)
{
if
(
ret_value
<
0
)
fail_test
(
tc
,
file
,
line
,
message
,
ret_value
);
}
}
/*-------------------------------------------------------------------------*
/*-------------------------------------------------------------------------*
...
@@ -157,6 +167,8 @@ static void print_details(git_testsuite *ts)
...
@@ -157,6 +167,8 @@ static void print_details(git_testsuite *ts)
failCount
++
;
failCount
++
;
printf
(
" %d)
\"
%s
\"
[test %s @ %s]
\n\t
%s
\n
"
,
printf
(
" %d)
\"
%s
\"
[test %s @ %s]
\n\t
%s
\n
"
,
failCount
,
tc
->
description
,
tc
->
name
,
tc
->
failed_pos
,
tc
->
message
);
failCount
,
tc
->
description
,
tc
->
name
,
tc
->
failed_pos
,
tc
->
message
);
if
(
tc
->
ret_value
)
printf
(
"
\t
Error: (%d) %s
\n
"
,
tc
->
ret_value
,
git_lasterror
());
}
}
}
}
}
}
...
...
tests/test_lib.h
View file @
05e58576
...
@@ -38,8 +38,9 @@ typedef git_testsuite *(*libgit2_suite)(void);
...
@@ -38,8 +38,9 @@ typedef git_testsuite *(*libgit2_suite)(void);
void
git_test__init
(
git_test
*
t
,
const
char
*
name
,
const
char
*
description
);
void
git_test__init
(
git_test
*
t
,
const
char
*
name
,
const
char
*
description
);
void
git_test__fail
(
git_test
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
);
void
git_test__fail
(
git_test
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
);
void
git_test__assert
(
git_test
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
int
condition
);
void
git_test__assert
(
git_test
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
int
condition
);
void
git_test__assert_pass
(
git_test
*
tc
,
const
char
*
file
,
int
line
,
const
char
*
message
,
int
ret_value
);
#define must_pass(expr) git_test__assert
(_gittest, __FILE__, __LINE__, "Method failed: " #expr, (expr) == 0
)
#define must_pass(expr) git_test__assert
_pass(_gittest, __FILE__, __LINE__, "Method failed: " #expr, (expr)
)
#define must_fail(expr) git_test__assert(_gittest, __FILE__, __LINE__, "Expected method to fail: " #expr, (expr) < 0)
#define must_fail(expr) git_test__assert(_gittest, __FILE__, __LINE__, "Expected method to fail: " #expr, (expr) < 0)
#define must_be_true(expr) git_test__assert(_gittest, __FILE__, __LINE__, "Expression is not true: " #expr, !!(expr))
#define must_be_true(expr) git_test__assert(_gittest, __FILE__, __LINE__, "Expression is not true: " #expr, !!(expr))
...
...
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