lang: Detect sub tests with the same name

This detects identically named tests and fails the test in such a
scenario to prevent confusion.
This commit is contained in:
James Shubin
2018-07-07 12:20:23 -04:00
parent cf50fb3568
commit a287f028d1
5 changed files with 54 additions and 1 deletions

View File

@@ -26,6 +26,7 @@ import (
"testing"
"github.com/purpleidea/mgmt/lang/interfaces"
"github.com/purpleidea/mgmt/util"
"github.com/davecgh/go-spew/spew"
"github.com/kylelemons/godebug/pretty"
@@ -127,7 +128,13 @@ func TestInterpolate0(t *testing.T) {
})
}
names := []string{}
for index, tc := range testCases { // run all the tests
if util.StrInList(tc.name, names) {
t.Errorf("test #%d: duplicate sub test name of: %s", index, tc.name)
continue
}
names = append(names, tc.name)
t.Run(fmt.Sprintf("test #%d (%s)", index, tc.name), func(t *testing.T) {
code, fail, exp := tc.code, tc.fail, tc.ast
@@ -366,7 +373,13 @@ func TestInterpolateBasicStmt(t *testing.T) {
})
}
names := []string{}
for index, tc := range testCases { // run all the tests
if util.StrInList(tc.name, names) {
t.Errorf("test #%d: duplicate sub test name of: %s", index, tc.name)
continue
}
names = append(names, tc.name)
t.Run(fmt.Sprintf("test #%d (%s)", index, tc.name), func(t *testing.T) {
ast, fail, exp := tc.ast, tc.fail, tc.exp
@@ -681,7 +694,13 @@ func TestInterpolateBasicExpr(t *testing.T) {
// })
//}
names := []string{}
for index, tc := range testCases { // run all the tests
if util.StrInList(tc.name, names) {
t.Errorf("test #%d: duplicate sub test name of: %s", index, tc.name)
continue
}
names = append(names, tc.name)
t.Run(fmt.Sprintf("test #%d (%s)", index, tc.name), func(t *testing.T) {
ast, fail, exp := tc.ast, tc.fail, tc.exp

View File

@@ -29,6 +29,7 @@ import (
"github.com/purpleidea/mgmt/lang/interfaces"
"github.com/purpleidea/mgmt/lang/unification"
"github.com/purpleidea/mgmt/pgraph"
"github.com/purpleidea/mgmt/util"
)
func vertexAstCmpFn(v1, v2 pgraph.Vertex) (bool, error) {
@@ -365,12 +366,18 @@ func TestAstFunc0(t *testing.T) {
})
}
names := []string{}
for index, test := range values { // run all the tests
name, code, fail, scope, exp := test.name, test.code, test.fail, test.scope, test.graph
if name == "" {
name = "<sub test not named>"
}
if util.StrInList(name, names) {
t.Errorf("test #%d: duplicate sub test name of: %s", index, name)
continue
}
names = append(names, name)
//if index != 3 { // hack to run a subset (useful for debugging)
//if test.name != "simple operators" {
@@ -591,12 +598,18 @@ func TestAstInterpret0(t *testing.T) {
})
}
names := []string{}
for index, test := range values { // run all the tests
name, code, fail, exp := test.name, test.code, test.fail, test.graph
if name == "" {
name = "<sub test not named>"
}
if util.StrInList(name, names) {
t.Errorf("test #%d: duplicate sub test name of: %s", index, name)
continue
}
names = append(names, name)
//if index != 3 { // hack to run a subset (useful for debugging)
//if test.name != "nil" {

View File

@@ -28,6 +28,7 @@ import (
"github.com/purpleidea/mgmt/engine/resources"
_ "github.com/purpleidea/mgmt/lang/funcs/facts/core" // load facts
"github.com/purpleidea/mgmt/pgraph"
"github.com/purpleidea/mgmt/util"
multierr "github.com/hashicorp/go-multierror"
errwrap "github.com/pkg/errors"
@@ -850,12 +851,18 @@ func TestInterpretMany(t *testing.T) {
})
}
names := []string{}
for index, test := range values { // run all the tests
name, code, fail, exp := test.name, test.code, test.fail, test.graph
if name == "" {
name = "<sub test not named>"
}
if util.StrInList(name, names) {
t.Errorf("test #%d: duplicate sub test name of: %s", index, name)
continue
}
names = append(names, name)
//if index != 3 { // hack to run a subset (useful for debugging)
//if test.name != "nil" {

View File

@@ -26,6 +26,7 @@ import (
"github.com/purpleidea/mgmt/lang/interfaces"
"github.com/purpleidea/mgmt/lang/types"
"github.com/purpleidea/mgmt/util"
"github.com/davecgh/go-spew/spew"
)
@@ -115,7 +116,7 @@ func TestLexParse0(t *testing.T) {
}
{
values = append(values, test{
name: "one res",
name: "one res with param",
code: `
test "t1" {
int16 => 01134, # some comment
@@ -1412,12 +1413,18 @@ func TestLexParse0(t *testing.T) {
})
}
names := []string{}
for index, test := range values { // run all the tests
name, code, fail, exp := test.name, test.code, test.fail, test.exp
if name == "" {
name = "<sub test not named>"
}
if util.StrInList(name, names) {
t.Errorf("test #%d: duplicate sub test name of: %s", index, name)
continue
}
names = append(names, name)
//if index != 3 { // hack to run a subset (useful for debugging)
//if (index != 20 && index != 21) {

View File

@@ -26,6 +26,7 @@ import (
"github.com/purpleidea/mgmt/lang/interfaces"
"github.com/purpleidea/mgmt/lang/types"
"github.com/purpleidea/mgmt/lang/unification"
"github.com/purpleidea/mgmt/util"
)
func TestUnification1(t *testing.T) {
@@ -511,7 +512,13 @@ func TestUnification1(t *testing.T) {
})
}
names := []string{}
for index, test := range values { // run all the tests
if util.StrInList(test.name, names) {
t.Errorf("test #%d: duplicate sub test name of: %s", index, test.name)
continue
}
names = append(names, test.name)
t.Run(fmt.Sprintf("test #%d (%s)", index, test.name), func(t *testing.T) {
ast, fail, expect := test.ast, test.fail, test.expect