35#ifndef _SIR_TESTS_SHARED_H_INCLUDED
36# define _SIR_TESTS_SHARED_H_INCLUDED
40# include "sir/errors.h"
41# include "sir/internal.h"
42# include "sir/helpers.h"
44# include "sir/filesystem.h"
46# if !defined(__WIN__) || defined(__ORANGEC__)
47# if !defined(__ORANGEC__)
50# elif defined(__WIN__)
54# if defined(__cplusplus)
63# define SIR_TESTLOGDIR "./logs/"
66# define MAKE_LOG_NAME(name) SIR_TESTLOGDIR name
69# define TEST_S(n) ((n) > 1 ? "tests" : "test")
72# define PRN_STR(str) ((str) ? (str) : SIR_RED("NULL"))
75# define PRN_PASS(pass) ((pass) ? SIR_GREENB("PASS") : SIR_REDB("FAIL"))
78# define INDENT_ITEM "\t " SIR_BULLET " "
81# define SIR_MAXTESTNAME 32
84# define SIR_CL_MAXFLAG 32
87# define SIR_CL_MAXUSAGE 256
93# define SIR_CL_PERFFLAG "--perf"
94# define SIR_CL_ONLYFLAG "--only"
95# define SIR_CL_LISTFLAG "--list"
96# define SIR_CL_LEAVELOGSFLAG "--leave-logs"
97# define SIR_CL_WAITFLAG "--wait"
98# define SIR_CL_VERSIONFLAG "--version"
99# define SIR_CL_HELPFLAG "--help"
105# define SIR_CL_ONLYUSAGE SIR_ULINE("name") " [, " SIR_ULINE("name") ", ...]"
109# define SIR_CL_PERFNAME "performance"
115# define SIR_CL_PERFDESC "Only run the performance measurement test"
116# define SIR_CL_ONLYDESC "Only run the test(s) specified"
117# define SIR_CL_LISTDESC "Prints a list of available test names for use with '" SIR_BOLD("--only") "'"
118# define SIR_CL_LEAVELOGSDESC "Log files are not deleted so that they may be examined"
119# define SIR_CL_WAITDESC "After running test(s), wait for a keypress before exiting"
120# define SIR_CL_VERSIONDESC "Prints the version of libsir that the test suite was built with"
121# define SIR_CL_HELPDESC "Shows this message"
124# define TEST_MSG(msg, ...) (void)printf("\t" msg SIR_EOL, __VA_ARGS__)
127# define TEST_MSG_0(msg) (void)printf("\t" msg SIR_EOL)
130# define ERROR_MSG(msg, ...) TEST_MSG(SIR_RED(msg), __VA_ARGS__)
133# define ERROR_MSG_0(msg) TEST_MSG_0(SIR_RED(msg))
136# if !defined(SIR_NO_TEXT_STYLING)
137# define PASSFAIL_MSG(expr, msg, ...) \
138 (void)printf(expr ? SIR_GREEN(msg) : SIR_RED(msg), __VA_ARGS__)
140# define PASSFAIL_MSG(expr, msg, ...) \
141 (void)printf(msg, __VA_ARGS__)
145# define PRINT_EXPECTED_ERROR() (void)print_test_error(true, true)
152# define PRINT_RESULT_RETURN(pass) print_test_error(pass, false)
158# if !defined(__WIN__)
159# define HANDLE_OS_ERROR(clib, msg, ...) \
162 (void)_sir_handleerr(errno); \
163 ERROR_MSG(msg ":", __VA_ARGS__); \
164 (void)print_test_error(false, false); \
167# define HANDLE_OS_ERROR(clib, msg, ...) \
169 clib ? (void)_sir_handleerr(errno) : (void)_sir_handlewin32err(GetLastError()); \
170 ERROR_MSG(msg ":", __VA_ARGS__); \
171 (void)print_test_error(false, false); \
180# if !defined(__cplusplus)
181typedef bool (*sir_test_fn)(void);
183typedef bool (*sir_test_fn)();
191 const char*
const name;
199 const char*
const flag;
217void print_intro(
size_t tgt_tests);
220void print_test_intro(
size_t num,
size_t tgt_tests,
const char*
const name);
223void print_test_outro(
size_t num,
size_t tgt_tests,
const char*
const name,
bool pass);
226void print_test_summary(
size_t tgt_tests,
size_t passed,
double elapsed);
229void print_failed_test_intro(
size_t tgt_tests,
size_t passed);
232void print_failed_test(
const char*
const name);
238bool mark_test_to_run(
const char*
const name,
sir_test* tests,
size_t num_tests);
241void print_test_list(
const sir_test* tests,
size_t num_tests);
244void print_usage_info(
const sir_cl_arg* args,
size_t num_args);
251bool print_test_error(
bool result,
bool expected);
256void print_libsir_version(
void);
269bool parse_cmd_line(
int argc,
char** argv,
const sir_cl_arg* args,
size_t num_args,
273void wait_for_keypress(
void);
277void sir_timer_start(
sir_time* timer) {
278 (void)_sir_msec_since(NULL, timer);
283double sir_timer_elapsed(
const sir_time* timer) {
285 return _sir_msec_since(timer, &now);
289long sir_timer_getres(
void);
292void sir_sleep_msec(uint32_t msec);
295size_t sir_readline(FILE* f,
char* buf,
size_t size);
298uint32_t getrand(uint32_t upper_bound);
302bool getrand_bool(uint32_t upper_bound) {
303 return ((!upper_bound) ?
true : getrand(upper_bound) % 2 == 0);
310void rmfile(
const char* filename,
bool leave_logs);
316bool enumfiles(
const char* path,
const char* search,
bool del,
unsigned* count);
318# if defined(__cplusplus)
ANSI escape sequence macros.
Public interface to libsir.
A command line argument.
Definition tests_shared.h:198
const char *const usage
(e.g.
Definition tests_shared.h:200
const char *const desc
(e.g.
Definition tests_shared.h:201
Shared command line configuration.
Definition tests_shared.h:205
bool only
–wait
Definition tests_shared.h:208
size_t to_run
–only
Definition tests_shared.h:209
bool wait
–leave-logs
Definition tests_shared.h:207
Maps a test function to a human-readable name and some metadata.
Definition tests_shared.h:190
bool pass
Whether to run the test or not.
Definition tests_shared.h:194
bool run
The function pointer.
Definition tests_shared.h:193
sir_test_fn fn
The test's name.
Definition tests_shared.h:192
Internally-used time value type.
Definition types.h:281