commit 009c5e1eaaebd3bcd09444fa9b6ceddb1af285b5 from: Sven M. Hallberg date: Sat Jul 19 18:03:37 2025 UTC add -v option (verbose mode) commit - db018202b88b529616efd0651f71681906c9036a commit + 009c5e1eaaebd3bcd09444fa9b6ceddb1af285b5 blob - 8f4b89b2cb0c37849715682fd01092e41739bcca blob + 52aa65a46fed30234eab7e9973a7aa75a15903e3 --- exercise +++ exercise @@ -14,6 +14,7 @@ set opts(-pd) {*} ;# pattern for test se set opts(-ps) {*.ts} ;# pattern for test suite executable files set opts(-pt) {*.t} ;# pattern for test executable files set opts(-q) 0 ;# quiet mode +set opts(-v) 0 ;# verbose mode # executing tests @@ -43,6 +44,9 @@ proc execute_test {job basedir path} { # Call files relative to basedir, or ".". set exe [file join $basedir $path] + # If verbose, report started tests to stdout. + if {$opts(-v)} {qputs $path} + if {$suite} { # Pass stderr through when calling test suites. set errfile @stderr @@ -68,6 +72,12 @@ proc execute_test {job basedir path} { } if {$suite} { + # Pass quoted output, adding one level of quoting. + if {$opts(-v) && [string index $out 0] eq ">"} { + qputs $out + continue + } + set scounters [sanitize_suite_counters $out] print_progress [add_suite_counters $counters $scounters] } @@ -263,6 +273,15 @@ proc notok {counters} { } } +proc qputs {s} { + global esc + if {[isatty stdout]} { + puts [string cat {*}[color 7 [list "> "]] $s {*}$esc(ce)] + } else { + puts "> $s" + } +} + proc summary {counters} { global esc @@ -417,9 +436,9 @@ proc main {argc argv} { if {[info exists env(EXERCISEDIR)]} {set opts(-D) $env(EXERCISEDIR)} # handle command line options - set u {[-q] [-B dir] [-C dir] [-D dir] [-j n] [-p k=pattern] [path ...]} + set u {[-qv] [-B dir] [-C dir] [-D dir] [-j n] [-p k=pattern] [path ...]} set prog [file tail $::argv0] - while {[getopt argv {B:C:D:j:p:q} opt arg]} { + while {[getopt argv {B:C:D:j:p:qv} opt arg]} { if {$opt eq "?"} { puts stderr "usage: $prog $u" exit 1 blob - 2c8a581d832e54901f45054573dd4418110320eb blob + 6f441dbbea6d9f7adbd9fcaef97a4843dad662d9 --- exercise.1 +++ exercise.1 @@ -8,7 +8,7 @@ . .Sh SYNOPSIS .Nm exercise -.Op Fl q +.Op Fl qv .Op Fl B Ar dir .Op Fl C Ar dir .Op Fl D Ar dir @@ -87,7 +87,9 @@ as test executables. Defaults to .Sq *.t . .It Fl q -Do not print status counters to standard output. +Be quiet. Do not print status counters to standard output. +.It Fl v +Be verbose. Print the name of each test to standard output. .El . .Ss Test Files blob - /dev/null blob + 9c7a0a4c15bf176d37410eeeaa81df06cef6ebda (mode 755) --- /dev/null +++ tests/exercise/flag/v.t @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e + +./assert-exercise $0 \ + "> $0.tst\nrun 1 ok 1 fail 0 error 0\n" \ + '' \ + -v < $0.tst\n" \ + '' \ + -qv < $0.ts\n> > test1\n> > test2\nrun 2 ok 2 fail 0 error 0\n" \ + '' \ + -v < test1" + echo "run 2 ok 1 fail 0 error 0" + echo "> test2" + echo "run 2 ok 2 fail 0 error 0" +EOF