]> git.proxmox.com Git - libgit2.git/blame - tests/clar/clar.h
Merge https://salsa.debian.org/debian/libgit2 into proxmox/bullseye
[libgit2.git] / tests / clar / clar.h
CommitLineData
e8a92fe1
RB
1/*
2 * Copyright (c) Vicent Marti. All rights reserved.
3 *
4 * This file is part of clar, distributed under the ISC license.
5 * For full terms see the included COPYING file.
6 */
2e6f06a8
VM
7#ifndef __CLAR_TEST_H__
8#define __CLAR_TEST_H__
9
10#include <stdlib.h>
11
0f65733b
VM
12enum cl_test_status {
13 CL_TEST_OK,
14 CL_TEST_FAILURE,
6c7cee42 15 CL_TEST_SKIP,
e579e0f7 16 CL_TEST_NOTRUN
0f65733b
VM
17};
18
22a2d3d5
UG
19enum cl_output_format {
20 CL_OUTPUT_CLAP,
e579e0f7 21 CL_OUTPUT_TAP
22a2d3d5
UG
22};
23
6c7cee42 24/** Setup clar environment */
10be94e9
ET
25void clar_test_init(int argc, char *argv[]);
26int clar_test_run(void);
27void clar_test_shutdown(void);
28
6c7cee42 29/** One shot setup & run */
2e6f06a8
VM
30int clar_test(int argc, char *argv[]);
31
10be94e9
ET
32const char *clar_sandbox_path(void);
33
2e6f06a8
VM
34void cl_set_cleanup(void (*cleanup)(void *), void *opaque);
35void cl_fs_cleanup(void);
36
cfcb346d
ET
37/**
38 * cl_trace_* is a hook to provide a simple global tracing
39 * mechanism.
40 *
41 * The goal here is to let main() provide clar-proper
42 * with a callback to optionally write log info for
43 * test operations into the same stream used by their
44 * actual tests. This would let them print test names
45 * and maybe performance data as they choose.
46 *
47 * The goal is NOT to alter the flow of control or to
48 * override test selection/skipping. (So the callback
49 * does not return a value.)
50 *
51 * The goal is NOT to duplicate the existing
52 * pass/fail/skip reporting. (So the callback
53 * does not accept a status/errorcode argument.)
54 *
55 */
56typedef enum cl_trace_event {
57 CL_TRACE__SUITE_BEGIN,
58 CL_TRACE__SUITE_END,
59 CL_TRACE__TEST__BEGIN,
60 CL_TRACE__TEST__END,
61 CL_TRACE__TEST__RUN_BEGIN,
62 CL_TRACE__TEST__RUN_END,
e579e0f7 63 CL_TRACE__TEST__LONGJMP
cfcb346d
ET
64} cl_trace_event;
65
66typedef void (cl_trace_cb)(
67 cl_trace_event ev,
68 const char *suite_name,
69 const char *test_name,
70 void *payload);
71
72/**
73 * Register a callback into CLAR to send global trace events.
74 * Pass NULL to disable.
75 */
76void cl_trace_register(cl_trace_cb *cb, void *payload);
77
78
2e6f06a8
VM
79#ifdef CLAR_FIXTURE_PATH
80const char *cl_fixture(const char *fixture_name);
81void cl_fixture_sandbox(const char *fixture_name);
82void cl_fixture_cleanup(const char *fixture_name);
ac3d33df 83const char *cl_fixture_basename(const char *fixture_name);
2e6f06a8
VM
84#endif
85
86/**
87 * Assertion macros with explicit error message
88 */
22a2d3d5
UG
89#define cl_must_pass_(expr, desc) clar__assert((expr) >= 0, __FILE__, __func__, __LINE__, "Function call failed: " #expr, desc, 1)
90#define cl_must_fail_(expr, desc) clar__assert((expr) < 0, __FILE__, __func__, __LINE__, "Expected function call to fail: " #expr, desc, 1)
91#define cl_assert_(expr, desc) clar__assert((expr) != 0, __FILE__, __func__, __LINE__, "Expression is not true: " #expr, desc, 1)
2e6f06a8
VM
92
93/**
94 * Check macros with explicit error message
95 */
22a2d3d5
UG
96#define cl_check_pass_(expr, desc) clar__assert((expr) >= 0, __FILE__, __func__, __LINE__, "Function call failed: " #expr, desc, 0)
97#define cl_check_fail_(expr, desc) clar__assert((expr) < 0, __FILE__, __func__, __LINE__, "Expected function call to fail: " #expr, desc, 0)
98#define cl_check_(expr, desc) clar__assert((expr) != 0, __FILE__, __func__, __LINE__, "Expression is not true: " #expr, desc, 0)
2e6f06a8
VM
99
100/**
101 * Assertion macros with no error message
102 */
103#define cl_must_pass(expr) cl_must_pass_(expr, NULL)
104#define cl_must_fail(expr) cl_must_fail_(expr, NULL)
105#define cl_assert(expr) cl_assert_(expr, NULL)
106
107/**
108 * Check macros with no error message
109 */
110#define cl_check_pass(expr) cl_check_pass_(expr, NULL)
111#define cl_check_fail(expr) cl_check_fail_(expr, NULL)
112#define cl_check(expr) cl_check_(expr, NULL)
113
114/**
115 * Forced failure/warning
116 */
22a2d3d5
UG
117#define cl_fail(desc) clar__fail(__FILE__, __func__, __LINE__, "Test failed.", desc, 1)
118#define cl_warning(desc) clar__fail(__FILE__, __func__, __LINE__, "Warning during test execution:", desc, 0)
2e6f06a8 119
0f65733b
VM
120#define cl_skip() clar__skip()
121
2e6f06a8
VM
122/**
123 * Typed assertion macros
124 */
22a2d3d5
UG
125#define cl_assert_equal_s(s1,s2) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #s1 " != " #s2, 1, "%s", (s1), (s2))
126#define cl_assert_equal_s_(s1,s2,note) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #s1 " != " #s2 " (" #note ")", 1, "%s", (s1), (s2))
7202ec29 127
22a2d3d5
UG
128#define cl_assert_equal_wcs(wcs1,wcs2) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #wcs1 " != " #wcs2, 1, "%ls", (wcs1), (wcs2))
129#define cl_assert_equal_wcs_(wcs1,wcs2,note) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #wcs1 " != " #wcs2 " (" #note ")", 1, "%ls", (wcs1), (wcs2))
09debe12 130
22a2d3d5
UG
131#define cl_assert_equal_strn(s1,s2,len) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #s1 " != " #s2, 1, "%.*s", (s1), (s2), (int)(len))
132#define cl_assert_equal_strn_(s1,s2,len,note) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #s1 " != " #s2 " (" #note ")", 1, "%.*s", (s1), (s2), (int)(len))
806571f3 133
22a2d3d5
UG
134#define cl_assert_equal_wcsn(wcs1,wcs2,len) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #wcs1 " != " #wcs2, 1, "%.*ls", (wcs1), (wcs2), (int)(len))
135#define cl_assert_equal_wcsn_(wcs1,wcs2,len,note) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #wcs1 " != " #wcs2 " (" #note ")", 1, "%.*ls", (wcs1), (wcs2), (int)(len))
09debe12 136
22a2d3d5
UG
137#define cl_assert_equal_i(i1,i2) clar__assert_equal(__FILE__,__func__,__LINE__,#i1 " != " #i2, 1, "%d", (int)(i1), (int)(i2))
138#define cl_assert_equal_i_(i1,i2,note) clar__assert_equal(__FILE__,__func__,__LINE__,#i1 " != " #i2 " (" #note ")", 1, "%d", (i1), (i2))
139#define cl_assert_equal_i_fmt(i1,i2,fmt) clar__assert_equal(__FILE__,__func__,__LINE__,#i1 " != " #i2, 1, (fmt), (int)(i1), (int)(i2))
7202ec29 140
22a2d3d5 141#define cl_assert_equal_b(b1,b2) clar__assert_equal(__FILE__,__func__,__LINE__,#b1 " != " #b2, 1, "%d", (int)((b1) != 0),(int)((b2) != 0))
cf94024c 142
22a2d3d5 143#define cl_assert_equal_p(p1,p2) clar__assert_equal(__FILE__,__func__,__LINE__,"Pointer mismatch: " #p1 " != " #p2, 1, "%p", (p1), (p2))
7202ec29 144
0f65733b 145void clar__skip(void);
2e6f06a8 146
7202ec29
RB
147void clar__fail(
148 const char *file,
22a2d3d5
UG
149 const char *func,
150 size_t line,
7202ec29
RB
151 const char *error,
152 const char *description,
153 int should_abort);
154
2e6f06a8
VM
155void clar__assert(
156 int condition,
157 const char *file,
22a2d3d5
UG
158 const char *func,
159 size_t line,
2e6f06a8
VM
160 const char *error,
161 const char *description,
162 int should_abort);
163
cf94024c
RB
164void clar__assert_equal(
165 const char *file,
22a2d3d5
UG
166 const char *func,
167 size_t line,
cf94024c
RB
168 const char *err,
169 int should_abort,
170 const char *fmt,
171 ...);
2e6f06a8
VM
172
173#endif