Skip to content

Commit

Permalink
assert: fix color
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jul 16, 2023
1 parent 98dc3cb commit fda7002
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func Diff(expected, actual string) string {
highlighted := make([]string, 0)
for _, line := range strings.Split(diff, "\n") {
switch {
case strings.HasPrefix(line, "+"):
highlighted = append(highlighted, fmt.Sprintf("\033[0;31m%v\033[0m", line))
case strings.HasPrefix(line, "-"):
highlighted = append(highlighted, fmt.Sprintf("\033[0;31m%v\033[0m", line))
case strings.HasPrefix(line, "+"):
highlighted = append(highlighted, fmt.Sprintf("\033[0;32m%v\033[0m", line))
default:
highlighted = append(highlighted, line)
Expand Down
11 changes: 7 additions & 4 deletions pkg/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,20 @@ func Package(t *testing.T, pkg string) (f func(func(s *Sandbox))) {

carapace.Gen(cmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
args := []string{"run", "-cover", pkg, "_carapace", "export", ""}
args := []string{"run"}
if coverdir := env.CoverDir(); coverdir != "" {
c.Setenv("GOCOVERDIR", env.CoverDir())
args = append(args, "-cover")
}

args = append(args, pkg, "_carapace", "export", "")
args = append(args, c.Args...)
args = append(args, c.Value)

var err error
if c.Dir, err = os.Getwd(); err != nil { // `go run` needs to run in actual workdir and not the sandbox dir
return carapace.ActionMessage(err.Error())
}
if coverdir := env.CoverDir(); coverdir != "" {
c.Setenv("GOCOVERDIR", env.CoverDir())
}
return carapace.ActionExecCommand("go", args...)(func(output []byte) carapace.Action {
return carapace.ActionImport(output)
}).Invoke(c).ToA()
Expand Down

0 comments on commit fda7002

Please sign in to comment.