Use Str8 instead of const char * in tester functions
This commit is contained in:
parent
19134d0e15
commit
62dcfdaa93
@ -1,6 +1,7 @@
|
|||||||
#include "tester.h"
|
#include "tester.h"
|
||||||
#include "aliases.h"
|
#include "aliases.h"
|
||||||
#include "termcolour.h"
|
#include "termcolour.h"
|
||||||
|
#include "str8.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -31,20 +32,20 @@ void run_tests(TestFunc *func1, ...) {
|
|||||||
|
|
||||||
internal void handle_test_result(TestFuncResult result) {
|
internal void handle_test_result(TestFuncResult result) {
|
||||||
TerminalColour colour;
|
TerminalColour colour;
|
||||||
const char *result_text;
|
Str8 result_text;
|
||||||
|
|
||||||
if (result.passed) {
|
if (result.passed) {
|
||||||
colour = WAPP_TERM_COLOUR_FG_BR_GREEN;
|
colour = WAPP_TERM_COLOUR_FG_BR_GREEN;
|
||||||
result_text = "PASSED";
|
result_text = wapp_str8_lit("PASSED");
|
||||||
} else {
|
} else {
|
||||||
colour = WAPP_TERM_COLOUR_FG_BR_RED;
|
colour = WAPP_TERM_COLOUR_FG_BR_RED;
|
||||||
result_text = "FAILED";
|
result_text = wapp_str8_lit("FAILED");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("[");
|
printf("[");
|
||||||
wapp_shell_termcolour_print_text(result_text, colour);
|
wapp_shell_termcolour_print_text(&result_text, colour);
|
||||||
wapp_shell_termcolour_clear_colour();
|
wapp_shell_termcolour_clear_colour();
|
||||||
printf("] %s\n", result.name);
|
printf("] " WAPP_STR8_SPEC "\n", wapp_str8_varg(result.name));
|
||||||
|
|
||||||
if (!result.passed) {
|
if (!result.passed) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -3,22 +3,23 @@
|
|||||||
|
|
||||||
#include "misc_utils.h"
|
#include "misc_utils.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
#include "str8.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
BEGIN_C_LINKAGE
|
BEGIN_C_LINKAGE
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
#define wapp_tester_result(PASSED) ((TestFuncResult){.name = __func__, .passed = PASSED})
|
#define wapp_tester_result(PASSED) ((TestFuncResult){.name = wapp_str8_lit_ro(__func__), .passed = PASSED})
|
||||||
#define wapp_tester_run_tests(...) run_tests(__VA_ARGS__, NULL)
|
#define wapp_tester_run_tests(...) run_tests(__VA_ARGS__, NULL)
|
||||||
|
|
||||||
typedef struct test_func_result TestFuncResult;
|
typedef struct test_func_result TestFuncResult;
|
||||||
struct test_func_result {
|
struct test_func_result {
|
||||||
const char *name;
|
Str8RO name;
|
||||||
bool passed;
|
bool passed;
|
||||||
|
|
||||||
#ifdef WAPP_PLATFORM_WINDOWS
|
#ifdef WAPP_PLATFORM_WINDOWS
|
||||||
wapp_misc_utils_padding_size(sizeof(const char *) + sizeof(bool));
|
wapp_misc_utils_padding_size(sizeof(Str8RO) + sizeof(bool));
|
||||||
#endif // WAPP_PLATFORM_WINDOWS
|
#endif // WAPP_PLATFORM_WINDOWS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user