Files
webterm/go/webterm/shellsplit_test.go
T
GitHub Copilot 52a96915f0 test: add 14 fuzz tests across Go packages
Fuzz targets covering all input-processing functions:
- terminalstate: FuzzTrackerFeed, FuzzTrackerFeedIncremental
- normalize: FuzzNormalizeC1Controls, FuzzFilterDASequences
- slugify: FuzzSlugify (with unit tests)
- identity: FuzzGenerateID (with unit tests)
- replay: FuzzReplayBuffer, FuzzReplayBufferRapid
- svg_exporter: FuzzColorToHex, FuzzIsHex, FuzzRenderTerminalSVG
- shellsplit: FuzzShlexSplit (with unit test)
- twoway: FuzzTwoWayMap (with unit test)
- config: FuzzExtractLabel

All 14 targets validated with -fuzztime=3s, no panics found.
All unit tests pass with -race.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-14 16:25:55 +00:00

39 lines
898 B
Go

package webterm
import "testing"
func TestShlexSplit(t *testing.T) {
parts, err := shlexSplitImpl("echo 'hello world'")
if err != nil {
t.Fatalf("shlexSplit error = %v", err)
}
if len(parts) != 2 || parts[0] != "echo" || parts[1] != "hello world" {
t.Fatalf("unexpected split result: %v", parts)
}
}
func FuzzShlexSplit(f *testing.F) {
f.Add("echo hello")
f.Add("echo 'hello world'")
f.Add(`echo "hello world"`)
f.Add("")
f.Add("a b c d e f g h i j")
f.Add(`echo "it's a test"`)
f.Add("echo \\n")
f.Add("'unclosed")
f.Add(`"unclosed`)
f.Add("a\x00b")
f.Fuzz(func(t *testing.T, command string) {
// Must not panic; errors are acceptable for malformed input
parts, err := shlexSplitImpl(command)
if err != nil {
return
}
// If no error, parts should be non-nil
if parts == nil {
t.Errorf("shlexSplit(%q) returned nil parts without error", command)
}
})
}