mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Add integration test for redbean
This commit is contained in:
parent
01e6b3ad8d
commit
af59806a42
5 changed files with 106 additions and 41 deletions
|
@ -18,20 +18,20 @@
|
|||
* format strings are constexprs that only contain directives.
|
||||
*/
|
||||
|
||||
#define PFLINK(FMT) \
|
||||
({ \
|
||||
if (___PFLINK(FMT, strpbrk, "faAeEgG")) STATIC_YOINK("__fmt_dtoa"); \
|
||||
if (___PFLINK(FMT, strpbrk, "cmrqs")) { \
|
||||
if (___PFLINK(FMT, strchr, '#')) STATIC_YOINK("kCp437"); \
|
||||
if (___PFLINK(FMT, strstr, "%m")) STATIC_YOINK("strerror"); \
|
||||
if (!IsTiny() && (___PFLINK(FMT, strstr, "%*") || \
|
||||
___PFLINK(FMT, strpbrk, "0123456789"))) { \
|
||||
STATIC_YOINK("strnwidth"); \
|
||||
STATIC_YOINK("strnwidth16"); \
|
||||
STATIC_YOINK("wcsnwidth"); \
|
||||
} \
|
||||
} \
|
||||
FMT; \
|
||||
#define PFLINK(FMT) \
|
||||
({ \
|
||||
if (___PFLINK(FMT, strpbrk, "faAeg")) STATIC_YOINK("__fmt_dtoa"); \
|
||||
if (___PFLINK(FMT, strpbrk, "cmrqs")) { \
|
||||
if (___PFLINK(FMT, strchr, '#')) STATIC_YOINK("kCp437"); \
|
||||
if (___PFLINK(FMT, strstr, "%m")) STATIC_YOINK("strerror"); \
|
||||
if (!IsTiny() && (___PFLINK(FMT, strstr, "%*") || \
|
||||
___PFLINK(FMT, strpbrk, "0123456789"))) { \
|
||||
STATIC_YOINK("strnwidth"); \
|
||||
STATIC_YOINK("strnwidth16"); \
|
||||
STATIC_YOINK("wcsnwidth"); \
|
||||
} \
|
||||
} \
|
||||
FMT; \
|
||||
})
|
||||
|
||||
#define SFLINK(FMT) \
|
||||
|
|
|
@ -74,6 +74,7 @@ COSMOPOLITAN_C_START_
|
|||
* and if the test succeeds it'll be removed along with any contents.
|
||||
*/
|
||||
extern char testlib_enable_tmp_setup_teardown;
|
||||
extern char testlib_enable_tmp_setup_teardown_once;
|
||||
|
||||
/**
|
||||
* User-defined test setup function.
|
||||
|
@ -82,6 +83,7 @@ extern char testlib_enable_tmp_setup_teardown;
|
|||
* defined by the linkage.
|
||||
*/
|
||||
void SetUp(void);
|
||||
void SetUpOnce(void);
|
||||
|
||||
/**
|
||||
* User-defined test cleanup function.
|
||||
|
@ -90,6 +92,7 @@ void SetUp(void);
|
|||
* defined by the linkage.
|
||||
*/
|
||||
void TearDown(void);
|
||||
void TearDownOnce(void);
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § testing library » assert or die ─╬─│┼
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
static int x;
|
||||
static char cwd[PATH_MAX];
|
||||
static char tmp[PATH_MAX];
|
||||
|
||||
void testlib_finish(void) {
|
||||
if (g_testlib_failed) {
|
||||
fprintf(stderr, "%u / %u %s\n", g_testlib_failed, g_testlib_ran,
|
||||
|
@ -42,6 +46,18 @@ wontreturn void testlib_abort(void) {
|
|||
unreachable;
|
||||
}
|
||||
|
||||
static void SetupTmpDir(void) {
|
||||
snprintf(tmp, sizeof(tmp), "o/tmp/%s.%d.%d", program_invocation_short_name,
|
||||
getpid(), x++);
|
||||
CHECK_NE(-1, makedirs(tmp, 0755), "tmp=%s", tmp);
|
||||
CHECK_NE(-1, chdir(tmp), "tmp=%s", tmp);
|
||||
}
|
||||
|
||||
static void TearDownTmpDir(void) {
|
||||
CHECK_NE(-1, chdir(cwd));
|
||||
CHECK_NE(-1, rmrf(tmp));
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs all test case functions in sorted order.
|
||||
*/
|
||||
|
@ -62,18 +78,12 @@ testonly void testlib_runtestcases(testfn_t *start, testfn_t *end,
|
|||
*
|
||||
* @see ape/ape.lds
|
||||
*/
|
||||
int x;
|
||||
char cwd[PATH_MAX];
|
||||
char tmp[PATH_MAX];
|
||||
const testfn_t *fn;
|
||||
CHECK_NOTNULL(getcwd(cwd, sizeof(cwd)));
|
||||
if (weaken(testlib_enable_tmp_setup_teardown_once)) SetupTmpDir();
|
||||
if (weaken(SetUpOnce)) weaken(SetUpOnce)();
|
||||
for (x = 0, fn = start; fn != end; ++fn) {
|
||||
if (weaken(testlib_enable_tmp_setup_teardown)) {
|
||||
CHECK_NOTNULL(getcwd(cwd, sizeof(cwd)));
|
||||
snprintf(tmp, sizeof(tmp), "o/tmp/%s.%d.%d",
|
||||
program_invocation_short_name, getpid(), x++);
|
||||
CHECK_NE(-1, makedirs(tmp, 0755), "tmp=%s", tmp);
|
||||
CHECK_NE(-1, chdir(tmp), "tmp=%s", tmp);
|
||||
}
|
||||
if (weaken(testlib_enable_tmp_setup_teardown)) SetupTmpDir();
|
||||
if (weaken(SetUp)) weaken(SetUp)();
|
||||
errno = 0;
|
||||
SetLastError(0);
|
||||
|
@ -83,9 +93,8 @@ testonly void testlib_runtestcases(testfn_t *start, testfn_t *end,
|
|||
(*fn)();
|
||||
sys_getpid();
|
||||
if (weaken(TearDown)) weaken(TearDown)();
|
||||
if (weaken(testlib_enable_tmp_setup_teardown)) {
|
||||
CHECK_NE(-1, chdir(cwd));
|
||||
CHECK_NE(-1, rmrf(tmp));
|
||||
}
|
||||
if (weaken(testlib_enable_tmp_setup_teardown)) TearDownTmpDir();
|
||||
}
|
||||
if (weaken(TearDownOnce)) weaken(TearDownOnce)();
|
||||
if (weaken(testlib_enable_tmp_setup_teardown_once)) TearDownTmpDir();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue