aboutsummaryrefslogtreecommitdiff
path: root/stdlib/stdlib.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-10 23:46:26 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-03-10 23:46:26 -0400
commit9885ab11632f91b78b8e077956d2b34373ddde30 (patch)
treed14866d498e1d5e083913581fa11b0d2bdaddf89 /stdlib/stdlib.h
parent038a9f548e2e26c90083fc95a459b63dc848daf7 (diff)
For doctests, only print code if there's no expected value. If there's
an error, show the mismatch below the stack trace.
Diffstat (limited to 'stdlib/stdlib.h')
-rw-r--r--stdlib/stdlib.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h
index 1625dd88..93bd4a02 100644
--- a/stdlib/stdlib.h
+++ b/stdlib/stdlib.h
@@ -30,11 +30,21 @@ __attribute__((format(printf, 4, 5)))
_Noreturn void fail_source(const char *filename, int64_t start, int64_t end, const char *fmt, ...);
Text_t builtin_last_err();
void start_test(const char *filename, int64_t start, int64_t end);
-void end_test(const void *expr, const TypeInfo_t *type, const char *expected);
+void end_test(const void *expr, const TypeInfo_t *type);
+void test_value(const void *expr, const TypeInfo_t *type, const char *expected);
#define test(expr, typeinfo, expected, start, end) {\
- start_test(__SOURCE_FILE__, start, end); \
+ const char *_expected = expected; \
+ if (!_expected || !_expected[0]) { \
+ start_test(__SOURCE_FILE__, start, end); \
+ } \
auto _expr = expr; \
- end_test(&_expr, typeinfo, expected); }
+ if (!_expected || !_expected[0]) { \
+ end_test(&_expr, typeinfo); \
+ } else { \
+ test_value(&_expr, typeinfo, _expected); \
+ } \
+}
+
void say(Text_t text, bool newline);
Text_t ask(Text_t prompt, bool bold, bool force_tty);
_Noreturn void tomo_exit(Text_t text, int32_t status);