| 1 | package evidence |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestCommandMatches(t *testing.T) { |
| 6 | cases := []struct { |
| 7 | name string |
| 8 | cited string |
| 9 | ran string |
| 10 | want bool |
| 11 | }{ |
| 12 | {"exact", "go test ./...", "go test ./...", true}, |
| 13 | {"cd prefix dropped", "git merge upstream/main-v2 --ff-only", |
| 14 | "cd /repo && git merge upstream/main-v2 --ff-only", true}, |
| 15 | {"flag drift inside compound", "rm -v scripts/test_lines.txt && ls scripts/test_lines.txt 2>&1", |
| 16 | "rm -v scripts/test_lines.txt && ls -la scripts/test_lines.txt 2>&1 || true", true}, |
| 17 | {"quote style drift", `test -f test-tools.md && echo 'still exists' || echo 'deleted'`, |
| 18 | `test -f test-tools.md && echo "still exists" || echo "deleted"`, true}, |
| 19 | {"quoted pipe is not a segment separator", `printf "%s\n" "a | b"`, |
| 20 | `printf '%s\n' 'a | b'`, true}, |
| 21 | {"pipe tail dropped", "go test ./internal/tool/... -count=1 -timeout 60s", |
| 22 | "cd /f/Reasonix && go test ./internal/tool/... -count=1 -timeout 60s 2>&1 | tail -10", true}, |
| 23 | {"whitespace collapse", "go test ./...", "go test ./...", true}, |
| 24 | {"different command rejected", "go test ./...", "go vet ./...", false}, |
| 25 | {"extra cited token rejected", "go test ./a/... ./b/...", "go test ./a/...", false}, |
| 26 | {"bare token needs exact", "ls", "ls -la scripts", false}, |
| 27 | {"bare token exact ok", "ls", "ls", true}, |
| 28 | {"empty cited", "", "go test ./...", false}, |
| 29 | {"comment lines ignored", "shuf -i 1-30 -n 10", |
| 30 | "# pick lines to delete\nshuf -i 1-30 -n 10 | sort -rn", true}, |
| 31 | } |
| 32 | for _, tc := range cases { |
| 33 | t.Run(tc.name, func(t *testing.T) { |
| 34 | if got := CommandMatches(tc.cited, tc.ran); got != tc.want { |
| 35 | t.Fatalf("CommandMatches(%q, %q) = %v, want %v", tc.cited, tc.ran, got, tc.want) |
| 36 | } |
| 37 | }) |
| 38 | } |
| 39 | } |
| 40 |