Repository: SimonBaeumer/commander
Pull request #75 (2019-04-10 18:35:42)

More logging
Fixes #

## Checklist

 - [x] Added unit / integration tests for windows, macOS and Linux? 
 - [x] Added a changelog entry in [CHANGELOG.md](../CHANGELOG.md)?
 - [x] Updated the documentation ([README.md](../README.md), [docs](../docs))?
 - [x] Does your change work on `Linux`, `Windows` and `macOS`?


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e9598e2..2839218 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,8 @@
 # v1.1.0
 
  - Add `not-contains` assertion on `stdout` and `stderr`
+ - Add validation for invalid data types in `stdout` and `stderr` assertions
+ - More logging for `--verbose` option on the `test` command
 
 # v1.0.1
 
diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go
index cbc8de8..f52d1b0 100644
--- a/pkg/runtime/runtime.go
+++ b/pkg/runtime/runtime.go
@@ -157,6 +157,8 @@ func runTest(test TestCase) TestResult {
 	}
 
 	log.Println("title: '"+test.Title+"'", " Command: ", cut.Cmd)
+	log.Println("title: '"+test.Title+"'", " Directory: ", cut.Dir)
+	log.Println("title: '"+test.Title+"'", " Env: ", cut.Env)
 
 	// Write test result
 	test.Result = CommandResult{
diff --git a/pkg/runtime/validator.go b/pkg/runtime/validator.go
index a9fc9e6..76d0f53 100644
--- a/pkg/runtime/validator.go
+++ b/pkg/runtime/validator.go
@@ -3,6 +3,7 @@ package runtime
 import (
 	"fmt"
 	"github.com/SimonBaeumer/commander/pkg/matcher"
+	"log"
 	"strings"
 )
 
@@ -24,7 +25,9 @@ func newValidationResult(m matcher.MatcherResult) ValidationResult {
 func Validate(test TestCase) TestResult {
 	equalMatcher := matcher.NewMatcher(matcher.Equal)
 
+	log.Println("title: '"+test.Title+"'", " Stdout-Expected: ", test.Expected.Stdout)
 	matcherResult := validateExpectedOut(test.Result.Stdout, test.Expected.Stdout)
+	log.Println("title: '"+test.Title+"'", " Stdout-Result: ", matcherResult.Success)
 	if !matcherResult.Success {
 		return TestResult{
 			ValidationResult: newValidationResult(matcherResult),
@@ -33,7 +36,9 @@ func Validate(test TestCase) TestResult {
 		}
 	}
 
+	log.Println("title: '"+test.Title+"'", " Stderr-Expected: ", test.Expected.Stderr)
 	matcherResult = validateExpectedOut(test.Result.Stderr, test.Expected.Stderr)
+	log.Println("title: '"+test.Title+"'", " Stderr-Result: ", matcherResult.Success)
 	if !matcherResult.Success {
 		return TestResult{
 			ValidationResult: newValidationResult(matcherResult),
@@ -42,7 +47,9 @@ func Validate(test TestCase) TestResult {
 		}
 	}
 
+	log.Println("title: '"+test.Title+"'", " Exit-Expected: ", test.Expected.ExitCode)
 	matcherResult = equalMatcher.Match(test.Result.ExitCode, test.Expected.ExitCode)
+	log.Println("title: '"+test.Title+"'", " Exit-Result: ", matcherResult.Success)
 	if !matcherResult.Success {
 		return TestResult{
 			ValidationResult: newValidationResult(matcherResult),
diff --git a/pkg/suite/yaml_suite.go b/pkg/suite/yaml_suite.go
index f5573fe..9f367ca 100644
--- a/pkg/suite/yaml_suite.go
+++ b/pkg/suite/yaml_suite.go
@@ -211,6 +211,11 @@ func (y *YAMLConfig) convertToExpectedOut(value interface{}) runtime.ExpectedOut
 			}
 		}
 		break
+
+	case nil:
+		break
+	default:
+		panic(fmt.Sprintf("Failed to parse Stdout or Stderr with values: %v", value))
 	}
 
 	return exp


Test patch:
diff --git a/pkg/suite/yaml_suite_test.go b/pkg/suite/yaml_suite_test.go
index d877534..d176faa 100644
--- a/pkg/suite/yaml_suite_test.go
+++ b/pkg/suite/yaml_suite_test.go
@@ -225,3 +225,22 @@ tests:
 
 	_ = ParseYAML(yaml)
 }
+
+func TestYamlSuite_ShouldFailIfArrayIsGivenToExpectedOut(t *testing.T) {
+	defer func() {
+		r := recover()
+		if r != nil {
+			assert.Contains(t, r, "Failed to parse Stdout or Stderr with values: [yeah]")
+		}
+		assert.NotNil(t, r)
+	}()
+
+	yaml := []byte(`
+tests:
+    echo hello:
+        stdout: 
+          - yeah
+`)
+
+	_ = ParseYAML(yaml)
+}