File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -152,10 +152,14 @@ func (t tshim) Verbose() bool {
152152// RunT is like Run but uses an interface type instead of the concrete *testing.T
153153// type to make it possible to use testscript functionality outside of go test.
154154func RunT (t T , p Params ) {
155- files , err := filepath .Glob (filepath .Join (p .Dir , "*.txt" ))
155+ glob := filepath .Join (p .Dir , "*.txt" )
156+ files , err := filepath .Glob (glob )
156157 if err != nil {
157158 t .Fatal (err )
158159 }
160+ if len (files ) == 0 {
161+ t .Fatal (fmt .Sprintf ("no scripts found matching glob: %v" , glob ))
162+ }
159163 testTempDir , err := ioutil .TempDir (os .Getenv ("GOTMPDIR" ), "go-test-script" )
160164 if err != nil {
161165 t .Fatal (err )
Original file line number Diff line number Diff line change @@ -202,6 +202,32 @@ func TestTestwork(t *testing.T) {
202202 }
203203}
204204
205+ // TestBadDir verifies that invoking testscript with a directory that either
206+ // does not exist or that contains no *.txt scripts fails the test
207+ func TestBadDir (t * testing.T ) {
208+ ft := new (fakeT )
209+ func () {
210+ defer func () {
211+ if err := recover (); err != nil {
212+ if err != errAbort {
213+ panic (err )
214+ }
215+ }
216+ }()
217+ RunT (ft , Params {
218+ Dir : "thiswillnevermatch" ,
219+ })
220+ }()
221+ wantCount := 1
222+ if got := len (ft .failMsgs ); got != wantCount {
223+ t .Fatalf ("expected %v fail message; got %v" , wantCount , got )
224+ }
225+ wantMsg := regexp .MustCompile (`no scripts found matching glob: thiswillnevermatch[/\\]\*\.txt` )
226+ if got := ft .failMsgs [0 ]; ! wantMsg .MatchString (got ) {
227+ t .Fatalf ("expected msg to match `%v`; got:\n %v" , wantMsg , got )
228+ }
229+ }
230+
205231func setSpecialVal (ts * TestScript , neg bool , args []string ) {
206232 ts .Setenv ("SPECIALVAL" , "42" )
207233}
You can’t perform that action at this time.
0 commit comments