Commit Diff


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" \
+	'' \
+	<<EOF
+#!/bin/sh
+    # (sanity check base case)
+    # found as $wd/foo.tst
+    # called as $wd/foo.tst from outside $wd
+    exit 0
+EOF
+pth=foo.tst ./assert-exercise $wd/foo \
+	"total 1  run 1  ok 1  fail 0  error 0\n" \
+	'' \
+	-B $wd <<EOF
+#!/bin/sh
+    # found as foo.tst
+    # called as $wd/foo from outside $wd
+    test -f $wd/foo.tst
+EOF
+./assert-exercise $wd/foo \
+	"total 1  run 1  ok 1  fail 0  error 0\n" \
+	'' \
+	-C $wd -B.. <<EOF
+#!/bin/sh
+    # found as `basename $wd`/foo.tst
+    # called as ../$wd/foo.tst from within $wd
+    test -f foo.tst
+EOF