commit 101dd348a5859c78ec62ef2388cb675ff8a6db3d from: Sven M. Hallberg date: Sun May 25 09:35:22 2025 UTC unify pattern flags into -p[dst]=... commit - 1314fbfbc67df30377310bcdc47ef99f9ba41046 commit + 101dd348a5859c78ec62ef2388cb675ff8a6db3d blob - 0d53aa841f05888d803febdf56df90a0379fe5f8 blob + 87bba5bd2068ef0369f5ef9408b91cc6a86ddefd --- exercise +++ exercise @@ -8,9 +8,9 @@ package require Tcl 8.4 # config options -set opts(-d) {*} ;# pattern for test search directories -set opts(-p) {*.t} ;# pattern for test executable files -set opts(-s) {*.tests} ;# pattern for test suite executable files +set opts(-pd) {*} ;# pattern for test search directories +set opts(-ps) {*.tests} ;# pattern for test suite executable files +set opts(-pt) {*.t} ;# pattern for test executable files set opts(-q) 0 ;# quiet mode @@ -21,7 +21,7 @@ proc execute_test {countervar path} { upvar $countervar counters # Should the test result be integrated as a nested test suite? - set suite [string match $opts(-s) [file tail $path]] + set suite [string match $opts(-ps) [file tail $path]] # Call files in current dir with "./". set exe $path @@ -141,9 +141,9 @@ proc find_files_iter {resultvar dirsvar paths} { if {[dict exists $dirs $normpath]} continue dict set dirs $normpath {} - set subs [glob -type d -nocomplain -directory $path $opts(-d)] - set tests [glob -type f -nocomplain -directory $path $opts(-p)] - set suites [glob -type f -nocomplain -directory $path $opts(-s)] + set subs [glob -type d -nocomplain -directory $path $opts(-pd)] + set suites [glob -type f -nocomplain -directory $path $opts(-ps)] + set tests [glob -type f -nocomplain -directory $path $opts(-pt)] find_files_iter result dirs [lsort $subs] lappend result {*}[lsort $suites] @@ -323,12 +323,28 @@ proc main {argc argv} { set counters {run 0 ok 0 fail 0 error 0} # handle command line options - set u {[-q] [-d pat] [-p pat] [-s pat] [path ...]} + set u {[-q] [-p k=pattern] [path ...]} + set prog [file tail $::argv0] while {[getopt argv {d:p:qs:} opt arg]} { if {$opt eq "?"} { - puts stderr "usage: [file tail $::argv0] $u" + puts stderr "usage: $prog $u" exit 1 } + if {$opt eq "p"} { + # handle key-value options -pd=, -ps=, -pt= + if {[set i [string first "=" $arg]] == -1} { + puts stderr "$prog: -p expects key=value argument" + exit 1 + } + set k [string range $arg 0 [expr $i - 1]] + set v [string range $arg [expr $i + 1] end] + if {$k ni {d s t}} { + puts stderr "$prog: -p expects key d, s, or t" + exit 1 + } + set opt p$k + set arg $v + } set opts(-$opt) $arg } set argc [llength $argv] @@ -346,7 +362,7 @@ proc main {argc argv} { # sanity-check counters, exit 127 if mismatched (should never happen) if {[inconsistent $counters]} { - puts stderr "[file tail $::argv0]: inconsistent counters: $counters" + puts stderr "$prog: inconsistent counters, this is a bug: $counters" exit 127 } blob - e6b117aba3449ac86045ce62092acf3922ef5c61 blob + ff3863eca702df7bc6c4b4266889bdd512d5d8f9 --- exercise.1 +++ exercise.1 @@ -8,7 +8,9 @@ . .Sh SYNOPSIS .Nm exercise -.Op path +.Op Fl q +.Op Fl p Ar k Ns Sy = Ns Ar pattern +.Op Ar path ... . .Sh DESCRIPTION The @@ -29,20 +31,20 @@ To be run as test suites (see below), files must match The options are as follows: .Pp .Bl -tag -.It Fl d Ar pattern +.It Fl p Sy d= Ns Ar pattern When searching for tests, only descend into directories that match the given pattern. Defaults to .Dq * (all directories). -.It Fl p Ar pattern -Process (only) files matching the given pattern as tests. -Defaults to -.Dq *.t . -.It Fl s Ar pattern +.It Fl p Sy s= Ns Ar pattern Process (only) files matching the given pattern as test suites. Defaults to .Dq *.tests . +.It Fl p Sy t= Ns Ar pattern +Process (only) files matching the given pattern as tests. +Defaults to +.Dq *.t . .It Fl q Do not print status counters to standard output. .El