commit 5395451f9420a5190afab8926d91ed814f8408d0 from: Sven M. Hallberg date: Thu Jun 26 11:14:44 2025 UTC add -C (chdir) option commit - c690e7b81fb4ca88ebe7970f8f6fa6d30f8438da commit + 5395451f9420a5190afab8926d91ed814f8408d0 blob - 5683696daa291398786336627041302aeb81e24c blob + 1ca5191228279b55ba69e8a1fb70cde27f5a2b38 --- 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] [-p k=pattern] [path ...]} + set u {[-q] [-C dir] [-p k=pattern] [path ...]} set prog [file tail $::argv0] - while {[getopt argv {d:p:qs:} opt arg]} { + while {[getopt argv {C:d:p:qs:} opt arg]} { if {$opt eq "?"} { puts stderr "usage: $prog $u" exit 1 @@ -356,6 +356,9 @@ proc main {argc argv} { } set argc [llength $argv] + # change into workdir if requested with -C + if {[info exists opts(-C)]} {cd $opts(-C)} + set paths [expr {$argc == 0 ? "." : $argv}] set files [find_files $paths] blob - 6b78f371dccf9a58e21afaf1d2df6c56e02de7ef blob + 94fe3054ac1de2ddfbfa65ac7734fb269da87803 --- tests/assert-exercise +++ tests/assert-exercise @@ -11,6 +11,7 @@ d=`dirname $0` exe=$d/../exercise test -z "$tst" && tst=$1.tst +test -z "$pth" && pth=$tst out=$1.out err=$1.err expout=$1.expout @@ -29,7 +30,7 @@ chmod +x $tst # execute & compare shift 3 -$exe "$@" $tst 1>$out 2>$err +$exe "$@" $pth 1>$out 2>$err test "$?" = "127" && exit 127 diff -u $experr $err >&2 && \ diff -u $expout $out >&2 blob - /dev/null blob + 5e3466d53e264631da66f0799bb4d41be4958c5a (mode 755) --- /dev/null +++ tests/flag-C.t @@ -0,0 +1,36 @@ +#!/bin/sh + +set -e + +wd=$0.wd +trap "rmdir $wd" EXIT +mkdir $wd + +d=`dirname $0` +$d/assert-exercise $wd/foo \ + "total 1 run 1 ok 1 fail 0 error 0\n" \ + '' \ + <