feat: bux test command + Std::Test module
- Add 'bux test' CLI command: discovers .bux files in tests/, compiles each into a temp package, runs them, reports pass/fail - Add Std::Test module with Assert, AssertEqInt, AssertTrue, AssertFalse, Fail - Add bux_exit and bux_assert C runtime primitives - Update README.md and docs/BuildAndTest.md
This commit is contained in:
@@ -1324,6 +1324,20 @@ const char* bux_socket_error(void) {
|
||||
return strerror(errno);
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Test / Assert primitives
|
||||
* ============================================================================ */
|
||||
|
||||
void bux_exit(int code) {
|
||||
exit(code);
|
||||
}
|
||||
|
||||
void bux_assert(int cond, const char* file, int line, const char* expr) {
|
||||
if (!cond) {
|
||||
fprintf(stderr, "ASSERT FAILED: %s at %s:%d\n", expr, file, line);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* Cryptography primitives (OpenSSL)
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
module Std::Test {
|
||||
|
||||
extern func bux_exit(code: int);
|
||||
extern func bux_assert(cond: int, file: String, line: int, expr: String);
|
||||
|
||||
func Test_Exit(code: int) {
|
||||
bux_exit(code);
|
||||
}
|
||||
|
||||
func Test_Assert(cond: bool) {
|
||||
bux_assert(cond as int, "", 0, "");
|
||||
}
|
||||
|
||||
func Test_AssertEqInt(a: int, b: int) {
|
||||
if a != b {
|
||||
PrintLine("ASSERT_EQ FAILED:");
|
||||
PrintInt(a);
|
||||
PrintLine(" != ");
|
||||
PrintInt(b);
|
||||
bux_exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
func Test_AssertTrue(cond: bool) {
|
||||
if !cond {
|
||||
PrintLine("ASSERT_TRUE FAILED");
|
||||
bux_exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
func Test_AssertFalse(cond: bool) {
|
||||
if cond {
|
||||
PrintLine("ASSERT_FALSE FAILED");
|
||||
bux_exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Fail(msg: String) {
|
||||
PrintLine("FAIL:");
|
||||
PrintLine(msg);
|
||||
bux_exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user