Commit Diff


commit - a7c24adfe1ef9827b23c061f93786de05743e45a
commit + 807251c0e5fa20065b3e2f4729cd2f15fbcc38cd
blob - 1c54bfbe69667cdc5abd8e950373dbc9020ea9d1
blob + d231e9368a8d32bb9b31599c1c74c3dadad2d085
--- Makefile
+++ Makefile
@@ -4,4 +4,4 @@ README: exercise.1
 
 .PHONY: test
 test:
-	./exercise -C tests/helpers -B..
+	./exercise -C tests -D helpers
blob - fe2f1f2c9309273ef34af1edce78a5f894147519
blob + 39bb1df9fe297f8080d796da995c38f5ed1807db
--- exercise
+++ exercise
@@ -17,7 +17,7 @@ set opts(-q) 0                  ;# quiet mode
 
 # executing tests
 
-proc execute_test {countervar path} {
+proc execute_test {countervar basedir path} {
     global opts
     upvar $countervar counters
 
@@ -25,7 +25,7 @@ proc execute_test {countervar path} {
     set suite [string match $opts(-ps) [file tail $path]]
 
     # Call files relative to basedir, or ".".
-    set exe [file join $opts(-B) $path]
+    set exe [file join $basedir $path]
 
     if {$suite} {
         # Pass stderr through when calling test suites.
@@ -154,13 +154,13 @@ proc find_files_iter {resultvar dirsvar paths} {
     }
 }
 
-proc find_files {paths} {
+proc find_files {basedir paths} {
     global opts
     set dirs {}
     set files {}
     set workdir [pwd]
 
-    cd $opts(-B)
+    cd $basedir
     find_files_iter files dirs $paths
     cd $workdir
 
@@ -389,9 +389,9 @@ proc main {argc argv} {
     set counters {run 0  ok 0  fail 0  error 0}
 
     # handle command line options
-    set u {[-q] [-B dir] [-C dir] [-p k=pattern] [path ...]}
+    set u {[-q] [-C dir] [-p k=pattern] [path ...]}
     set prog [file tail $::argv0]
-    while {[getopt argv {B:C:d:p:qs:} opt arg]} {
+    while {[getopt argv {B:C:D:d:p:qs:} opt arg]} {
         if {$opt eq "?"} {
             puts stderr "usage: $prog $u"
             exit 1
@@ -419,15 +419,22 @@ proc main {argc argv} {
     if {[info exists opts(-C)]} {cd $opts(-C)}
 
     # determine the set of test files to operate on
+    set basedir $opts(-B)
     set paths [expr {$argc == 0 ? "." : $argv}]
-    set files [find_files $paths]
+    set files [find_files $basedir $paths]
 
+    # change into (late) workdir if requested with -D
+    if {[info exists opts(-D)]} {
+        set basedir [pwd]
+        cd $opts(-D)
+    }
+
     # run the tests
     dict set counters run [llength $files]  ;# tentative total run count
                                             ;# might adjust when suites run
     foreach file $files {
         print_progress $counters
-        execute_test counters $file
+        execute_test counters $basedir $file
     }
     if {!$opts(-q)} {puts [summary $counters]}
 
blob - 03e968ae46b991f23dbddefa0ffa8b0721edd154
blob + 77e4d960e4f9e2393e2bfeae09d9d74ba7ff3a71
--- exercise.1
+++ exercise.1
@@ -32,21 +32,18 @@ To be run as test suites (see below), files must match
 .Pp
 The options are as follows:
 .Bl -tag -width Ds
-.It Fl B Ar dir
-Find test files relative to the given directory.
-This effectively applies a prefix to any
-.Ar path
-arguments.
-If
-.Ar dir
-is a relative path,
-it applies to the working directory in effect after any
-.Fl C
-option.
 .It Fl C Ar dir
 Change the working directory to
 .Ar dir
 before doing anything else.
+.It Fl D Ar dir
+Change the working directory to
+.Ar dir
+before running tests.
+This is useful where
+.Ar dir
+contains common helper files
+that tests can then easily find.
 .It Fl p Sy d= Ns Ar pattern
 When searching for tests,
 only descend into directories that match the given pattern.
@@ -173,20 +170,6 @@ The helper runs
 .Nm
 with some test (shell) script to execute and compares
 the outcome to expectations.
-.Pp
-An example use of the
-.Fl B
-option is to change (with
-.Fl C )
-into a directory containing some helper files
-and then to use
-.Fl B Pa ..
-(for instance)
-to point back to the top-level test directory.
-This way
-.Ar path
-arguments can be used normally
-but tests find the helper files in their current working directory.
 .
 .Sh SEE ALSO
 .Xr sh 1
blob - e202585d2adf34ae1904bba23d4b5300ab248e5b
blob + 5474a3185b15b99805807af2482fbf6cc7de61c6
--- tests/exercise/flag/C.t
+++ tests/exercise/flag/C.t
@@ -17,12 +17,12 @@ mkdir $wd
     exit 0
 EOF
 ./assert-exercise $wd/foo \
-	"run 1  ok 0  fail 0  error 1\n" \
-	"$wd/foo.tst: no such file or directory\nerror $wd/foo.tst\n\n" \
+	"run 1  ok 1  fail 0  error 0\n" \
+	'' \
 	-C $wd <<EOF
 #!/bin/sh
-    # not found as $wd/foo.tst from within $wd
-    exit 0
+    # found as $wd/foo.tst
+    test "\$PWD" = "$wd"
 EOF
 pth=foo.tst ./assert-exercise $wd/foo \
 	"run 1  ok 1  fail 0  error 0\n" \