@@ -93,7 +93,7 @@ src_tests=$(awk "${awk_json}"'
9393' " ${tmp_dir} /${slug} /${slug} -tests.factor" )
9494
9595# 2. Parse Factor stdout into NDJSON segments and failures:
96- # segments: {"type":"segment","idx":N,"failed":bool,"output":"..."}
96+ # segments: {"type":"segment","idx":N,"failed":bool,"name":"..."," output":"..."}
9797# failures: {"type":"failure","line_no":N,"message":"..."}
9898parsed=$( printf ' %s\n' " ${raw_output} " | awk " ${awk_json} " '
9999 function close_segment( out, i) {
@@ -102,8 +102,8 @@ parsed=$(printf '%s\n' "${raw_output}" | awk "${awk_json}"'
102102 for (i = 1; i <= seg_n; i++) out = out (i > 1 ? "\n" : "") seg[i]
103103 sub(/^\n+/, "", out)
104104 sub(/\n+$/, "", out)
105- printf "{\"type\":\"segment\",\"idx\":%d,\"failed\":%s,\"output\":%s}\n",
106- idx, (seg_failed ? "true" : "false"), json_str(out)
105+ printf "{\"type\":\"segment\",\"idx\":%d,\"failed\":%s,\"name\":%s,\" output\":%s}\n",
106+ idx, (seg_failed ? "true" : "false"), json_str(cur_name), json_str( out)
107107 }
108108 function close_failure( body, i) {
109109 body = ""
@@ -126,6 +126,9 @@ parsed=$(printf '%s\n' "${raw_output}" | awk "${awk_json}"'
126126 BEGIN {
127127 state = "inline"
128128 idx = 0
129+ pending_name = ""
130+ cur_name = ""
131+ desc_re = "^###DESC### "
129132 header_re = "^(Unit Test|Unit Test~|Unit Test V~|Long Unit Test|Must Fail|Must Fail With|Must Not Fail|Must Infer|Must Infer As): "
130133 }
131134 state == "inline" && $0 ~ header_re {
@@ -134,6 +137,18 @@ parsed=$(printf '%s\n' "${raw_output}" | awk "${awk_json}"'
134137 seg_failed = 0
135138 seg_n = 0
136139 delete seg
140+ cur_name = pending_name
141+ pending_name = ""
142+ next
143+ }
144+ # A generated "###DESC### <description>" line labels the test that
145+ # follows it (it is printed before that test' " '" ' s "Unit Test:" header).
146+ # Stash it as the upcoming segment' " '" ' s name; never add it to any
147+ # segment' " '" ' s output. Concept exercises emit no such lines.
148+ state == "inline" && $0 ~ desc_re {
149+ line = $0
150+ sub(desc_re, "", line)
151+ pending_name = line
137152 next
138153 }
139154 state == "inline" && $0 == "###FAIL_BEGIN###" {
@@ -188,7 +203,7 @@ failures=$(printf '%s\n' "${parsed}" | awk '/"type":"failure"/' || true)
188203
189204# 3. If no segments emitted, surface a top-level error from the raw output.
190205if [[ -z " ${segments} " ]]; then
191- cleaned=$( printf ' %s\n' " ${raw_output} " | awk ' /^\([UO]\) /{exit} {print}' \
206+ cleaned=$( printf ' %s\n' " ${raw_output} " | awk ' /^\([UO]\) /{exit} !/^###DESC### / {print}' \
192207 | awk '
193208 NF {
194209 print
@@ -229,8 +244,10 @@ jq -n \
229244 else "fail" end
230245 else "pass" end
231246 ) as $status
247+ | ($seg.name // "") as $label
232248 | {
233- name: ("Test " + ((.key + 1) | tostring)),
249+ name: (if ($label | length) > 0 then $label
250+ else ("Test " + ((.key + 1) | tostring)) end),
234251 status: $status,
235252 test_code: ($src.test_code // ""),
236253 }
0 commit comments