35#ifndef _SIR_TESTS_SHARED_H_INCLUDED
36# define _SIR_TESTS_SHARED_H_INCLUDED
39# include "sir/errors.h"
40# include "sir/internal.h"
41# include "sir/helpers.h"
43# include "sir/filesystem.h"
45# if !defined(__WIN__) || defined(__ORANGEC__)
46# if !defined(__ORANGEC__)
49# elif defined(__WIN__)
53# if defined(__cplusplus)
62# define SIR_TESTLOGDIR "./logs/"
65# define MAKE_LOG_NAME(name) SIR_TESTLOGDIR name
68# define TEST_S(n) ((n) > 1 ? "tests" : "test")
71# define PRN_STR(str) ((str) ? (str) : SIR_RED("NULL"))
74# define PRN_PASS(pass) ((pass) ? SIR_GREENB("PASS") : SIR_REDB("FAIL"))
77# define INDENT_ITEM "\t " SIR_BULLET " "
80# define SIR_MAXTESTNAME 32
83# define SIR_CL_MAXFLAG 32
86# define SIR_CL_MAXUSAGE 256
92# define SIR_CL_PERFFLAG "--perf"
93# define SIR_CL_ONLYFLAG "--only"
94# define SIR_CL_LISTFLAG "--list"
95# define SIR_CL_LEAVELOGSFLAG "--leave-logs"
96# define SIR_CL_WAITFLAG "--wait"
97# define SIR_CL_VERSIONFLAG "--version"
98# define SIR_CL_HELPFLAG "--help"
104# define SIR_CL_ONLYUSAGE SIR_ULINE("name") " [, " SIR_ULINE("name") ", ...]"
108# define SIR_CL_PERFNAME "performance"
114# define SIR_CL_PERFDESC "Only run the performance measurement test"
115# define SIR_CL_ONLYDESC "Only run the test(s) specified"
116# define SIR_CL_LISTDESC "Prints a list of available test names for use with '" SIR_BOLD("--only") "'"
117# define SIR_CL_LEAVELOGSDESC "Log files are not deleted so that they may be examined"
118# define SIR_CL_WAITDESC "After running test(s), wait for a keypress before exiting"
119# define SIR_CL_VERSIONDESC "Prints the version of libsir that the test suite was built with"
120# define SIR_CL_HELPDESC "Shows this message"
123# define TEST_MSG(msg, ...) (void)printf("\t" msg SIR_EOL, __VA_ARGS__)
126# define TEST_MSG_0(msg) (void)printf("\t" msg SIR_EOL)
129# define ERROR_MSG(msg, ...) TEST_MSG(SIR_RED(msg), __VA_ARGS__)
132# define ERROR_MSG_0(msg) TEST_MSG_0(SIR_RED(msg))
135# if !defined(SIR_NO_TEXT_STYLING)
136# define PASSFAIL_MSG(expr, msg, ...) \
137 (void)printf(expr ? SIR_GREEN(msg) : SIR_RED(msg), __VA_ARGS__)
139# define PASSFAIL_MSG(expr, msg, ...) \
140 (void)printf(msg, __VA_ARGS__)
144# define PRINT_EXPECTED_ERROR() (void)print_test_error(true, true)
151# define PRINT_RESULT_RETURN(pass) print_test_error(pass, false)
157# if !defined(__WIN__)
158# define HANDLE_OS_ERROR(clib, msg, ...) \
161 (void)_sir_handleerr(errno); \
162 ERROR_MSG(msg ":", __VA_ARGS__); \
163 (void)print_test_error(false, false); \
166# define HANDLE_OS_ERROR(clib, msg, ...) \
168 clib ? (void)_sir_handleerr(errno) : (void)_sir_handlewin32err(GetLastError()); \
169 ERROR_MSG(msg ":", __VA_ARGS__); \
170 (void)print_test_error(false, false); \
179# if !defined(__cplusplus)
180typedef bool (*sir_test_fn)(void);
182typedef bool (*sir_test_fn)();
190 const char*
const name;
198 const char*
const flag;
216void print_intro(
size_t tgt_tests);
219void print_test_intro(
size_t num,
size_t tgt_tests,
const char*
const name);
222void print_test_outro(
size_t num,
size_t tgt_tests,
const char*
const name,
bool pass);
225void print_test_summary(
size_t tgt_tests,
size_t passed,
double elapsed);
228void print_failed_test_intro(
size_t tgt_tests,
size_t passed);
231void print_failed_test(
const char*
const name);
237bool mark_test_to_run(
const char*
const name,
sir_test* tests,
size_t num_tests);
240void print_test_list(
const sir_test* tests,
size_t num_tests);
243void print_usage_info(
const sir_cl_arg* args,
size_t num_args);
250bool print_test_error(
bool result,
bool expected);
255void print_libsir_version(
void);
268bool parse_cmd_line(
int argc,
char** argv,
const sir_cl_arg* args,
size_t num_args,
272void wait_for_keypress(
void);
276void sir_timer_start(
sir_time* timer) {
277 (void)_sir_msec_since(NULL, timer);
282double sir_timer_elapsed(
const sir_time* timer) {
284 return _sir_msec_since(timer, &now);
288long sir_timer_getres(
void);
291void sir_sleep_msec(uint32_t msec);
294size_t sir_readline(FILE* f,
char* buf,
size_t size);
297uint32_t getrand(uint32_t upper_bound);
301bool getrand_bool(uint32_t upper_bound) {
302 return ((!upper_bound) ?
true : getrand(upper_bound) % 2 == 0);
309void rmfile(
const char* filename,
bool leave_logs);
315bool enumfiles(
const char* path,
const char* search,
bool del,
unsigned* count);
317# if defined(__cplusplus)
ANSI escape sequence macros.
Public interface to libsir.
A command line argument.
Definition tests_shared.h:197
const char *const usage
(e.g.
Definition tests_shared.h:199
const char *const desc
(e.g.
Definition tests_shared.h:200
Shared command line configuration.
Definition tests_shared.h:204
bool only
–wait
Definition tests_shared.h:207
size_t to_run
–only
Definition tests_shared.h:208
bool wait
–leave-logs
Definition tests_shared.h:206
Maps a test function to a human-readable name and some metadata.
Definition tests_shared.h:189
bool pass
Whether to run the test or not.
Definition tests_shared.h:193
bool run
The function pointer.
Definition tests_shared.h:192
sir_test_fn fn
The test's name.
Definition tests_shared.h:191
Internally-used time value type.
Definition types.h:281