mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 23:08:31 +00:00
finish intellisense support and sync with upstream
This commit is contained in:
commit
ec9bfd8c56
221 changed files with 2360 additions and 1439 deletions
|
@ -27,8 +27,8 @@ STATIC_YOINK("strnwidth");
|
|||
|
||||
void __testlib_ezbenchreport(const char *form, uint64_t c1, uint64_t c2) {
|
||||
uint64_t ns1, ns2;
|
||||
ns1 = rintl(converttickstonanos(c1));
|
||||
ns2 = rintl(converttickstonanos(c2));
|
||||
ns1 = rintl(ConvertTicksToNanos(c1));
|
||||
ns2 = rintl(ConvertTicksToNanos(c2));
|
||||
(fprintf)(stderr,
|
||||
VEIL("r", "%-30s l: %,10lu𝑐 %,10lu𝑛𝑠 m: %,10lu𝑐 %,10lu𝑛𝑠\n"),
|
||||
form, c1, ns1, c2, ns2);
|
||||
|
|
|
@ -59,16 +59,31 @@ COSMOPOLITAN_C_START_
|
|||
#define EXPECT_LE(C, X) _TEST2("EXPECT_LE", C, <=, (X), #C, " ≤ ", #X, 0)
|
||||
#define EXPECT_LT(C, X) _TEST2("EXPECT_LT", C, <, (X), #C, " < ", #X, 0)
|
||||
|
||||
#define _TEST2(NAME, WANT, OP, GOT, WANTCODE, OPSTR, GOTCODE, ISFATAL) \
|
||||
do { \
|
||||
autotype(WANT) Want = (WANT); \
|
||||
autotype(GOT) Got = (GOT); \
|
||||
if (!(Want OP Got)) { \
|
||||
testlib_showerror(FILIFU NAME, OPSTR, WANTCODE OPSTR GOTCODE, \
|
||||
testlib_formatint(Want), testlib_formatint(Got)); \
|
||||
testlib_onfail2(ISFATAL); \
|
||||
} \
|
||||
} while (0)
|
||||
/**
|
||||
* Enables setup and teardown of test directories.
|
||||
*
|
||||
* If the linker says this symbol exists then, regardless of its value,
|
||||
* a unique test directory will be created at the start of each test,
|
||||
* the test will be run with that directory as its working directory,
|
||||
* and if the test succeeds it'll be removed along with any contents.
|
||||
*/
|
||||
extern char testlib_enable_tmp_setup_teardown;
|
||||
|
||||
/**
|
||||
* User-defined test setup function.
|
||||
*
|
||||
* The test runner will call this function before each TEST() if it's
|
||||
* defined by the linkage.
|
||||
*/
|
||||
void SetUp(void);
|
||||
|
||||
/**
|
||||
* User-defined test cleanup function.
|
||||
*
|
||||
* The test runner will call this function after each TEST() if it's
|
||||
* defined by the linkage.
|
||||
*/
|
||||
void TearDown(void);
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § testing library » assert or die ─╬─│┼
|
||||
|
@ -87,39 +102,12 @@ COSMOPOLITAN_C_START_
|
|||
__TEST_EQ(expect, __FILE__, __LINE__, __FUNCTION__, #WANT, #GOT, WANT, GOT, \
|
||||
__VA_ARGS__)
|
||||
|
||||
#define __TEST_EQ(KIND, FILE, LINE, FUNC, WANTCODE, GOTCODE, WANT, GOT, ...) \
|
||||
({ \
|
||||
autotype(GOT) Got = _I(GOT); \
|
||||
typeof(Got) Want = _I(WANT); \
|
||||
testlib_ontest(); \
|
||||
if (Want != Got) { \
|
||||
TESTLIB_ONFAIL(FILE, FUNC); \
|
||||
TESTLIB_SHOWERROR(testlib_showerror_##KIND##_eq, LINE, WANTCODE, \
|
||||
GOTCODE, testlib_formatint(_I(Want)), \
|
||||
testlib_formatint(_I(Got)), "" __VA_ARGS__); \
|
||||
} \
|
||||
(void)0; \
|
||||
})
|
||||
|
||||
#define ASSERT_NE(WANT, GOT, ...) \
|
||||
__TEST_NE(assert, __FILE__, __LINE__, __FUNCTION__, #WANT, #GOT, WANT, GOT, \
|
||||
__VA_ARGS__)
|
||||
#define EXPECT_NE(WANT, GOT, ...) \
|
||||
__TEST_NE(expect, __FILE__, __LINE__, __FUNCTION__, #WANT, #GOT, WANT, GOT, \
|
||||
__VA_ARGS__)
|
||||
#define __TEST_NE(KIND, FILE, LINE, FUNC, WANTCODE, GOTCODE, WANT, GOT, ...) \
|
||||
({ \
|
||||
autotype(GOT) Got = (GOT); \
|
||||
typeof(Got) Want = (WANT); \
|
||||
testlib_ontest(); \
|
||||
if (Want == Got) { \
|
||||
TESTLIB_ONFAIL(FILE, FUNC); \
|
||||
TESTLIB_SHOWERROR(testlib_showerror_##KIND##_ne, LINE, WANTCODE, \
|
||||
GOTCODE, testlib_formatint(_I(Want)), \
|
||||
testlib_formatint(_I(Got)), "" __VA_ARGS__); \
|
||||
} \
|
||||
(void)0; \
|
||||
})
|
||||
|
||||
#define ASSERT_BETWEEN(BEG, END, GOT) \
|
||||
assertBetween(FILIFU _I(BEG), _I(END), _I(GOT), \
|
||||
|
@ -245,6 +233,53 @@ COSMOPOLITAN_C_START_
|
|||
const char *file; \
|
||||
int line
|
||||
|
||||
#define TESTLIB_ONFAIL(FILE, FUNC) \
|
||||
if (g_testlib_shoulddebugbreak) DebugBreak(); \
|
||||
testlib_showerror_file = FILE; \
|
||||
testlib_showerror_func = FUNC
|
||||
|
||||
#define TESTLIB_SHOWERROR(THUNK, ...) \
|
||||
(((typeof(&testlib_showerror_))strongaddr(#THUNK)))(__VA_ARGS__)
|
||||
|
||||
#define __TEST_EQ(KIND, FILE, LINE, FUNC, WANTCODE, GOTCODE, WANT, GOT, ...) \
|
||||
({ \
|
||||
autotype(GOT) Got = _I(GOT); \
|
||||
typeof(Got) Want = _I(WANT); \
|
||||
testlib_ontest(); \
|
||||
if (Want != Got) { \
|
||||
TESTLIB_ONFAIL(FILE, FUNC); \
|
||||
TESTLIB_SHOWERROR(testlib_showerror_##KIND##_eq, LINE, WANTCODE, \
|
||||
GOTCODE, testlib_formatint(_I(Want)), \
|
||||
testlib_formatint(_I(Got)), "" __VA_ARGS__); \
|
||||
} \
|
||||
(void)0; \
|
||||
})
|
||||
|
||||
#define __TEST_NE(KIND, FILE, LINE, FUNC, WANTCODE, GOTCODE, WANT, GOT, ...) \
|
||||
({ \
|
||||
autotype(GOT) Got = (GOT); \
|
||||
typeof(Got) Want = (WANT); \
|
||||
testlib_ontest(); \
|
||||
if (Want == Got) { \
|
||||
TESTLIB_ONFAIL(FILE, FUNC); \
|
||||
TESTLIB_SHOWERROR(testlib_showerror_##KIND##_ne, LINE, WANTCODE, \
|
||||
GOTCODE, testlib_formatint(_I(Want)), \
|
||||
testlib_formatint(_I(Got)), "" __VA_ARGS__); \
|
||||
} \
|
||||
(void)0; \
|
||||
})
|
||||
|
||||
#define _TEST2(NAME, WANT, OP, GOT, WANTCODE, OPSTR, GOTCODE, ISFATAL) \
|
||||
do { \
|
||||
autotype(WANT) Want = (WANT); \
|
||||
autotype(GOT) Got = (GOT); \
|
||||
if (!(Want OP Got)) { \
|
||||
testlib_showerror(FILIFU NAME, OPSTR, WANTCODE OPSTR GOTCODE, \
|
||||
testlib_formatint(Want), testlib_formatint(Got)); \
|
||||
testlib_onfail2(ISFATAL); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
typedef void (*testfn_t)(void);
|
||||
|
||||
struct TestFixture {
|
||||
|
@ -265,14 +300,6 @@ extern const testfn_t __testcase_start[], __testcase_end[];
|
|||
extern const struct TestFixture __fixture_start[], __fixture_end[];
|
||||
extern const struct TestFixture __combo_start[], __combo_end[];
|
||||
|
||||
#define TESTLIB_ONFAIL(FILE, FUNC) \
|
||||
if (g_testlib_shoulddebugbreak) DebugBreak(); \
|
||||
testlib_showerror_file = FILE; \
|
||||
testlib_showerror_func = FUNC
|
||||
|
||||
#define TESTLIB_SHOWERROR(THUNK, ...) \
|
||||
(((typeof(&testlib_showerror_))strongaddr(#THUNK)))(__VA_ARGS__)
|
||||
|
||||
void testlib_showerror_(int line, const char *wantcode, const char *gotcode,
|
||||
char *FREED_want, char *FREED_got, const char *fmt,
|
||||
...) relegated;
|
||||
|
|
|
@ -17,15 +17,17 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/nt/process.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
void SetUp(void);
|
||||
void TearDown(void);
|
||||
#include "libc/x/x.h"
|
||||
|
||||
void testlib_finish(void) {
|
||||
if (g_testlib_failed) {
|
||||
|
@ -60,8 +62,18 @@ 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;
|
||||
for (fn = start; fn != end; ++fn) {
|
||||
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(SetUp)) weaken(SetUp)();
|
||||
errno = 0;
|
||||
SetLastError(0);
|
||||
|
@ -71,5 +83,9 @@ testonly void testlib_runtestcases(testfn_t *start, testfn_t *end,
|
|||
(*fn)();
|
||||
getpid$sysv();
|
||||
if (weaken(TearDown)) weaken(TearDown)();
|
||||
if (weaken(testlib_enable_tmp_setup_teardown)) {
|
||||
CHECK_NE(-1, chdir(cwd));
|
||||
CHECK_NE(-1, rmrf(tmp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue