Skip to content
Merged
2 changes: 2 additions & 0 deletions cmd/flow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/onflow/flow-cli/internal/signatures"
"github.com/onflow/flow-cli/internal/snapshot"
"github.com/onflow/flow-cli/internal/status"
"github.com/onflow/flow-cli/internal/test"
"github.com/onflow/flow-cli/internal/tools"
"github.com/onflow/flow-cli/internal/transactions"
"github.com/onflow/flow-cli/internal/version"
Expand All @@ -58,6 +59,7 @@ func main() {
// single commands
status.Command.AddToParent(cmd)
tools.DevWallet.AddToParent(cmd)
test.TestCommand.AddToParent(cmd)

// structured commands
cmd.AddCommand(cadence.Cmd)
Expand Down
15 changes: 15 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/manifoldco/promptui v0.9.0
github.com/onflow/cadence v0.27.0
github.com/onflow/cadence-tools/languageserver v0.0.0-20220926202318-0d961fc5d7e7
github.com/onflow/cadence-tools/test v0.1.0
github.com/onflow/fcl-dev-wallet v0.5.1
github.com/onflow/flow-cli/pkg/flowkit v0.0.0-20220926143050-dfd5770b1cd7
github.com/onflow/flow-emulator v0.37.0
Expand Down Expand Up @@ -72,8 +73,19 @@ require (
github.com/imdario/mergo v0.3.12 // indirect
github.com/improbable-eng/grpc-web v0.12.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/ipfs/bbloom v0.0.4 // indirect
github.com/ipfs/go-block-format v0.0.3 // indirect
github.com/ipfs/go-cid v0.2.0 // indirect
github.com/ipfs/go-datastore v0.5.1 // indirect
github.com/ipfs/go-ipfs-blockstore v1.2.0 // indirect
github.com/ipfs/go-ipfs-ds-help v1.1.0 // indirect
github.com/ipfs/go-ipfs-util v0.0.2 // indirect
github.com/ipfs/go-ipld-format v0.3.0 // indirect
github.com/ipfs/go-log v1.0.5 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/ipfs/go-metrics-interface v0.0.1 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/joho/godotenv v1.4.0 // indirect
github.com/kevinburke/go-bindata v3.23.0+incompatible // indirect
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
Expand Down Expand Up @@ -115,6 +127,7 @@ require (
github.com/onflow/fusd/lib/go/contracts v0.0.0-20211021081023-ae9de8fb2c7e // indirect
github.com/onflow/nft-storefront/lib/go/contracts v0.0.0-20220714155620-011db20fe754 // indirect
github.com/onflow/sdks v0.4.4 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand Down Expand Up @@ -160,6 +173,8 @@ require (
go.opentelemetry.io/otel/trace v1.8.0 // indirect
go.opentelemetry.io/proto/otlp v0.18.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.22.0 // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/exp v0.0.0-20220713135740-79cabaa25d75 // indirect
golang.org/x/net v0.0.0-20220812174116-3211cb980234 // indirect
Expand Down
70 changes: 69 additions & 1 deletion go.sum

Large diffs are not rendered by default.

113 changes: 113 additions & 0 deletions internal/test/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Flow CLI
*
* Copyright 2022 Dapper Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package test

import (
"bytes"
"fmt"

"github.com/spf13/cobra"

"github.com/onflow/flow-cli/internal/command"
"github.com/onflow/flow-cli/pkg/flowkit"
"github.com/onflow/flow-cli/pkg/flowkit/services"
"github.com/onflow/flow-cli/pkg/flowkit/util"

cdcTests "github.com/onflow/cadence-tools/test"
)

type flagsTests struct {
// Nothing for now
}

var testFlags = flagsTests{}

var TestCommand = &command.Command{
Cmd: &cobra.Command{
Use: "test <filename>",
Short: "Run Cadence tests",
Example: `flow test script.cdc`,
Args: cobra.MinimumNArgs(1),
},
Flags: &testFlags,
Run: run,
}

func run(
args []string,
readerWriter flowkit.ReaderWriter,
_ command.GlobalFlags,
services *services.Services,
) (command.Result, error) {

filename := args[0]

code, err := readerWriter.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("error loading script file: %w", err)
}

result, err := services.Tests.Execute(
code,
filename,
readerWriter,
)

if err != nil {
return nil, err
}

return &TestResult{
Results: result,
}, nil
}

type TestResult struct {
cdcTests.Results
}

var _ command.Result = &TestResult{}

func (r *TestResult) JSON() any {
results := make([]map[string]string, 0, len(r.Results))

for _, result := range r.Results {
results = append(results, map[string]string{
"testName": result.TestName,
"error": result.Error.Error(),
})
}

return results
}

func (r *TestResult) String() string {
var b bytes.Buffer
writer := util.CreateTabWriter(&b)

_, _ = fmt.Fprintf(writer, cdcTests.PrettyPrintResults(r.Results))

_ = writer.Flush()

return b.String()
}

func (r *TestResult) Oneliner() string {
return cdcTests.PrettyPrintResults(r.Results)
}
17 changes: 17 additions & 0 deletions pkg/flowkit/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/joho/godotenv v1.4.0
github.com/manifoldco/promptui v0.9.0
github.com/onflow/cadence v0.27.0
github.com/onflow/cadence-tools/test v0.1.0
github.com/onflow/flow-core-contracts/lib/go/templates v0.11.2-0.20220720151516-797b149ceaaa
github.com/onflow/flow-emulator v0.37.0
github.com/onflow/flow-go v0.26.14-test-synchronization.0.20220924005019-be5302fb1342
Expand Down Expand Up @@ -61,12 +62,24 @@ require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/gax-go/v2 v2.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/ipfs/bbloom v0.0.4 // indirect
github.com/ipfs/go-block-format v0.0.3 // indirect
github.com/ipfs/go-cid v0.2.0 // indirect
github.com/ipfs/go-datastore v0.5.1 // indirect
github.com/ipfs/go-ipfs-blockstore v1.2.0 // indirect
github.com/ipfs/go-ipfs-ds-help v1.1.0 // indirect
github.com/ipfs/go-ipfs-util v0.0.2 // indirect
github.com/ipfs/go-ipld-format v0.3.0 // indirect
github.com/ipfs/go-log v1.0.5 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/ipfs/go-metrics-interface v0.0.1 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/kevinburke/go-bindata v3.23.0+incompatible // indirect
github.com/klauspost/compress v1.15.1 // indirect
github.com/klauspost/cpuid/v2 v2.1.0 // indirect
Expand Down Expand Up @@ -95,12 +108,14 @@ require (
github.com/onflow/flow-go/crypto v0.24.4 // indirect
github.com/onflow/flow/protobuf/go/flow v0.3.1 // indirect
github.com/onflow/sdks v0.4.4 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/psiemens/sconfig v0.1.0 // indirect
github.com/rivo/uniseg v0.2.1-0.20211004051800-57c86be7915a // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/sethvargo/go-retry v0.2.3 // indirect
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
Expand All @@ -127,6 +142,8 @@ require (
go.opentelemetry.io/otel/trace v1.8.0 // indirect
go.opentelemetry.io/proto/otlp v0.18.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.22.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/net v0.0.0-20220812174116-3211cb980234 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
Expand Down
Loading