A klammer set's Python speaks through the log

Assembled from development commit d5f9c20b94b3. Since 5c29da5: a print() in
@eval, or in any Python a klammer set runs, is a log line -- on the
error stream under the command's name at -v 1, silent otherwise, never
in the document -- and K_log(level, text) is the builtin behind it; a
Python script using the binding keeps its own stdout. Previously such
output was lost, or on a terminal landed in the document.
This commit is contained in:
ack committed 2026-09-25 23:08:26 +02:00
1 parent 5c29da52dc
commit fc2e848e91
7 files changed
+126 -3

No files matched your search

+26
View File
@@ -273,6 +273,32 @@ else
fi
rm -rf "$CTX"
# A klammer set's Python speaks through the log (2026-09-25, TODO 69): a
# print() -- embedded Python's stdout, which was never flushed and so never
# seen, or on a terminal landed in the document -- goes to stderr at -v 1
# under the command's name, and never into the result; K_log(level, text)
# is the builtin behind it.
"$K/bin/ktext" --klammersets none -s '@eval print("from print"); K_log(2, "from K_log"); 42 @' -d >"$OUTF" 2>"$ERRF"
if [ "$(cat "$OUTF")" = "42" ] && [ ! -s "$ERRF" ]; then
pass "23. at -v 0 a print() in @eval is silent and the result is the result alone"
else
fail "23. stdout [$(cat "$OUTF")], stderr [$(plain < "$ERRF" | head -2 | tr '\n' '|')]"
fi
"$K/bin/ktext" --klammersets none -s '@eval print("from print"); K_log(2, "from K_log"); 42 @' -d -v 1 >"$OUTF" 2>"$ERRF"
# A log line is "<prefix>: <text> " (K::log ends with a space); the -v 1
# argument dump also echoes the -s text, so the checks want the log form.
if [ "$(cat "$OUTF")" = "42" ] && grep -qE 'ktext(\.exe)?: from print $' "$ERRF" && ! grep -qE ': from K_log $' "$ERRF"; then
pass "24. at -v 1 the print() is a log line on stderr; a level-2 K_log is not"
else
fail "24. stdout [$(cat "$OUTF")], stderr [$(plain < "$ERRF" | grep -v '^ ' | tr '\n' '|')]"
fi
"$K/bin/ktext" --klammersets none -s '@eval K_log(2, "from K_log"); 42 @' -d -v 2 >"$OUTF" 2>"$ERRF"
if [ "$(cat "$OUTF")" = "42" ] && grep -qE ': from K_log $' "$ERRF"; then
pass "25. at -v 2 the level-2 K_log line appears"
else
fail "25. stdout [$(cat "$OUTF")]" "$(plain < "$ERRF" | tail -3 | tr '\n' '|')"
fi
echo
echo "==========="
echo "Results: ${PASS} passed, ${FAIL} failed"