commit 9a51a4f9a4d3b07e859786042208a46c9d630566 from: Sven M. Hallberg date: Thu Jun 26 11:14:46 2025 UTC add -B (basedir) option This is used as a path prefix for find_files, relative to the current workdir (after any change due to -C). An use would be to change (with -C) into a directory containing helper scripts, then use (for instance) -B.. to point back to the top-level test directory. commit - 5395451f9420a5190afab8926d91ed814f8408d0 commit + 9a51a4f9a4d3b07e859786042208a46c9d630566 blob - 1ca5191228279b55ba69e8a1fb70cde27f5a2b38 blob + 191bba64e131cbca60b8a7c34e94e4771dddc306 --- exercise +++ exercise @@ -330,9 +330,9 @@ proc main {argc argv} { set counters {total 0 run 0 ok 0 fail 0 error 0} # handle command line options - set u {[-q] [-C dir] [-p k=pattern] [path ...]} + set u {[-q] [-B dir] [-C dir] [-p k=pattern] [path ...]} set prog [file tail $::argv0] - while {[getopt argv {C:d:p:qs:} opt arg]} { + while {[getopt argv {B:C:d:p:qs:} opt arg]} { if {$opt eq "?"} { puts stderr "usage: $prog $u" exit 1 @@ -359,9 +359,18 @@ proc main {argc argv} { # change into workdir if requested with -C if {[info exists opts(-C)]} {cd $opts(-C)} + # determine the set of test files to operate on set paths [expr {$argc == 0 ? "." : $argv}] + if {[info exists opts(-B)]} { + set i 0 + foreach path $paths { + lset paths $i [file join $opts(-B) $path] + incr i + } + } set files [find_files $paths] + # run the tests dict set counters total [llength $files] ;# tentative total test count ;# might adjust when suites run foreach file $files { blob - /dev/null blob + ddea8a03d8141add00b3d2adf64053c0ceeec2d0 (mode 755) --- /dev/null +++ tests/flag-B.t @@ -0,0 +1,37 @@ +#!/bin/sh + +set -e + +cd `dirname $0` +wd=`basename $0`.wd +trap "rmdir $wd" EXIT +mkdir $wd + +./assert-exercise $wd/foo \ + "total 1 run 1 ok 1 fail 0 error 0\n" \ + '' \ + <