Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tests #3651

Merged
merged 8 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ci:
# test all packages
go test -coverprofile=coverage.txt -covermode=atomic -parallel 8 -race -coverpkg $(COVERPKGS) ./...
# run interpreter smoke tests. results from run above are reused, so no tests runs are duplicated
go test -count=5 ./tests/interpreter/... -runSmokeTests=true -validateAtree=false
go test -count=5 ./interpreter/... -runSmokeTests=true -validateAtree=false
# remove coverage of empty functions from report
sed -i -e 's/^.* 0 0$$//' coverage.txt

Expand Down
6 changes: 3 additions & 3 deletions cmd/info/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/onflow/cadence/parser"
"github.com/onflow/cadence/sema"
"github.com/onflow/cadence/stdlib"
"github.com/onflow/cadence/tests/checker"
"github.com/onflow/cadence/tests/sema_utils"
)

type command struct {
Expand Down Expand Up @@ -80,7 +80,7 @@ var commands = map[string]command{

func dumpBuiltinTypes() {

allBaseSemaTypes := checker.AllBaseSemaTypes()
allBaseSemaTypes := sema_utils.AllBaseSemaTypes()

types := make([]sema.Type, 0, len(allBaseSemaTypes))

Expand Down Expand Up @@ -239,7 +239,7 @@ func dumpBuiltinValues() {
ty sema.Type
}

allBaseSemaValueTypes := checker.AllBaseSemaValueTypes()
allBaseSemaValueTypes := sema_utils.AllBaseSemaValueTypes()
standardLibraryValues := stdlib.DefaultScriptStandardLibraryValues(nil)

valueTypes := make([]valueType, 0, len(allBaseSemaValueTypes)+len(standardLibraryValues))
Expand Down
4 changes: 2 additions & 2 deletions compiler/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (
"github.com/stretchr/testify/require"

"github.com/onflow/cadence/compiler/ir"
"github.com/onflow/cadence/tests/checker"
. "github.com/onflow/cadence/tests/sema_utils"
)

func TestCompilerSimple(t *testing.T) {

checker, err := checker.ParseAndCheck(t, `
checker, err := ParseAndCheck(t, `
fun inc(a: Int): Int {
let mod = 1
return a + mod
Expand Down
2 changes: 1 addition & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ contains command-line tools that are useful when working on the implementation f
Run the checker tests with the `cadence.checkConcurrently` flag, e.g.

```shell
go test -race -v ./tests/checker -cadence.checkConcurrently=10
go test -race -v ./sema/... -cadence.checkConcurrently=10
```

This runs each check of a checker test 10 times, concurrently,
Expand Down
4 changes: 2 additions & 2 deletions encoding/ccf/ccf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import (
"github.com/onflow/cadence/interpreter"
"github.com/onflow/cadence/runtime"
"github.com/onflow/cadence/sema"
"github.com/onflow/cadence/tests/checker"
"github.com/onflow/cadence/tests/runtime_utils"
. "github.com/onflow/cadence/tests/sema_utils"
"github.com/onflow/cadence/tests/utils"
)

Expand Down Expand Up @@ -4949,7 +4949,7 @@ func TestEncodeSortedDictionary(t *testing.T) {
}

func exportFromScript(t *testing.T, code string) cadence.Value {
checker, err := checker.ParseAndCheck(t, code)
checker, err := ParseAndCheck(t, code)
require.NoError(t, err)

var uuid uint64
Expand Down
4 changes: 2 additions & 2 deletions encoding/json/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/onflow/cadence/common"
"github.com/onflow/cadence/interpreter"
"github.com/onflow/cadence/runtime"
"github.com/onflow/cadence/tests/checker"
. "github.com/onflow/cadence/tests/sema_utils"

"github.com/onflow/cadence"
"github.com/onflow/cadence/sema"
Expand Down Expand Up @@ -1123,7 +1123,7 @@ func TestEncodeDictionary(t *testing.T) {
}

func exportFromScript(t *testing.T, code string) cadence.Value {
checker, err := checker.ParseAndCheck(t, code)
checker, err := ParseAndCheck(t, code)
require.NoError(t, err)

var uuid uint64 = 0
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/onflow/cadence/interpreter"
"github.com/onflow/cadence/sema"
"github.com/onflow/cadence/stdlib"
"github.com/onflow/cadence/tests/checker"
. "github.com/onflow/cadence/tests/sema_utils"
. "github.com/onflow/cadence/tests/utils"
)

Expand Down Expand Up @@ -855,7 +855,7 @@ func TestInterpretInitializerWithInterfacePreCondition(t *testing.T) {
)
}

checker, err := checker.ParseAndCheck(t,
checker, err := ParseAndCheck(t,
fmt.Sprintf(
`
access(all)
Expand Down
File renamed without changes.
34 changes: 15 additions & 19 deletions interpreter/deepcopyremove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/onflow/cadence/common"
. "github.com/onflow/cadence/interpreter"
"github.com/onflow/cadence/interpreter"
"github.com/onflow/cadence/tests/utils"
)

Expand All @@ -38,49 +38,49 @@ func TestValueDeepCopyAndDeepRemove(t *testing.T) {

storage := newUnmeteredInMemoryStorage()

inter, err := NewInterpreter(
inter, err := interpreter.NewInterpreter(
nil,
utils.TestLocation,
&Config{
&interpreter.Config{
Storage: storage,
},
)
require.NoError(t, err)

dictionaryStaticType := &DictionaryStaticType{
KeyType: PrimitiveStaticTypeString,
ValueType: PrimitiveStaticTypeInt256,
dictionaryStaticType := &interpreter.DictionaryStaticType{
KeyType: interpreter.PrimitiveStaticTypeString,
ValueType: interpreter.PrimitiveStaticTypeInt256,
}

dictValueKey := NewUnmeteredStringValue(
dictValueKey := interpreter.NewUnmeteredStringValue(
strings.Repeat("x", int(atree.MaxInlineMapKeySize()+1)),
)

dictValueValue := NewUnmeteredInt256ValueFromInt64(1)
dictValue := NewDictionaryValue(
dictValueValue := interpreter.NewUnmeteredInt256ValueFromInt64(1)
dictValue := interpreter.NewDictionaryValue(
inter,
EmptyLocationRange,
interpreter.EmptyLocationRange,
dictionaryStaticType,
dictValueKey, dictValueValue,
)

arrayValue := NewArrayValue(
arrayValue := interpreter.NewArrayValue(
inter,
EmptyLocationRange,
&VariableSizedStaticType{
interpreter.EmptyLocationRange,
&interpreter.VariableSizedStaticType{
Type: dictionaryStaticType,
},
common.ZeroAddress,
dictValue,
)

optionalValue := NewUnmeteredSomeValueNonCopying(arrayValue)
optionalValue := interpreter.NewUnmeteredSomeValueNonCopying(arrayValue)

compositeValue := newTestCompositeValue(inter, address)

compositeValue.SetMember(
inter,
EmptyLocationRange,
interpreter.EmptyLocationRange,
"value",
optionalValue,
)
Expand All @@ -99,7 +99,3 @@ func TestValueDeepCopyAndDeepRemove(t *testing.T) {

require.Equal(t, 1, count)
}

func newUnmeteredInMemoryStorage() InMemoryStorage {
return NewInMemoryStorage(nil)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/onflow/cadence/common"
"github.com/onflow/cadence/interpreter"
"github.com/onflow/cadence/sema"
"github.com/onflow/cadence/tests/checker"
. "github.com/onflow/cadence/tests/sema_utils"
"github.com/onflow/cadence/tests/utils"
)

Expand Down Expand Up @@ -221,7 +221,7 @@ func TestInterpretResultVariable(t *testing.T) {
)
require.NoError(t, err)
require.Len(t, checkerErrors, 1)
checkerError := checker.RequireCheckerErrors(t, checkerErrors[0], 1)
checkerError := RequireCheckerErrors(t, checkerErrors[0], 1)
require.IsType(t, &sema.PurityError{}, checkerError[0])

_, err = inter.Invoke("main")
Expand Down Expand Up @@ -280,7 +280,7 @@ func TestInterpretResultVariable(t *testing.T) {
)
require.NoError(t, err)
require.Len(t, checkerErrors, 1)
checkerError := checker.RequireCheckerErrors(t, checkerErrors[0], 1)
checkerError := RequireCheckerErrors(t, checkerErrors[0], 1)
require.IsType(t, &sema.PurityError{}, checkerError[0])

_, err = inter.Invoke("main")
Expand Down
4 changes: 2 additions & 2 deletions tests/interpreter/if_test.go → interpreter/if_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

. "github.com/onflow/cadence/tests/sema_utils"
. "github.com/onflow/cadence/tests/utils"

"github.com/onflow/cadence/interpreter"
"github.com/onflow/cadence/sema"
"github.com/onflow/cadence/tests/checker"
)

func TestInterpretIfStatement(t *testing.T) {
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestInterpretIfStatement(t *testing.T) {
`,
ParseCheckAndInterpretOptions{
HandleCheckerError: func(err error) {
errs := checker.RequireCheckerErrors(t, err, 2)
errs := RequireCheckerErrors(t, err, 2)

assert.IsType(t, &sema.UnreachableStatementError{}, errs[0])
assert.IsType(t, &sema.UnreachableStatementError{}, errs[1])
Expand Down
24 changes: 12 additions & 12 deletions tests/interpreter/import_test.go → interpreter/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/onflow/cadence/common/orderedmap"
"github.com/onflow/cadence/interpreter"
"github.com/onflow/cadence/sema"
"github.com/onflow/cadence/tests/checker"
. "github.com/onflow/cadence/tests/sema_utils"
. "github.com/onflow/cadence/tests/utils"
)

Expand Down Expand Up @@ -154,7 +154,7 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) {

address := common.MustBytesToAddress([]byte{0x1})

importedCheckerA, err := checker.ParseAndCheckWithOptions(t,
importedCheckerA, err := ParseAndCheckWithOptions(t,
`
// this function *SHOULD* be imported in the importing program
access(all) fun a(): Int {
Expand All @@ -166,7 +166,7 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) {
return 11
}
`,
checker.ParseAndCheckOptions{
ParseAndCheckOptions{
Location: common.AddressLocation{
Address: address,
Name: "a",
Expand All @@ -175,7 +175,7 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) {
)
require.NoError(t, err)

importedCheckerB, err := checker.ParseAndCheckWithOptions(t,
importedCheckerB, err := ParseAndCheckWithOptions(t,
`
// this function *SHOULD* be imported in the importing program
access(all) fun b(): Int {
Expand All @@ -187,7 +187,7 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) {
return 22
}
`,
checker.ParseAndCheckOptions{
ParseAndCheckOptions{
Location: common.AddressLocation{
Address: address,
Name: "b",
Expand All @@ -196,15 +196,15 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) {
)
require.NoError(t, err)

importingChecker, err := checker.ParseAndCheckWithOptions(t,
importingChecker, err := ParseAndCheckWithOptions(t,
`
import a, b from 0x1

access(all) fun test(): Int {
return a() + b()
}
`,
checker.ParseAndCheckOptions{
ParseAndCheckOptions{
Config: &sema.Config{
LocationHandler: func(identifiers []ast.Identifier, location common.Location) (result []sema.ResolvedLocation, err error) {

Expand Down Expand Up @@ -316,19 +316,19 @@ func TestInterpretResourceConstructionThroughIndirectImport(t *testing.T) {

address := common.MustBytesToAddress([]byte{0x1})

importedChecker, err := checker.ParseAndCheckWithOptions(t,
importedChecker, err := ParseAndCheckWithOptions(t,
`
resource R {}
`,
checker.ParseAndCheckOptions{
ParseAndCheckOptions{
Location: common.AddressLocation{
Address: address,
},
},
)
require.NoError(t, err)

importingChecker, err := checker.ParseAndCheckWithOptions(t,
importingChecker, err := ParseAndCheckWithOptions(t,
`
import R from 0x1

Expand All @@ -337,7 +337,7 @@ func TestInterpretResourceConstructionThroughIndirectImport(t *testing.T) {
destroy r
}
`,
checker.ParseAndCheckOptions{
ParseAndCheckOptions{
Config: &sema.Config{
ImportHandler: func(checker *sema.Checker, importedLocation common.Location, _ ast.Range) (sema.Import, error) {
require.IsType(t, common.AddressLocation{}, importedLocation)
Expand Down Expand Up @@ -396,7 +396,7 @@ func TestInterpretResourceConstructionThroughIndirectImport(t *testing.T) {
require.ErrorAs(t, err, &resourceConstructionError)

assert.Equal(t,
checker.RequireGlobalType(t, importedChecker.Elaboration, "R"),
RequireGlobalType(t, importedChecker.Elaboration, "R"),
resourceConstructionError.CompositeType,
)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/onflow/cadence/interpreter"
"github.com/onflow/cadence/tests/checker"
. "github.com/onflow/cadence/tests/sema_utils"
. "github.com/onflow/cadence/tests/utils"
)

Expand Down Expand Up @@ -407,7 +407,7 @@ func TestInterpretMemberAccessType(t *testing.T) {
value, err := inter.Invoke("S")
require.NoError(t, err)

sType := checker.RequireGlobalType(t, inter.Program.Elaboration, "S")
sType := RequireGlobalType(t, inter.Program.Elaboration, "S")

ref := interpreter.NewUnmeteredEphemeralReferenceValue(inter, interpreter.UnauthorizedAccess, value, sType, interpreter.EmptyLocationRange)

Expand Down Expand Up @@ -454,7 +454,7 @@ func TestInterpretMemberAccessType(t *testing.T) {
value, err := inter.Invoke("S2")
require.NoError(t, err)

sType := checker.RequireGlobalType(t, inter.Program.Elaboration, "S")
sType := RequireGlobalType(t, inter.Program.Elaboration, "S")

ref := interpreter.NewUnmeteredEphemeralReferenceValue(inter, interpreter.UnauthorizedAccess, value, sType, interpreter.EmptyLocationRange)

Expand Down Expand Up @@ -496,7 +496,7 @@ func TestInterpretMemberAccessType(t *testing.T) {
value, err := inter.Invoke("S")
require.NoError(t, err)

sType := checker.RequireGlobalType(t, inter.Program.Elaboration, "S")
sType := RequireGlobalType(t, inter.Program.Elaboration, "S")

ref := interpreter.NewUnmeteredEphemeralReferenceValue(inter, interpreter.UnauthorizedAccess, value, sType, interpreter.EmptyLocationRange)

Expand Down Expand Up @@ -541,7 +541,7 @@ func TestInterpretMemberAccessType(t *testing.T) {
value, err := inter.Invoke("S2")
require.NoError(t, err)

sType := checker.RequireGlobalType(t, inter.Program.Elaboration, "S")
sType := RequireGlobalType(t, inter.Program.Elaboration, "S")

ref := interpreter.NewUnmeteredEphemeralReferenceValue(inter, interpreter.UnauthorizedAccess, value, sType, interpreter.EmptyLocationRange)

Expand Down
Loading
Loading