diff options
| author | Vicent Martà <vicent@github.com> | 2013-03-07 11:14:03 -0800 |
|---|---|---|
| committer | Vicent Martà <vicent@github.com> | 2013-03-07 11:14:03 -0800 |
| commit | 6f83a7813310766325ae14f6ac7591dc56341fc5 (patch) | |
| tree | 4fbee7fe0e9f5ce6c0d26acc0b5656a4e138d673 /tests-clar | |
| parent | 33abaad809669d33f2e9ea7eeb473ec43b8257ce (diff) | |
| parent | b5ec5430a8cad68c1c534568a5a7047e42f75580 (diff) | |
| download | libgit2-6f83a7813310766325ae14f6ac7591dc56341fc5.tar.gz | |
Merge pull request #1403 from ethomson/tracing
Optional tracing back to consumers
Diffstat (limited to 'tests-clar')
| -rw-r--r-- | tests-clar/trace/trace.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/tests-clar/trace/trace.c b/tests-clar/trace/trace.c new file mode 100644 index 000000000..712fe62c6 --- /dev/null +++ b/tests-clar/trace/trace.c @@ -0,0 +1,86 @@ +#include "clar_libgit2.h" +#include "trace.h" + +static int written = 0; + +static void trace_callback(git_trace_level_t level, const char *message) +{ + cl_assert(strcmp(message, "Hello world!") == 0); + + written = 1; +} + +void test_trace_trace__initialize(void) +{ + git_trace_set(GIT_TRACE_INFO, trace_callback); + written = 0; +} + +void test_trace_trace__cleanup(void) +{ + git_trace_set(GIT_TRACE_NONE, NULL); +} + +void test_trace_trace__sets(void) +{ +#ifdef GIT_TRACE + cl_assert(git_trace_level() == GIT_TRACE_INFO); +#endif +} + +void test_trace_trace__can_reset(void) +{ +#ifdef GIT_TRACE + cl_assert(git_trace_level() == GIT_TRACE_INFO); + cl_git_pass(git_trace_set(GIT_TRACE_ERROR, trace_callback)); + + cl_assert(written == 0); + git_trace(GIT_TRACE_INFO, "Hello %s!", "world"); + cl_assert(written == 0); + + git_trace(GIT_TRACE_ERROR, "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); + cl_git_pass(git_trace_set(GIT_TRACE_NONE, NULL)); + + cl_assert(git_trace_level() == GIT_TRACE_NONE); + + cl_assert(written == 0); + git_trace(GIT_TRACE_FATAL, "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, "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, "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, "Hello %s!", "world"); + cl_assert(written == 1); +#endif +} + |
