An output policy for the three commands, and @cond as a true special form
A snapshot of the development tree. The substantial changes since the last one:
COMMAND OUTPUT POLICY. The three commands display text in exactly three cases,
and each owns a stream: LOGGING under "-v" greater than 0 and an ERROR before
termination go to STDERR; OUTPUT THE USER ASKED FOR goes to STDOUT. For ktext
that output is a document, so "ktext doc.kt -d | ..." is now safe -- logging
used to share the stream and land inside the document. A bare command prints
its usage and succeeds rather than failing. Colour is emitted only to a
terminal, per stream, and NO_COLOR is honoured.
"-v 1" reports every decision whose outcome you could not have read off your own
input: the klammerset that was loaded and from which file, a font's directory, a
":files" name's file, how "-o" was expanded. Higher levels are the trace.
The commands no longer warn and continue: an anomaly is an error, described with
its location. Two exceptions remain, each for a stated reason -- a condition
that is expected and temporary by design, and a judgment that is a heuristic
rather than exact.
@cond IS NOW A TRUE SPECIAL FORM, resolved at APPLICATION time rather than when
the file is read. Two consequences for a writer:
* a state variable reaches the predicate. "@@@state Flag :value true @@@
@cond *Flag* | T | F @" renders "T"; it used to see the literal "*Flag*" and
silently take the false branch. The document now behaves like a klammer
body, whose arguments are bound before its conditionals are decided.
* nothing in a discarded branch happens -- it is not read, not evaluated, not
expanded. An @eval in the branch not taken used to run anyway.
Its predicate relation is total and strict: true, True, 1; false, False, 0, and
empty; anything else is an error at the @cond rather than silently false.
@eval REACHING OUTSIDE. ":shell" and ":haskell" now keep the command's standard
error out of the document (it appears under "-v 1") and treat a nonzero exit as
an error naming what the command reported. A command that exits nonzero on
purpose -- "grep" finding no match -- says so with "|| true".
KLAMMER SETS. Several combine: "--klammersets a b c" loads all three in the
order given, sharing one namespace, with the definition modes deciding
collisions. "none" means none and may not be combined with other symbols. A
klammerset with symbol X is declared in a file X/X.k, which is what lets two
sets require the same third set without loading it twice.
TESTS. Four new suites: the kdiag command's interface, the @eval primitive's
contract with the outside world, and verbosity at both tiers. Three suites
that could not run on macOS at all now do.
Assembled from dev commit 6c8ee6c22fca.
This commit is contained in:
@@ -17,7 +17,10 @@
|
||||
# REPORTED, and a companion case checks that rendering is unaffected.
|
||||
#
|
||||
# Engine tier: the fixtures in tst/coverage/ declare their own targets with
|
||||
# @@@target, so no klammer set is involved.
|
||||
# @@@target, so no klammer set is involved -- hence "--klammersets none".
|
||||
# Since the 2026-08-14 redesign "-i" ADDS a file to whatever klammersets are
|
||||
# loaded (the SKS by default) rather than replacing them, so the exclusion has
|
||||
# to be explicit or every count here would include the SKS.
|
||||
#
|
||||
# Usage: ./coverage_test.sh (needs KLAMMERTEXT_HOME set; kdesc on PATH)
|
||||
# Exit code: 0 if all tests pass, 1 otherwise.
|
||||
@@ -34,23 +37,50 @@ green=$'\033[32m'
|
||||
bold=$'\033[1m'
|
||||
reset=$'\033[0m'
|
||||
|
||||
# Each fixture is analysed once; the tests match against the saved report.
|
||||
declare -A REPORT VREPORT
|
||||
|
||||
# GNU coreutils' "timeout" is NOT present on macOS, and Homebrew's is named
|
||||
# "gtimeout", so a bare "timeout" made this suite fail WHOLESALE there -- every
|
||||
# case, because the command never ran at all (found on Olion, 2026-08-16). The
|
||||
# guard is a safety net against a hung command, not part of what is being
|
||||
# tested, so it is optional: bound the command where the tool exists, run it
|
||||
# directly where it does not.
|
||||
if command -v timeout >/dev/null 2>&1; then
|
||||
limited() { timeout 60 "$@"; }
|
||||
elif command -v gtimeout >/dev/null 2>&1; then
|
||||
limited() { gtimeout 60 "$@"; }
|
||||
else
|
||||
limited() { "$@"; }
|
||||
fi
|
||||
|
||||
# Each fixture is analysed once and its report SAVED TO A FILE, keyed by name.
|
||||
#
|
||||
# It used to be a pair of associative arrays. "declare -A" is bash 4, and
|
||||
# macOS ships bash 3.2 as /bin/bash -- where the declaration fails and every
|
||||
# string subscript then evaluates to 0, so all five fixtures overwrote one
|
||||
# slot and the whole suite compared the wrong report against the wrong test.
|
||||
# Files have no such floor and read the same on both systems.
|
||||
REPORTS=$(mktemp -d /tmp/coverage_reports.XXXXXX)
|
||||
trap 'rm -rf "$REPORTS"' EXIT
|
||||
|
||||
for f in basic undecidable cycle split clean; do
|
||||
REPORT[$f]=$(timeout 30 "$KDESC" -i "$DIR/$f.k" --coverage 2>&1 |
|
||||
sed 's/\x1b\[[0-9;]*m//g')
|
||||
limited "$KDESC" --klammersets none -i "$DIR/$f.k" --coverage 2>&1 |
|
||||
sed 's/\x1b\[[0-9;]*m//g' > "$REPORTS/$f"
|
||||
# "all" adds the source-file column AND the empty problem categories.
|
||||
VREPORT[$f]=$(timeout 30 "$KDESC" -i "$DIR/$f.k" --coverage all 2>&1 |
|
||||
sed 's/\x1b\[[0-9;]*m//g')
|
||||
if [ -z "${REPORT[$f]}" ] || [ -z "${VREPORT[$f]}" ]; then
|
||||
limited "$KDESC" --klammersets none -i "$DIR/$f.k" --coverage all 2>&1 |
|
||||
sed 's/\x1b\[[0-9;]*m//g' > "$REPORTS/$f.all"
|
||||
if [ ! -s "$REPORTS/$f" ] || [ ! -s "$REPORTS/$f.all" ]; then
|
||||
echo "${red}FAIL${reset} $f.k produced no report"; FAIL=$((FAIL+1))
|
||||
fi
|
||||
done
|
||||
|
||||
# report FIXTURE [all] — the saved report, on stdout.
|
||||
report() { cat "$REPORTS/$1"; }
|
||||
vreport() { cat "$REPORTS/$1.all"; }
|
||||
|
||||
# vlacks NAME FIXTURE REGEX — the VERBOSE report does NOT match REGEX.
|
||||
vlacks() {
|
||||
local name="$1" fixture="$2" rgx="$3"
|
||||
if printf '%s\n' "${VREPORT[$fixture]}" | grep -Eq "$rgx"; then
|
||||
if vreport "$fixture" | grep -Eq "$rgx"; then
|
||||
echo "${red}FAIL${reset} $name — unexpected match: $rgx"; FAIL=$((FAIL+1))
|
||||
else
|
||||
echo "${green}PASS${reset} $name"; PASS=$((PASS+1))
|
||||
@@ -60,7 +90,7 @@ vlacks() {
|
||||
# vhas NAME FIXTURE REGEX — the VERBOSE report matches REGEX.
|
||||
vhas() {
|
||||
local name="$1" fixture="$2" rgx="$3"
|
||||
if printf '%s\n' "${VREPORT[$fixture]}" | grep -Eq "$rgx"; then
|
||||
if vreport "$fixture" | grep -Eq "$rgx"; then
|
||||
echo "${green}PASS${reset} $name"; PASS=$((PASS+1))
|
||||
else
|
||||
echo "${red}FAIL${reset} $name"
|
||||
@@ -71,7 +101,7 @@ vhas() {
|
||||
# has NAME FIXTURE REGEX — the report matches REGEX.
|
||||
has() {
|
||||
local name="$1" fixture="$2" rgx="$3"
|
||||
if printf '%s\n' "${REPORT[$fixture]}" | grep -Eq "$rgx"; then
|
||||
if report "$fixture" | grep -Eq "$rgx"; then
|
||||
echo "${green}PASS${reset} $name"; PASS=$((PASS+1))
|
||||
else
|
||||
echo "${red}FAIL${reset} $name"
|
||||
@@ -86,7 +116,7 @@ has() {
|
||||
section_lacks() {
|
||||
local name="$1" fixture="$2" header="$3" rgx="$4"
|
||||
local body
|
||||
body=$(printf '%s\n' "${REPORT[$fixture]}" |
|
||||
body=$(report "$fixture" |
|
||||
awk -v h="$header" 'index($0, h) == 1 { f = 1; next } f && /^$/ { exit } f')
|
||||
if [ -z "$body" ]; then
|
||||
echo "${red}FAIL${reset} $name — section [$header] not found"; FAIL=$((FAIL+1)); return
|
||||
@@ -101,7 +131,7 @@ section_lacks() {
|
||||
# lacks NAME FIXTURE REGEX — the report does NOT match REGEX.
|
||||
lacks() {
|
||||
local name="$1" fixture="$2" rgx="$3"
|
||||
if printf '%s\n' "${REPORT[$fixture]}" | grep -Eq "$rgx"; then
|
||||
if report "$fixture" | grep -Eq "$rgx"; then
|
||||
echo "${red}FAIL${reset} $name — unexpected match: $rgx"; FAIL=$((FAIL+1))
|
||||
else
|
||||
echo "${green}PASS${reset} $name"; PASS=$((PASS+1))
|
||||
@@ -243,7 +273,7 @@ echo
|
||||
echo "-- the analysis changes nothing --"
|
||||
# Coverage is a report, not a policy: a klammer whose general body cannot be
|
||||
# interpreted is still offered to every target, exactly as before.
|
||||
out=$("$KTEXT" -k none -s '@@@target ta | Target A @@@
|
||||
out=$("$KTEXT" --klammersets none -s '@@@target ta | Target A @@@
|
||||
@@e : @eval 6 * 7 @ @@ x @e@' -t ta -d 2>&1 | tr -d '\n ')
|
||||
if [ "$out" = "x42" ]; then
|
||||
echo "${green}PASS${reset} 22. an underivable klammer still renders"; PASS=$((PASS+1))
|
||||
|
||||
Reference in New Issue
Block a user