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:
@@ -26,6 +26,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/purpleidea/mgmt/lang/interfaces"
|
"github.com/purpleidea/mgmt/lang/interfaces"
|
||||||
|
"github.com/purpleidea/mgmt/util"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/kylelemons/godebug/pretty"
|
"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
|
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) {
|
t.Run(fmt.Sprintf("test #%d (%s)", index, tc.name), func(t *testing.T) {
|
||||||
code, fail, exp := tc.code, tc.fail, tc.ast
|
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
|
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) {
|
t.Run(fmt.Sprintf("test #%d (%s)", index, tc.name), func(t *testing.T) {
|
||||||
ast, fail, exp := tc.ast, tc.fail, tc.exp
|
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
|
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) {
|
t.Run(fmt.Sprintf("test #%d (%s)", index, tc.name), func(t *testing.T) {
|
||||||
ast, fail, exp := tc.ast, tc.fail, tc.exp
|
ast, fail, exp := tc.ast, tc.fail, tc.exp
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/lang/interfaces"
|
"github.com/purpleidea/mgmt/lang/interfaces"
|
||||||
"github.com/purpleidea/mgmt/lang/unification"
|
"github.com/purpleidea/mgmt/lang/unification"
|
||||||
"github.com/purpleidea/mgmt/pgraph"
|
"github.com/purpleidea/mgmt/pgraph"
|
||||||
|
"github.com/purpleidea/mgmt/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func vertexAstCmpFn(v1, v2 pgraph.Vertex) (bool, error) {
|
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
|
for index, test := range values { // run all the tests
|
||||||
name, code, fail, scope, exp := test.name, test.code, test.fail, test.scope, test.graph
|
name, code, fail, scope, exp := test.name, test.code, test.fail, test.scope, test.graph
|
||||||
|
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name = "<sub test not named>"
|
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 != 3 { // hack to run a subset (useful for debugging)
|
||||||
//if test.name != "simple operators" {
|
//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
|
for index, test := range values { // run all the tests
|
||||||
name, code, fail, exp := test.name, test.code, test.fail, test.graph
|
name, code, fail, exp := test.name, test.code, test.fail, test.graph
|
||||||
|
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name = "<sub test not named>"
|
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 != 3 { // hack to run a subset (useful for debugging)
|
||||||
//if test.name != "nil" {
|
//if test.name != "nil" {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/engine/resources"
|
"github.com/purpleidea/mgmt/engine/resources"
|
||||||
_ "github.com/purpleidea/mgmt/lang/funcs/facts/core" // load facts
|
_ "github.com/purpleidea/mgmt/lang/funcs/facts/core" // load facts
|
||||||
"github.com/purpleidea/mgmt/pgraph"
|
"github.com/purpleidea/mgmt/pgraph"
|
||||||
|
"github.com/purpleidea/mgmt/util"
|
||||||
|
|
||||||
multierr "github.com/hashicorp/go-multierror"
|
multierr "github.com/hashicorp/go-multierror"
|
||||||
errwrap "github.com/pkg/errors"
|
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
|
for index, test := range values { // run all the tests
|
||||||
name, code, fail, exp := test.name, test.code, test.fail, test.graph
|
name, code, fail, exp := test.name, test.code, test.fail, test.graph
|
||||||
|
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name = "<sub test not named>"
|
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 != 3 { // hack to run a subset (useful for debugging)
|
||||||
//if test.name != "nil" {
|
//if test.name != "nil" {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import (
|
|||||||
|
|
||||||
"github.com/purpleidea/mgmt/lang/interfaces"
|
"github.com/purpleidea/mgmt/lang/interfaces"
|
||||||
"github.com/purpleidea/mgmt/lang/types"
|
"github.com/purpleidea/mgmt/lang/types"
|
||||||
|
"github.com/purpleidea/mgmt/util"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
)
|
)
|
||||||
@@ -115,7 +116,7 @@ func TestLexParse0(t *testing.T) {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
values = append(values, test{
|
values = append(values, test{
|
||||||
name: "one res",
|
name: "one res with param",
|
||||||
code: `
|
code: `
|
||||||
test "t1" {
|
test "t1" {
|
||||||
int16 => 01134, # some comment
|
int16 => 01134, # some comment
|
||||||
@@ -1412,12 +1413,18 @@ func TestLexParse0(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
names := []string{}
|
||||||
for index, test := range values { // run all the tests
|
for index, test := range values { // run all the tests
|
||||||
name, code, fail, exp := test.name, test.code, test.fail, test.exp
|
name, code, fail, exp := test.name, test.code, test.fail, test.exp
|
||||||
|
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name = "<sub test not named>"
|
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 != 3 { // hack to run a subset (useful for debugging)
|
||||||
//if (index != 20 && index != 21) {
|
//if (index != 20 && index != 21) {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/purpleidea/mgmt/lang/interfaces"
|
"github.com/purpleidea/mgmt/lang/interfaces"
|
||||||
"github.com/purpleidea/mgmt/lang/types"
|
"github.com/purpleidea/mgmt/lang/types"
|
||||||
"github.com/purpleidea/mgmt/lang/unification"
|
"github.com/purpleidea/mgmt/lang/unification"
|
||||||
|
"github.com/purpleidea/mgmt/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUnification1(t *testing.T) {
|
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
|
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) {
|
t.Run(fmt.Sprintf("test #%d (%s)", index, test.name), func(t *testing.T) {
|
||||||
ast, fail, expect := test.ast, test.fail, test.expect
|
ast, fail, expect := test.ast, test.fail, test.expect
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user