lang: If the test fails earlier than expected, exit early

If a test failed in stage 2 (fail2) instead of an expected fail in stage
3 (fail3) then it would continue running, which was an undefined
behaviour in our API. IOW we should not run Unify if SetScope failed.
This patch adds these additional checks to ensure our tests are more
robust.
This commit is contained in:
James Shubin
2019-06-02 18:48:48 -04:00
parent 4c6d304e60
commit da8cb40242
2 changed files with 13 additions and 9 deletions

View File

@@ -745,7 +745,7 @@ func TestAstFunc1(t *testing.T) {
reader := bytes.NewReader(output.Main) reader := bytes.NewReader(output.Main)
ast, err := LexParse(reader) ast, err := LexParse(reader)
if !fail && err != nil { if (!fail || !fail1) && err != nil {
t.Errorf("test #%d: FAIL", index) t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: lex/parse failed with: %+v", index, err) t.Errorf("test #%d: lex/parse failed with: %+v", index, err)
return return
@@ -810,7 +810,7 @@ func TestAstFunc1(t *testing.T) {
// propagate the scope down through the AST... // propagate the scope down through the AST...
err = iast.SetScope(scope) err = iast.SetScope(scope)
if !fail && err != nil { if (!fail || !fail2) && err != nil {
t.Errorf("test #%d: FAIL", index) t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: could not set scope: %+v", index, err) t.Errorf("test #%d: could not set scope: %+v", index, err)
return return
@@ -843,7 +843,7 @@ func TestAstFunc1(t *testing.T) {
Logf: xlogf, Logf: xlogf,
} }
err = unifier.Unify() err = unifier.Unify()
if !fail && err != nil { if (!fail || !fail3) && err != nil {
t.Errorf("test #%d: FAIL", index) t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: could not unify types: %+v", index, err) t.Errorf("test #%d: could not unify types: %+v", index, err)
return return
@@ -868,7 +868,7 @@ func TestAstFunc1(t *testing.T) {
// build the function graph // build the function graph
graph, err := iast.Graph() graph, err := iast.Graph()
if !fail && err != nil { if (!fail || !fail4) && err != nil {
t.Errorf("test #%d: FAIL", index) t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: functions failed with: %+v", index, err) t.Errorf("test #%d: functions failed with: %+v", index, err)
return return
@@ -1156,7 +1156,7 @@ func TestAstFunc2(t *testing.T) {
reader := bytes.NewReader(output.Main) reader := bytes.NewReader(output.Main)
ast, err := LexParse(reader) ast, err := LexParse(reader)
if !fail && err != nil { if (!fail || !fail1) && err != nil {
t.Errorf("test #%d: FAIL", index) t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: lex/parse failed with: %+v", index, err) t.Errorf("test #%d: lex/parse failed with: %+v", index, err)
return return
@@ -1221,7 +1221,7 @@ func TestAstFunc2(t *testing.T) {
// propagate the scope down through the AST... // propagate the scope down through the AST...
err = iast.SetScope(scope) err = iast.SetScope(scope)
if !fail && err != nil { if (!fail || !fail2) && err != nil {
t.Errorf("test #%d: FAIL", index) t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: could not set scope: %+v", index, err) t.Errorf("test #%d: could not set scope: %+v", index, err)
return return
@@ -1254,7 +1254,7 @@ func TestAstFunc2(t *testing.T) {
Logf: xlogf, Logf: xlogf,
} }
err = unifier.Unify() err = unifier.Unify()
if !fail && err != nil { if (!fail || !fail3) && err != nil {
t.Errorf("test #%d: FAIL", index) t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: could not unify types: %+v", index, err) t.Errorf("test #%d: could not unify types: %+v", index, err)
return return
@@ -1279,7 +1279,7 @@ func TestAstFunc2(t *testing.T) {
// build the function graph // build the function graph
graph, err := iast.Graph() graph, err := iast.Graph()
if !fail && err != nil { if (!fail || !fail4) && err != nil {
t.Errorf("test #%d: FAIL", index) t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: functions failed with: %+v", index, err) t.Errorf("test #%d: functions failed with: %+v", index, err)
return return
@@ -1366,7 +1366,7 @@ func TestAstFunc2(t *testing.T) {
ograph, err := interpret(iast) ograph, err := interpret(iast)
funcs.RUnlock() funcs.RUnlock()
if !fail && err != nil { if (!fail || !fail5) && err != nil {
t.Errorf("test #%d: FAIL", index) t.Errorf("test #%d: FAIL", index)
t.Errorf("test #%d: interpret failed with: %+v", index, err) t.Errorf("test #%d: interpret failed with: %+v", index, err)
return return

View File

@@ -3143,6 +3143,10 @@ func (obj *StmtInclude) Unify() ([]interfaces.Invariant, error) {
if obj.Name == "" { if obj.Name == "" {
return nil, fmt.Errorf("missing include name") return nil, fmt.Errorf("missing include name")
} }
if obj.class == nil {
// possible programming error
return nil, fmt.Errorf("include doesn't contain a class pointer yet")
}
// is it even possible for the signatures to match? // is it even possible for the signatures to match?
if len(obj.class.Args) != len(obj.Args) { if len(obj.class.Args) != len(obj.Args) {