From 640983c1250704dba0f5425a364db015cd9bc2b4 Mon Sep 17 00:00:00 2001 From: Sevki Date: Wed, 16 Aug 2017 22:54:50 +0200 Subject: [PATCH] use t.Run for tests using `t.Run` instead including the test name in error message is a more idiomatic way of testing things in go. Since this feature was added to go in 1.7 release and the travis config explicitly specifies 1.4 and 1.5 (2 and 2,5 year old releases) as test targets this change will break the CI builds, therefore this commit also proposes dropping those releases in favour of adding a newer version of go (1.8) as the test target. Signed-off-by: Sevki --- .travis.yml | 3 +-- main_test.go | 33 +++++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index f8de2ef..0802a6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: go sudo: false go: - - 1.4 - - 1.5 + - 1.8 - tip before_install: - go get github.com/axw/gocov/gocov diff --git a/main_test.go b/main_test.go index b1bf2bc..ba99cba 100644 --- a/main_test.go +++ b/main_test.go @@ -16,9 +16,7 @@ limitations under the License. package jsonnet -import ( - "testing" -) +import "testing" // Just a few simple sanity tests for now. Eventually we'll share end-to-end tests with the C++ // implementation but unsure if that should be done here or via some external framework. @@ -52,18 +50,21 @@ var mainTests = []mainTest{ func TestMain(t *testing.T) { for _, test := range mainTests { - vm := MakeVM() - output, err := vm.EvaluateSnippet(test.name, test.input) - var errString string - if err != nil { - errString = err.Error() - } - if errString != test.errString { - t.Errorf("%s: error result does not match. got\n\t%+v\nexpected\n\t%+v", - test.input, errString, test.errString) - } - if err == nil && output != test.golden { - t.Errorf("%s: got\n\t%+v\nexpected\n\t%+v", test.name, output, test.golden) - } + t.Run(test.name, func(t *testing.T) { + vm := MakeVM() + output, err := vm.EvaluateSnippet(test.name, test.input) + var errString string + if err != nil { + errString = err.Error() + } + + if errString != test.errString { + t.Errorf("%s: error result does not match. got\n\t%+v\nexpected\n\t%+v", + test.input, errString, test.errString) + } + if err == nil && output != test.golden { + t.Errorf("got\n\t%+v\nexpected\n\t%+v", output, test.golden) + } + }) } }