package docsite import "testing" // TestCommandWordGlobals: the docs checker finds the command word behind // the console's global options (D-13), in every form a page may use them. func TestCommandWordGlobals(t *testing.T) { tool, app := true, false cases := []struct { in string name string tool bool }{ {"bin/acme -v serve", "serve", app}, {"bin/acme -vv serve", "serve", app}, {"./bin/acme -vvv serve --port 8080", "serve", app}, {"summer -q migrate", "migrate", tool}, {"summer --quiet migrate", "migrate", tool}, {"summer -qn migrate", "migrate", tool}, {"bin/acme --env staging migrate", "migrate", app}, {"bin/acme --env=staging migrate", "migrate", app}, {"bin/acme --no-ansi --env=staging -n migrate --force", "migrate", app}, {"bin/acme --ansi -v queue:work", "queue:work", app}, {"summer list", "list", tool}, {"summer -v list --format=json", "list", tool}, {"bin/acme help migrate", "help", app}, {"bin/acme -n help migrate", "help", app}, {"$ SUMMER_ENV=dev bin/acme --env dev -q migrate:status", "migrate:status", app}, {"go run ./cmd/summer -v docs:build --check", "docs:build", tool}, } for _, tc := range cases { name, isTool, ok := commandWord(tc.in) if !ok || name != tc.name || isTool != tc.tool { t.Errorf("commandWord(%q) = %q, %v, %v; want %q, %v, true", tc.in, name, isTool, ok, tc.name, tc.tool) } } // Only global options and no command word. for _, in := range []string{"summer -v", "bin/acme --env staging", "summer -q --no-ansi -n", "bin/acme --env"} { if name, _, ok := commandWord(in); ok { t.Errorf("commandWord(%q) found %q, want no command", in, name) } } }