1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#include "clar_libgit2.h"
#include "trace.h"
static int written = 0;
static void trace_callback(
git_trace_level_t level,
void *cb_payload,
void *msg_payload,
const char *msg)
{
GIT_UNUSED(level); GIT_UNUSED(msg_payload);
cl_assert(strcmp(msg, "Hello world!") == 0);
if (cb_payload)
*((int *)cb_payload) = 1;
}
void test_trace_trace__initialize(void)
{
git_trace_set(GIT_TRACE_INFO_AND_BELOW, trace_callback, &written);
written = 0;
}
void test_trace_trace__cleanup(void)
{
git_trace_set(GIT_TRACE_NONE, NULL, NULL);
}
void test_trace_trace__sets(void)
{
#ifdef GIT_TRACE
cl_assert(git_trace_level() == GIT_TRACE_INFO_AND_BELOW);
#endif
}
void test_trace_trace__can_reset(void)
{
#ifdef GIT_TRACE
cl_assert(git_trace_level() == GIT_TRACE_INFO_AND_BELOW);
cl_git_pass(git_trace_set(GIT_TRACE_ERROR, trace_callback, &written));
cl_assert(written == 0);
git_trace(GIT_TRACE_INFO, NULL, "Hello %s!", "world");
cl_assert(written == 0);
git_trace(GIT_TRACE_ERROR, NULL, "Hello %s!", "world");
cl_assert(written == 1);
#endif
}
void test_trace_trace__can_unset(void)
{
#ifdef GIT_TRACE
cl_assert(git_trace_level() == GIT_TRACE_INFO_AND_BELOW);
cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL, NULL));
cl_assert(git_trace_level() == GIT_TRACE_NONE);
cl_assert(written == 0);
git_trace(GIT_TRACE_FATAL, NULL, "Hello %s!", "world");
cl_assert(written == 0);
#endif
}
void test_trace_trace__skips_higher_level(void)
{
#ifdef GIT_TRACE
cl_assert(written == 0);
git_trace(GIT_TRACE_DEBUG, NULL, "Hello %s!", "world");
cl_assert(written == 0);
#endif
}
void test_trace_trace__writes(void)
{
#ifdef GIT_TRACE
cl_assert(written == 0);
git_trace(GIT_TRACE_INFO, NULL, "Hello %s!", "world");
cl_assert(written == 1);
#endif
}
void test_trace_trace__writes_lower_level(void)
{
#ifdef GIT_TRACE
cl_assert(written == 0);
git_trace(GIT_TRACE_ERROR, NULL, "Hello %s!", "world");
cl_assert(written == 1);
#endif
}
|