Source file src/cmd/internal/script/engine_test.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package script
     6  
     7  import (
     8  	"context"
     9  	"slices"
    10  	"testing"
    11  )
    12  
    13  func FuzzQuoteArgs(f *testing.F) {
    14  	state, err := NewState(context.Background(), f.TempDir(), nil /* env */)
    15  	if err != nil {
    16  		f.Fatalf("failed to create state: %v", err)
    17  	}
    18  
    19  	f.Add("foo")
    20  	f.Add(`"foo"`)
    21  	f.Add(`'foo'`)
    22  	f.Fuzz(func(t *testing.T, s string) {
    23  		give := []string{s}
    24  		quoted := quoteArgs(give)
    25  		cmd, err := parse("file.txt", 42, "cmd "+quoted)
    26  		if err != nil {
    27  			t.Fatalf("quoteArgs(%q) = %q cannot be parsed: %v", give, quoted, err)
    28  		}
    29  		args := expandArgs(state, cmd.rawArgs, nil /* regexpArgs */)
    30  
    31  		if !slices.Equal(give, args) {
    32  			t.Fatalf("quoteArgs failed to round-trip.\ninput:\n\t%#q\nquoted:\n\t%q\nparsed:\n\t%#q", give, quoted, args)
    33  		}
    34  	})
    35  }
    36  

View as plain text