(t *testing.T)
| 16 | } |
| 17 | |
| 18 | func TestCountHits(t *testing.T) { |
| 19 | bn := basenameSet("cd.1posix", "plan9-rc.1", "rc.1plan9", "ls.1", "mwhatis.1") |
| 20 | cases := []struct { |
| 21 | name string |
| 22 | cmd string |
| 23 | want int |
| 24 | }{ |
| 25 | {"empty", "", 0}, |
| 26 | {"whitespace only", " \t ", 0}, |
| 27 | {"no token match", "tar xzvf archive.tar.gz", 0}, |
| 28 | {"single match", "ls.1 -la", 1}, |
| 29 | {"multiple matches with shell metachars", |
| 30 | "cd.1posix $(mktemp -d); plan9-rc.1 b; rc.1plan9 -c", 3}, |
| 31 | {"matches separated by pipes/redirs", |
| 32 | "plan9-rc.1|rc.1plan9>ls.1", 3}, |
| 33 | {"basename substring shouldn't match", |
| 34 | "plan9-rc.1.extra cd.1posix.suffix", 0}, |
| 35 | {"backtick and dollar split", |
| 36 | "`plan9-rc.1`$rc.1plan9", 2}, |
| 37 | {"quotes split tokens", |
| 38 | "echo \"plan9-rc.1\" 'rc.1plan9'", 2}, |
| 39 | {"ampersand and parens split", |
| 40 | "(plan9-rc.1 & rc.1plan9)", 2}, |
| 41 | } |
| 42 | for _, tc := range cases { |
| 43 | t.Run(tc.name, func(t *testing.T) { |
| 44 | got := countHits(tc.cmd, bn) |
| 45 | if got != tc.want { |
| 46 | t.Fatalf("countHits(%q) = %d, want %d", tc.cmd, got, tc.want) |
| 47 | } |
| 48 | }) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | func TestShouldShed(t *testing.T) { |
| 53 | bn := basenameSet("cd.1posix", "plan9-rc.1", "rc.1plan9", "ls.1") |
nothing calls this directly
no test coverage detected