diff --git a/action_test.go b/action_test.go new file mode 100644 index 0000000..a599553 --- /dev/null +++ b/action_test.go @@ -0,0 +1,26 @@ +package spec + +import ( + "bytes" + "strings" + "testing" + + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +func TestActionSpec(t *testing.T) { + cmd := &cobra.Command{} + carapace.Gen(cmd).PositionalCompletion( + ActionSpec("./example/example.yaml"), + ) + + var stdout bytes.Buffer + cmd.SetOut(&stdout) + cmd.SetArgs([]string{"_carapace", "export", ""}) + cmd.Execute() + + if !strings.Contains(stdout.String(), "sub1") { + t.Error("should contain sub1 subcommand") + } +} diff --git a/example/example.yaml b/example/example.yaml index 77b3b05..048fa44 100644 --- a/example/example.yaml +++ b/example/example.yaml @@ -39,7 +39,7 @@ commands: optarg: ["first", "second", "third"] positional: - ["pos1A", "pos1B"] - - ["$files"] + - ["$files([.go, go.mod])"] - ["$directories"] - ["$(echo \"pos: $C_ARG0 flag: $C_FLAG_STYLED\")"] positionalany: ["posAny1", "posAny2"] diff --git a/spec_test.go b/spec_test.go index 5e1696f..78f5be2 100644 --- a/spec_test.go +++ b/spec_test.go @@ -37,6 +37,14 @@ func TestSpec(t *testing.T) { t.Error(out) } + if out := execute(t, example, "example", "sub1", "--env", "C_"); !strings.Contains(out, "C_CALLBACK=C_") { + t.Error(out) + } + + if out := execute(t, example, "example", "sub1", "", ""); !strings.Contains(out, "action.go") { + t.Error(out) + } + if out := execute(t, example, "example", ""); !strings.Contains(out, "sub1") { t.Error(out) }