Skip to content

Commit 63eb049

Browse files
committed
feat(skip,test): support hiding output by result category
1 parent e03b81a commit 63eb049

File tree

3 files changed

+54
-15
lines changed

3 files changed

+54
-15
lines changed

completions/_ztr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ case $state in
4545
# [(--quiet | -q)] <arg> [<name> [<notes>]]
4646
_arguments \
4747
"(--quiet)--quiet[Silence output]" \
48-
"(-q)-q[Silence output]"
48+
"(-q)-q[Silence output]" \
49+
"(--quiet-skip)-quiet-skip[Silence output]"
4950
ret=0
5051
;;
5152
queue|\
@@ -55,6 +56,8 @@ case $state in
5556
"(--emulate)--emulate[Emulate <shell>]" \
5657
"(--quiet)--quiet[Silence output]" \
5758
"(-q)-q[Silence output]" \
59+
"(--quiet-fail)--quiet-fail[Silence output if test fails]" \
60+
"(--quiet-pass)--quiet-pass[Silence output if test passes]" \
5861
"(--quiet-emulate)--quiet-emulate[Do not warn when a non-zsh shell is emulated.]"
5962
ret=0
6063
;;

man/man1/ztr.1

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ ztr \- zsh test runner
88

99
\fBztr clear-summary\fR
1010

11-
\fBztr queue\fR [([((\fI\-\-quiet | \-q\fR) | [\fI\-\-quiet\-fail\fR] [\fI\-\-quiet\-pass\fR])] [\fI\-\-emulate\fR <\fIshell\fR>] [\fI\-\-quiet\-emulate\fR] | \fI\-\-skip\fR [(\fI\-\-quiet | \-q\fR)]) <\fIarg\fR> [<\fIname\fR> [<\fInotes\fR>]]]\fR
11+
\fBztr queue\fR [([((\fI\-\-quiet | \-q\fR) | [\fI\-\-quiet\-fail\fR] [\fI\-\-quiet\-pass\fR])] [\fI\-\-emulate\fR <\fIshell\fR>] [\fI\-\-quiet\-emulate\fR] | \fI\-\-skip\fR [((\fI\-\-quiet | \-q\fR) | \fI\-\-\quiet\-skip\fR)]) <\fIarg\fR> [<\fIname\fR> [<\fInotes\fR>]]]\fR
1212

1313
\fBztr run-queue\fR [(\fI\-\-quiet | \-q\fR)] [<\fIname\fR>]
1414

15-
\fBztr skip\fR [(\fI\-\-quiet | \-q\fR)] <\fIarg\fR> [<\fIname\fR> [<\fInotes\fR>]]\fR
15+
\fBztr skip\fR [((\fI\-\-quiet | \-q\fR) | \fI\-\-quiet\-skip\fR)] <\fIarg\fR> [<\fIname\fR> [<\fInotes\fR>]]\fR
1616

1717
\fBztr summary\fR
1818

19-
\fBztr test\fR [(\fI\-\-quiet | \-q\fR)] <\fIarg\fR> [\fI\-\-emulate\fR <\fIshell\fR>] [\fI\-\-quiet\-emulate\fR] [<\fIname\fR> [<\fInotes\fR>]]\fR
19+
\fBztr test\fR [((\fI\-\-quiet | \-q\fR) | [\fI\-\-quiet\-fail\fR] [\fI\-\-quiet\-pass\fR])] <\fIarg\fR> [\fI\-\-emulate\fR <\fIshell\fR>] [\fI\-\-quiet\-emulate\fR] [<\fIname\fR> [<\fInotes\fR>]]\fR
2020

2121
\fBztr\fR (\fBhelp | \-\-help\fR | \fB\-h\fR)
2222

@@ -39,13 +39,13 @@ Clear the queue.
3939
Clear the summary.
4040

4141
.IP \(bu
42-
\fBqueue\fR [([((\fI\-\-quiet | \-q\fR) | [\fI\-\-quiet\-fail\fR] [\fI\-\-quiet\-pass\fR])] [\fI\-\-emulate\fR <\fIshell\fR>] [\fI\-\-quiet\-emulate\fR] | \fI\-\-skip\fR [(\fI\-\-quiet | \-q\fR)]) <\fIarg\fR> [<\fIname\fR> [<\fInotes\fR>]]]\fR
42+
\fBqueue\fR [([((\fI\-\-quiet | \-q\fR) | [\fI\-\-quiet\-fail\fR] [\fI\-\-quiet\-pass\fR])] [\fI\-\-emulate\fR <\fIshell\fR>] [\fI\-\-quiet\-emulate\fR] | \fI\-\-skip\fR [((\fI\-\-quiet | \-q\fR) | \fI\-\-\quiet\-skip\fR)]) <\fIarg\fR> [<\fIname\fR> [<\fInotes\fR>]]]\fR
4343

4444
Without arguments: print the queued tests.
4545

46-
With arguments: as `ztr test` but the test is queued rather than run.
46+
With arguments but not \fI\-\-skip\fR: as \fBtest\fR but queueing rather than running immediately.
4747

48-
\fI\-\-skip\fR queues up a \fBskip\fR command rather than a \fBtest\fR command.
48+
With arguments and \fI\-\-skip\fR: as \fBskip\fR but queueing rather than running immediately.
4949

5050
.IP \(bu
5151
\fBrun-queue\fR [(\fI\-\-quiet | \-q\fR)] [<\fIname\fR>]
@@ -61,10 +61,12 @@ If \fIZTR_BOOTSTRAP_FN\fR is defined, it is run before the first queued test.
6161
If \fIZTR_CLEAN_FN\fR is defined, it is run after the last queued test.
6262

6363
.IP \(bu
64-
\fBskip\fR [(\fI\-\-quiet | \-q\fR)] <\fIarg\fR> [<\fIname\fR> [<\fInotes\fR>]]\fR
64+
\fBskip\fR [((\fI\-\-quiet | \-q\fR) | \fI\-\-quiet\-skip\fR)] <\fIarg\fR> [<\fIname\fR> [<\fInotes\fR>]]\fR
6565

6666
Skip <arg>.
6767

68+
Pass \fI\-\-quiet\-skip\fR to output nothing. Set \fIZTR_QUIET_SKIP=1\fR to make this the default.
69+
6870
See \fBtest\fR for details about \fI\-\-quiet\fR, <\fIname\fR>, and <\fInotes\fR>.
6971

7072
.IP \(bu
@@ -73,7 +75,7 @@ See \fBtest\fR for details about \fI\-\-quiet\fR, <\fIname\fR>, and <\fInotes\fR
7375
Pretty-print summary of results.
7476

7577
.IP \(bu
76-
\fBtest\fR [(\fI\-\-quiet | \-q\fR)] <\fIarg\fR> [\fI\-\-emulate\fR <\fIshell\fR>] [\fI\-\-quiet\-emulate\fR] [<\fIname\fR> [<\fInotes\fR>]]\fR
78+
\fBtest\fR [((\fI\-\-quiet | \-q\fR) | [\fI\-\-quiet\-fail\fR] [\fI\-\-quiet\-pass\fR])] <\fIarg\fR> [\fI\-\-emulate\fR <\fIshell\fR>] [\fI\-\-quiet\-emulate\fR] [<\fIname\fR> [<\fInotes\fR>]]\fR
7779

7880
Test <\fIarg\fR>. Pretty-print result and notes unless "quiet".
7981

@@ -83,6 +85,12 @@ If your arg will error when passed to `eval`, quote it. If your arg has spaces,
8385

8486
\fI\-\-quiet\-emulate\fR keeps the \fI\-\-emulate\fR <\fIshell\fR>'s <\fIshell\fR> out of the command output.
8587

88+
Pass \fI\-\-quiet\-fail\fR to output nothing if the test fails. Set \fIZTR_QUIET_FAIL=1\fR to make this the default.
89+
90+
Pass \fI\-\-quiet\-pass\fR to output nothing if the test passes. Set \fIZTR_QUIET_PASS=1\fR to make this the default.
91+
92+
Pass \fI\-\-quiet\fR to output nothing regardless of the result.
93+
8694
Optionally pass a <\fIname\fR> as a second parameter.
8795

8896
Optionally pass <\fInotes\fR> as a third parameter (requires that you also pass a <\fIname\fR> as a second parameter). For example, noting dependencies can help with troubleshooting. In the output notes are indented.

ztr.zsh

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ __ztr_init() { # Set variables.
127127
ZTR_QUIET=${ZTR_QUIET:-0}
128128
typeset -gi ZTR_QUIET_EMULATION_MODE >/dev/null && \
129129
ZTR_QUIET_EMULATION_MODE=${ZTR_QUIET_EMULATION_MODE:-0}
130+
typeset -gi ZTR_QUIET_FAIL >/dev/null && \
131+
ZTR_QUIET_FAIL=${ZTR_QUIET_FAIL:-0}
132+
typeset -gi ZTR_QUIET_PASS >/dev/null && \
133+
ZTR_QUIET_PASS=${ZTR_QUIET_PASS:-0}
134+
typeset -gi ZTR_QUIET_SKIP >/dev/null && \
135+
ZTR_QUIET_SKIP=${ZTR_QUIET_SKIP:-0}
130136

131137
# Global read-only string variables
132138
typeset -g +r ZTR_PATH && \
@@ -231,7 +237,7 @@ __ztr_skip() { # Skip <arg>.
231237
(( ZTR_RESULTS[skipped]++ ))
232238
typeset -gAr ZTR_RESULTS
233239

234-
if (( ! __ztr_quiet )); then
240+
if (( ! __ztr_quiet && ! __ztr_quiet_skip )); then
235241
'builtin' 'echo' - "${color_skipped}SKIP$color_default ${name:-$arg}${notes:+\\n $notes}"
236242
fi
237243
}
@@ -315,20 +321,24 @@ __ztr_test() { # Test <arg> [<name> [<notes>]]. Pretty-print result and notes un
315321
__ztr_teardown
316322

317323
if (( exit_code )); then
318-
result="${color_failed}FAIL$color_default"
324+
if (( ! __ztr_quiet_fail )); then
325+
result="${color_failed}FAIL$color_default"
326+
fi
319327

320328
typeset -gA +r ZTR_RESULTS
321329
(( ZTR_RESULTS[failed]++ ))
322330
typeset -gAr ZTR_RESULTS
323331
else
324-
result="${color_passed}PASS$color_default"
332+
if (( ! __ztr_quiet_pass )); then
333+
result="${color_passed}PASS$color_default"
334+
fi
325335

326336
typeset -gA +r ZTR_RESULTS
327337
(( ZTR_RESULTS[passed]++ ))
328338
typeset -gAr ZTR_RESULTS
329339
fi
330340

331-
if (( ! __ztr_quiet )); then
341+
if [[ -n $result ]] && (( ! __ztr_quiet )); then
332342
'builtin' 'print' "$result ${name:-$arg}${notes:+\\n $notes}"
333343

334344
(( ! __ztr_quiet_emulation_mode )) && [[ $__ztr_emulation_mode_used != zsh ]] \
@@ -352,11 +362,14 @@ ztr() {
352362
local -a args exit_code flags
353363
local -i clear_queue clear_summary queue run_queue run_test skip_test summary
354364
typeset -g __ztr_emulation_mode_requested __ztr_emulation_mode_used
355-
typeset -gi __ztr_queue_skip __ztr_quiet __ztr_quiet_emulation_mode
365+
typeset -gi __ztr_queue_skip __ztr_quiet __ztr_quiet_emulation_mode __ztr_quiet_fail __ztr_quiet_pass __ztr_quiet_skip
356366

357367
__ztr_emulation_mode_requested=$ZTR_EMULATION_MODE
358-
__ztr_quiet=$ZTR_QUIET
359368
__ztr_quiet_emulation_mode=$ZTR_QUIET_EMULATION_MODE
369+
__ztr_quiet_fail=$ZTR_QUIET_FAIL
370+
__ztr_quiet_pass=$ZTR_QUIET_PASS
371+
__ztr_quiet_skip=$ZTR_QUIET_SKIP
372+
__ztr_quiet=$ZTR_QUIET
360373

361374
while (( $# )); do
362375
case $1 in
@@ -385,6 +398,21 @@ ztr() {
385398
flags+=( "--quiet-emulate" )
386399
shift
387400
;;
401+
"--quiet-fail")
402+
__ztr_quiet_fail=1
403+
flags+=( "--quiet-fail" )
404+
shift
405+
;;
406+
"--quiet-pass")
407+
__ztr_quiet_pass=1
408+
flags+=( "--quiet-pass" )
409+
shift
410+
;;
411+
"--quiet-skip")
412+
__ztr_quiet_skip=1
413+
flags+=( "--quiet-skip" )
414+
shift
415+
;;
388416
"--version"|\
389417
"-v"|\
390418
"version")

0 commit comments

Comments
 (0)