Files
sx/examples/errors/1030-errors-log-and-comptime.sx
agra 66bdc70bf1 test: group examples into per-category folders
Move examples/*.sx and their expected/ snapshots into per-category
subfolders (examples/<category>/...). Folder = leading filename token,
with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus
runner and LSP sweep now discover each category's expected/ dir, while
issues/ stays flat. Example 1058's repo-root-relative companion import
is made file-relative. Path strings embedded in 164 snapshots were
regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
2026-06-21 14:41:34 +03:00

32 lines
1.2 KiB
Plaintext

// `log.sx` leveled logging + the `is_comptime()` builtin (ERR step E4.1,
// slice 1). `log.{warn,info,err,debug}` interpolate like `print` and write
// `LEVEL: <msg>` to stderr. `is_comptime()` is `true` under `#run` (the
// comptime interpreter) and folds to `false` in compiled code, so a gated
// branch dead-codes out of the runtime binary.
//
// (`log.error` is spelled `log.err` — `error` is a reserved keyword. The
// `process.exit` / `assert` part of E4.1 is blocked on `noreturn` codegen,
// issue 0058.)
//
// The test runner merges stderr+stdout; the log lines (stderr) precede the
// single stdout line. Expected exit code: 0.
#import "modules/std.sx";
log :: #import "modules/std/log.sx";
probe :: () -> i32 {
if is_comptime() { return 1; } // comptime interpreter path
return 2; // compiled-code path
}
CT :: #run probe(); // folds to 1 (run in the interpreter)
main :: () -> i32 {
log.warn("disk {}% full", 91);
log.info("user {} connected", "alice");
log.err("bad fd {}", 7);
log.debug("trace x={}", 42);
print("[stdout] is_comptime runtime={} comptime={}\n", probe(), CT);
return 0;
}