Re: [PATCH] tests: improve readability

Philippe Altherr <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <CAGdYchuf4UwFpaRAfC26AjP18gCMyxdL3__481DOLQSjAQMDSg@mail.gmail.com>
On Fri, Jun 5, 2026 at 7:50 PM Bart Schaefer <[email protected]>
wrote:

> Rather than make a lot of changes to the test output itself, maybe
> create something like Philippe's sed as a coprocess to filter the
> output (and then using that only for interactive sessions).


Maybe that's the best way to go for now. The current patch would disrupt
parts of my test script even though it's pretty simple (some sed
expressions would no longer do their job). Chances are that many other
existing workflows would be affected.

Adding a new test script instead of modifying the existing ones has the
advantage that no existing workflow will be affected and it allows us to
iterate as much as we want. In addition to that it also allows us to
introduce a more user friendly way to run tests. For example, my
script allows me to run "zsh-test -c A" instead of "make && make
check ZTST_continue=1 TESTNUM=A".

My script (shown below) already does a pretty good job but if we decide to
add something like that, I would replace the sed call with zsh code and try
to implement the things done in the patch but not in my script.

Philippe

#!/bin/zsh

function run() {
  echo "### Running: $@";
  "$@";
}

# main [-v] [<test-cases>]
function main() {
  local args=();
  while (($#)); do
    case $1 in
      -v|--verbose ) args+=(ZTST_verbose=1);;
      -c|--continue) args+=(ZTST_continue=1);;
      -*           ) echo "unrecognized option: $1" 1>&2; exit 1;;
      *            ) args+=(TESTNUM=$1);;
    esac;
    shift 1;
  done;
  run make || exit $?;
  run make check $args |& tee test.log |
    sed -E \
        -e "s/^([.]\/.*[.]ztst: skipped .*)/\x1b[1m\x1b[36m&\x1b[0m/" \
        -e "s/^([.]\/.*[.]ztst: .*)/\x1b[1m&\x1b[0m/" \
        -e "s/^(Was testing: )(.*)/\x1b[1m\1\x1b[31m\2\x1b[0m/" \
        -e "s/^(Test [.]\/.*[.]ztst failed:
)(.*)/\x1b[1m\1\x1b[31m\2\x1b[0m/" \
        -e "s/^([-][^-].*)/\x1b[31m&\x1b[0m/" \
        -e "s/^([+][^+].*)/\x1b[32m&\x1b[0m/" \
        -e "s/^(Test case skipped: .*)/\x1b[36m&\x1b[0m/" \
        -e "s/^([*]+)/\x1b[1m&\x1b[0m/" \
        -e "s/^([0-9]+ successful test scripts?, 0 failures, 0
skipped)/\x1b[1m\x1b[32m&\x1b[0m/" \
        -e "s/^([0-9]+ successful test scripts?, 0 failures), (.+
skipped)/\x1b[1m\x1b[32m\1\x1b[30m, \x1b[36m\2\x1b[0m/" \
        -e "s/^([0-9]+ successful test scripts?), (.+ failures?), (0
skipped)/\x1b[1m\1, \x1b[31m\2\x1b[30m, \3\x1b[0m/" \
        -e "s/^([0-9]+ successful test scripts?), (.+ failures?), (.+
skipped)/\x1b[1m\1, \x1b[31m\2\x1b[30m, \x1b[36m\3\x1b[0m/" \
        ||
    echo "${#${(f)$(<test.log)}} log lines";
}

main "$@";
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.