Skip to content

Commit

Permalink
assert location in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dsainati1 committed Jul 19, 2023
1 parent 291d81c commit 1e282eb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions runtime/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/interpreter"
"github.com/onflow/cadence/runtime/sema"
"github.com/onflow/cadence/runtime/stdlib"
)

func TestRuntimeError(t *testing.T) {
Expand Down Expand Up @@ -605,6 +606,22 @@ func TestRuntimeDefaultFunctionConflictPrintingError(t *testing.T) {
)
require.Error(t, err)
require.Contains(t, err.Error(), "access(all) resource R: TestInterfaces.A, TestInterfaces.B {}")

var errType *sema.CheckerError
require.ErrorAs(t, err, &errType)

checkerErr := err.(Error).
Err.(interpreter.Error).
Err.(*stdlib.InvalidContractDeploymentError).
Err.(*ParsingCheckingError).
Err.(*sema.CheckerError)

var specificErrType *sema.DefaultFunctionConflictError
require.ErrorAs(t, checkerErr.Errors[0], &specificErrType)

errorRange := checkerErr.Errors[0].(*sema.DefaultFunctionConflictError).Range

require.Equal(t, errorRange.StartPos.Line, 4)
}

func TestRuntimeMultipleInterfaceDefaultImplementationsError(t *testing.T) {
Expand Down Expand Up @@ -718,4 +735,20 @@ func TestRuntimeMultipleInterfaceDefaultImplementationsError(t *testing.T) {
)
require.Error(t, err)
require.Contains(t, err.Error(), "access(all) resource R: TestInterfaces.A, TestInterfaces.B {}")

var errType *sema.CheckerError
require.ErrorAs(t, err, &errType)

checkerErr := err.(Error).
Err.(interpreter.Error).
Err.(*stdlib.InvalidContractDeploymentError).
Err.(*ParsingCheckingError).
Err.(*sema.CheckerError)

var specificErrType *sema.MultipleInterfaceDefaultImplementationsError
require.ErrorAs(t, checkerErr.Errors[0], &specificErrType)

errorRange := checkerErr.Errors[0].(*sema.MultipleInterfaceDefaultImplementationsError).Range

require.Equal(t, errorRange.StartPos.Line, 4)
}

0 comments on commit 1e282eb

Please sign in to comment.