lang: Add an extra fail scenario to our test suite

Let's us write tests for Validate failures.
This commit is contained in:
James Shubin
2024-08-22 20:12:59 -04:00
parent 8594b6e2a9
commit 8dc0d44513

View File

@@ -1403,6 +1403,7 @@ func TestAstFunc3(t *testing.T) {
const magicErrorGraph = "errGraph: "
const magicErrorInterpret = "errInterpret: "
const magicErrorAutoEdge = "errAutoEdge: "
const magicErrorValidate = "errValidate: "
const magicEmpty = "# empty!"
dir, err := util.TestDirFull()
if err != nil {
@@ -1550,6 +1551,7 @@ func TestAstFunc3(t *testing.T) {
failGraph := false
failInterpret := false
failAutoEdge := false
failValidate := false
if strings.HasPrefix(expstr, magicError) {
errStr = strings.TrimPrefix(expstr, magicError)
expstr = errStr
@@ -1594,6 +1596,11 @@ func TestAstFunc3(t *testing.T) {
expstr = errStr
failAutoEdge = true
}
if strings.HasPrefix(expstr, magicErrorValidate) {
errStr = strings.TrimPrefix(expstr, magicErrorValidate)
expstr = errStr
failValidate = true
}
}
fail := errStr != ""
@@ -2183,7 +2190,9 @@ func TestAstFunc3(t *testing.T) {
return
}
defer func() {
if err := ge.Shutdown(); err != nil {
// skip errors if failValidate is true since it
// would cause an error here too as well...
if err := ge.Shutdown(); err != nil && !failValidate {
// TODO: cause the final exit code to be non-zero
t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: engine Shutdown failed with: %+v", index, err)
@@ -2197,11 +2206,27 @@ func TestAstFunc3(t *testing.T) {
return
}
if err := ge.Validate(); err != nil { // validate the new graph
err = ge.Validate() // validate the new graph
if (!fail || !failValidate) && err != nil {
t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: error validating the new graph: %+v", index, err)
return
}
if failValidate && err != nil {
s := err.Error() // convert to string
if s != expstr {
t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: expected different error", index)
t.Logf("test #%d: err: %s", index, s)
t.Logf("test #%d: exp: %s", index, expstr)
}
return
}
if failValidate && err == nil {
t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: validate passed, expected fail", index)
return
}
// TODO: apply the global metaparams to the graph