@@ -332,6 +332,44 @@ func TestSpecifyingFormatters(t *testing.T) {
332
332
}),
333
333
)
334
334
})
335
+
336
+ t .Run ("bad names" , func (t * testing.T ) {
337
+ for _ , name := range []string {"foo$" , "/bar" , "baz%" } {
338
+ treefmt (t ,
339
+ withArgs ("--formatters" , name ),
340
+ withError (func (as * require.Assertions , err error ) {
341
+ as .ErrorContains (err , fmt .Sprintf ("formatter name %q is invalid" , name ))
342
+ }),
343
+ )
344
+
345
+ t .Setenv ("TREEFMT_FORMATTERS" , name )
346
+
347
+ treefmt (t ,
348
+ withError (func (as * require.Assertions , err error ) {
349
+ as .ErrorContains (err , fmt .Sprintf ("formatter name %q is invalid" , name ))
350
+ }),
351
+ )
352
+
353
+ t .Setenv ("TREEFMT_FORMATTERS" , "" )
354
+
355
+ cfg .FormatterConfigs [name ] = & config.Formatter {
356
+ Command : "echo" ,
357
+ Includes : []string {"*" },
358
+ }
359
+
360
+ test .WriteConfig (t , configPath , cfg )
361
+
362
+ treefmt (t ,
363
+ withError (func (as * require.Assertions , err error ) {
364
+ as .ErrorContains (err , fmt .Sprintf ("formatter name %q is invalid" , name ))
365
+ }),
366
+ )
367
+
368
+ delete (cfg .FormatterConfigs , name )
369
+
370
+ test .WriteConfig (t , configPath , cfg )
371
+ }
372
+ })
335
373
}
336
374
337
375
func TestIncludesAndExcludes (t * testing.T ) {
@@ -1633,7 +1671,7 @@ func TestStdin(t *testing.T) {
1633
1671
treefmt (t ,
1634
1672
withArgs ("--stdin" , "../test.nix" ),
1635
1673
withError (func (as * require.Assertions , err error ) {
1636
- as .ErrorContains (err , fmt . Sprintf ( "path ../test.nix not inside the tree root %s" , tempDir ) )
1674
+ as .ErrorContains (err , "path ../test.nix not inside the tree root " + tempDir )
1637
1675
}),
1638
1676
withStderr (func (out []byte ) {
1639
1677
as .Contains (string (out ), "Error: path ../test.nix not inside the tree root" )
0 commit comments