From a186ab9c32f27c7754d8333b1af4dfcdad640e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Kivim=C3=A4ki?= Date: Thu, 30 Nov 2023 13:21:37 +0200 Subject: [PATCH] Show test results for each test --- cmd/docs/main.go | 3 +-- features/recipe-tests.feature | 2 +- internal/cli/test.go | 22 +++++++++++++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cmd/docs/main.go b/cmd/docs/main.go index 47df4057..ad880d21 100644 --- a/cmd/docs/main.go +++ b/cmd/docs/main.go @@ -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: diff --git a/features/recipe-tests.feature b/features/recipe-tests.feature index 756781d9..c165f7d4 100644 --- a/features/recipe-tests.feature +++ b/features/recipe-tests.feature @@ -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 diff --git a/internal/cli/test.go b/internal/cli/test.go index 8eb070ab..e35db04a 100644 --- a/internal/cli/test.go +++ b/internal/cli/test.go @@ -1,6 +1,7 @@ package cli import ( + "errors" "fmt" "path/filepath" @@ -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 }