Skip to content

Commit

Permalink
backport and use RequireErrorAs, remove duplicated ExpectCheckerErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Nov 23, 2020
1 parent 1030e61 commit c64e867
Showing 1 changed file with 2 additions and 36 deletions.
38 changes: 2 additions & 36 deletions runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/onflow/cadence/runtime/interpreter"
"github.com/onflow/cadence/runtime/sema"
"github.com/onflow/cadence/runtime/stdlib"
"github.com/onflow/cadence/runtime/tests/checker"
"github.com/onflow/cadence/runtime/tests/utils"
)

Expand Down Expand Up @@ -3341,7 +3342,7 @@ func TestRuntimeTransactionTopLevelDeclarations(t *testing.T) {
require.IsType(t, Error{}, err)
err = err.(Error).Unwrap()

errs := ExpectCheckerErrors(t, err, 1)
errs := checker.ExpectCheckerErrors(t, err, 1)

assert.IsType(t, &sema.InvalidTopLevelDeclarationError{}, errs[0])
})
Expand Down Expand Up @@ -5051,38 +5052,3 @@ func singleIdentifierLocationResolver(t *testing.T) func(identifiers []Identifie
}
}
}

// Copied to prevent import cycle while importing from tests/checker package
// while using ExtendedParsingCheckingError
// This now required `runtime` to get access `ExtendedParsingCheckingError`
// which in turns requires `runtime` so any import of original function from
// any other module will introduce cycle
// If we decide to keep extended debug functionality beyond original
// debug possible race condition, this would need to be refactored
func ExpectCheckerErrors(t *testing.T, err error, count int) []error {
if count <= 0 && err == nil {
return nil
}

require.Error(t, err)

// Temporary to help catch checking error
ee, is := err.(*ExtendedParsingCheckingError)
if is {
err = ee.Unwrap()
}

assert.IsType(t, &sema.CheckerError{}, err)

errs := err.(*sema.CheckerError).Errors

require.Len(t, errs, count)

// Get the error message, to check that it can be successfully generated

for _, checkerErr := range errs {
_ = checkerErr.Error()
}

return errs
}

0 comments on commit c64e867

Please sign in to comment.