Skip to content

Commit

Permalink
Show test results for each test
Browse files Browse the repository at this point in the history
  • Loading branch information
majori committed Nov 30, 2023
1 parent 8593515 commit a186ab9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
3 changes: 1 addition & 2 deletions cmd/docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ func mapCommandInfos(cmds []*cobra.Command) []CommandInfo {
}

func valueTypeToString(v pflag.Value) string {
t := v.Type()
switch t {
switch t := v.Type(); t {
case "stringArray":
return "[]string"
default:
Expand Down
2 changes: 1 addition & 1 deletion features/recipe-tests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ Feature: Running tests for a recipe
Given a recipes directory
When I create a recipe with name "foo"
And I run tests for recipe "foo"
Then CLI produced an output "Tests passed successfully"
Then CLI produced an output "✅: defaults"
And no errors were printed
22 changes: 19 additions & 3 deletions internal/cli/test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"errors"
"fmt"
"path/filepath"

Expand Down Expand Up @@ -105,14 +106,29 @@ func runTest(cmd *cobra.Command, opts testOptions) error {
return nil
}

cmd.Printf("Running tests for recipe \"%s\"...\n", re.Name)
errs := re.RunTests()
for i, err := range errs {
var symbol rune
if err == nil {
symbol = '✅'
} else {
symbol = '❌'
}

cmd.Printf("%c: %s\n", symbol, re.Tests[i].Name)
}

formattedErrs := make([]error, 0, len(errs))
for i, err := range errs {
if err != nil {
return fmt.Errorf("test %s failed: %v", re.Tests[i].Name, err)
formattedErrs = append(formattedErrs, fmt.Errorf("test %s failed: %v", re.Tests[i].Name, err))
}
}

// TODO: Show pass for each test
cmd.Println("Tests passed successfully")
if len(formattedErrs) > 0 {
return fmt.Errorf("recipe tests failed: %w", errors.Join(formattedErrs...))
}

return nil
}

0 comments on commit a186ab9

Please sign in to comment.