Skip to content

Commit

Permalink
Merge pull request #61 from rsteube/add-tests
Browse files Browse the repository at this point in the history
added tests
  • Loading branch information
rsteube authored May 11, 2022
2 parents 6b63ff7 + cc9572b commit 81ffd24
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
26 changes: 26 additions & 0 deletions action_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}
2 changes: 1 addition & 1 deletion example/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
8 changes: 8 additions & 0 deletions spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 81ffd24

Please sign in to comment.