From e796025a9f3359a461a9d171d5022e6cec3d1dc1 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Tue, 28 Nov 2023 16:56:09 -0800 Subject: [PATCH 1/9] Allow running individual test by name --- internal/test/test.go | 20 +++++++++---- internal/test/test_test.go | 58 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 5 deletions(-) diff --git a/internal/test/test.go b/internal/test/test.go index a94ded9a0..ca0327e1a 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -65,6 +65,7 @@ type flagsTests struct { CoverCode string `default:"all" flag:"covercode" info:"Use the covercode flag to calculate coverage report only for certain types of code. Available values are \"all\" & \"contracts\""` Random bool `default:"false" flag:"random" info:"Use the random flag to execute test cases randomly"` Seed int64 `default:"0" flag:"seed" info:"Use the seed flag to manipulate random execution of test cases"` + Name string `default:"" flag:"name" info:"Use the name flag to run only tests that match the given name"` } var testFlags = flagsTests{} @@ -191,13 +192,22 @@ func testCode( WithFileResolver(fileResolver(scriptPath, state)). WithContracts(contracts) - results, err := runner.RunTests(string(code)) - if err != nil { - return nil, err + if flags.Name != "" { + result, err := runner.RunTest(string(code), flags.Name) + if err != nil { + return nil, err + } + testResults[scriptPath] = []cdcTests.Result{*result} + } else { + results, err := runner.RunTests(string(code)) + if err != nil { + return nil, err + } + testResults[scriptPath] = results } - testResults[scriptPath] = results - for _, result := range results { + + for _, result := range testResults[scriptPath] { if result.Error != nil { status = 1 break diff --git a/internal/test/test_test.go b/internal/test/test_test.go index 1d2dc1554..9b6811267 100644 --- a/internal/test/test_test.go +++ b/internal/test/test_test.go @@ -585,4 +585,62 @@ Seed: 1521 string(output), ) }) + + t.Run("run specific test case by name", func(t *testing.T) { + t.Parallel() + + // Setup + _, state, _ := util.TestMocks(t) + + // Execute script + script := tests.TestScriptSimple + testFiles := map[string][]byte{ + script.Filename: script.Source, + } + flags := flagsTests{ + Name: "testSimple", + } + + result, err := testCode(testFiles, state, flags) + + assert.NoError(t, err) + assert.Len(t, result.Results, 1) + assert.NoError(t, result.Results[script.Filename][0].Error) + + expected := "Test results: \"./testScriptSimple.cdc\"\n- PASS: testSimple\n" + assert.Equal( + t, + expected, + result.Oneliner(), + ) + }) + + t.Run("run specific test case by name will fail if not found", func(t *testing.T) { + t.Parallel() + + // Setup + _, state, _ := util.TestMocks(t) + + // Execute script + script := tests.TestScriptSimple + testFiles := map[string][]byte{ + script.Filename: script.Source, + } + flags := flagsTests{ + Name: "doesNotExist", + } + + result, err := testCode(testFiles, state, flags) + + assert.NoError(t, err) + assert.Len(t, result.Results, 1) + assert.Error(t, result.Results[script.Filename][0].Error, "cannot find function in this scope: `doesNotExist`") + + expected := "Test results: \"./testScriptSimple.cdc\"\n- FAIL: doesNotExist\n\t\tcannot find function in this scope: `doesNotExist`\n" + assert.Equal( + t, + expected, + result.Oneliner(), + ) + }) } From 04f88ee0b9ed227742c43fff060f89129728144d Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Mon, 4 Dec 2023 08:26:39 -0800 Subject: [PATCH 2/9] Check if test exists before running --- go.mod | 2 +- go.sum | 8 ++++++++ internal/test/test.go | 19 ++++++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 2923e503b..428615db8 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/manifoldco/promptui v0.9.0 github.com/onflow/cadence v0.42.5 github.com/onflow/cadence-tools/languageserver v0.33.3 - github.com/onflow/cadence-tools/test v0.14.3 + github.com/onflow/cadence-tools/test v0.14.4 github.com/onflow/fcl-dev-wallet v0.7.4 github.com/onflow/flixkit-go v0.3.1 github.com/onflow/flow-cli/flowkit v1.6.1-0.20231110211255-b41f57a8b8c7 diff --git a/go.sum b/go.sum index db0e6111b..c21a61181 100644 --- a/go.sum +++ b/go.sum @@ -210,6 +210,7 @@ github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06 h1:T+Np/xtzIjYM github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06/go.mod h1:bynZ3gvVyhlvjLI7PT6dmZ7g76xzJ7HpxfjgkzCGz6s= github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ= github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= +github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2/go.mod h1:8BT+cPK6xvFOcRlk0R8eg+OTkcqI6baNH4xAkpiYVvQ= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= @@ -550,6 +551,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFb github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks= github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk= github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w= +github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= +github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE= github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -662,6 +665,7 @@ github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= @@ -823,6 +827,7 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= @@ -886,6 +891,8 @@ github.com/onflow/cadence-tools/lint v0.14.1 h1:Qkw8+q+ALfB62W7KWHMFh+90gTfJ+NoF github.com/onflow/cadence-tools/lint v0.14.1/go.mod h1:w1xfiiPpZ35v/F+2+MF/Rily7LcIgE0dm/FMW1vQkpc= github.com/onflow/cadence-tools/test v0.14.3 h1:tpLn7hBXij7QSSSUH3Pr7Fkl0jMoOSmmgj2ynK71Dyw= github.com/onflow/cadence-tools/test v0.14.3/go.mod h1:1FaKl2BPM05BWWwo5ctwE7dA/CE5KA/kxUrtcCkvCEc= +github.com/onflow/cadence-tools/test v0.14.4 h1:m4SwQFbzHasCDiLdI0zNIZVRMLYQUfiiL6BDZSp06Jo= +github.com/onflow/cadence-tools/test v0.14.4/go.mod h1:1FaKl2BPM05BWWwo5ctwE7dA/CE5KA/kxUrtcCkvCEc= github.com/onflow/fcl-dev-wallet v0.7.4 h1:vI6t3U0AO88R/Iitn5KsnniSpbN9Lqsqwvi9EJT4C0k= github.com/onflow/fcl-dev-wallet v0.7.4/go.mod h1:kc42jkiuoPJmxMRFjfbRO9XvnR/3XLheaOerxVMDTiw= github.com/onflow/flixkit-go v0.3.1 h1:5izElx+3H7vCqlzK0pzEZ+lW3xjfLoB4w5cD2/3qe2M= @@ -1179,6 +1186,7 @@ github.com/vmihailenco/msgpack/v4 v4.3.11 h1:Q47CePddpNGNhk4GCnAx9DDtASi2rasatE0 github.com/vmihailenco/msgpack/v4 v4.3.11/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= github.com/vmihailenco/tagparser v0.1.1 h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37wVyIuWY= github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= +github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208/go.mod h1:IotVbo4F+mw0EzQ08zFqg7pK3FebNXpaMsRy2RT+Ees= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= diff --git a/internal/test/test.go b/internal/test/test.go index ca0327e1a..830b5c5d8 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -193,11 +193,25 @@ func testCode( WithContracts(contracts) if flags.Name != "" { - result, err := runner.RunTest(string(code), flags.Name) + testFunctions, err := runner.GetTests(string(code)) if err != nil { return nil, err } - testResults[scriptPath] = []cdcTests.Result{*result} + includesTest := false + for _, testFunction := range testFunctions { + if testFunction == flags.Name { + includesTest = true + break + } + } + + if includesTest { + result, err := runner.RunTest(string(code), flags.Name) + if err != nil { + return nil, err + } + testResults[scriptPath] = []cdcTests.Result{*result} + } } else { results, err := runner.RunTests(string(code)) if err != nil { @@ -206,7 +220,6 @@ func testCode( testResults[scriptPath] = results } - for _, result := range testResults[scriptPath] { if result.Error != nil { status = 1 From 6b1246873ae2dcf58b21fec1ae3e5d7aa52f4576 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Mon, 4 Dec 2023 08:46:44 -0800 Subject: [PATCH 3/9] go mod tidy --- go.sum | 8 -------- 1 file changed, 8 deletions(-) diff --git a/go.sum b/go.sum index c21a61181..41927a46f 100644 --- a/go.sum +++ b/go.sum @@ -210,7 +210,6 @@ github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06 h1:T+Np/xtzIjYM github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06/go.mod h1:bynZ3gvVyhlvjLI7PT6dmZ7g76xzJ7HpxfjgkzCGz6s= github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ= github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= -github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2/go.mod h1:8BT+cPK6xvFOcRlk0R8eg+OTkcqI6baNH4xAkpiYVvQ= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= @@ -551,8 +550,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFb github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks= github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk= github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w= -github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= -github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE= github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -665,7 +662,6 @@ github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= @@ -827,7 +823,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= @@ -889,8 +884,6 @@ github.com/onflow/cadence-tools/languageserver v0.33.3 h1:o6f2kPxsgSruH+HT8CakcZ github.com/onflow/cadence-tools/languageserver v0.33.3/go.mod h1:rUy3zxWWZl+KYAyzhAcnrYNI8ZDKI242RFK8Q9w+90M= github.com/onflow/cadence-tools/lint v0.14.1 h1:Qkw8+q+ALfB62W7KWHMFh+90gTfJ+NoFulYETMCTkcI= github.com/onflow/cadence-tools/lint v0.14.1/go.mod h1:w1xfiiPpZ35v/F+2+MF/Rily7LcIgE0dm/FMW1vQkpc= -github.com/onflow/cadence-tools/test v0.14.3 h1:tpLn7hBXij7QSSSUH3Pr7Fkl0jMoOSmmgj2ynK71Dyw= -github.com/onflow/cadence-tools/test v0.14.3/go.mod h1:1FaKl2BPM05BWWwo5ctwE7dA/CE5KA/kxUrtcCkvCEc= github.com/onflow/cadence-tools/test v0.14.4 h1:m4SwQFbzHasCDiLdI0zNIZVRMLYQUfiiL6BDZSp06Jo= github.com/onflow/cadence-tools/test v0.14.4/go.mod h1:1FaKl2BPM05BWWwo5ctwE7dA/CE5KA/kxUrtcCkvCEc= github.com/onflow/fcl-dev-wallet v0.7.4 h1:vI6t3U0AO88R/Iitn5KsnniSpbN9Lqsqwvi9EJT4C0k= @@ -1186,7 +1179,6 @@ github.com/vmihailenco/msgpack/v4 v4.3.11 h1:Q47CePddpNGNhk4GCnAx9DDtASi2rasatE0 github.com/vmihailenco/msgpack/v4 v4.3.11/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= github.com/vmihailenco/tagparser v0.1.1 h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37wVyIuWY= github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= -github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208/go.mod h1:IotVbo4F+mw0EzQ08zFqg7pK3FebNXpaMsRy2RT+Ees= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= From b8307b40690e5f1a593d744c8457fd9740435e6d Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Mon, 4 Dec 2023 08:53:11 -0800 Subject: [PATCH 4/9] fix tests --- internal/test/test_test.go | 39 ++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/internal/test/test_test.go b/internal/test/test_test.go index 9b6811267..6a59070c4 100644 --- a/internal/test/test_test.go +++ b/internal/test/test_test.go @@ -615,7 +615,34 @@ Seed: 1521 ) }) - t.Run("run specific test case by name will fail if not found", func(t *testing.T) { + t.Run("run specific test case by name multiple files", func(t *testing.T) { + t.Parallel() + + // Setup + _, state, _ := util.TestMocks(t) + + scriptPassing := tests.TestScriptSimple + scriptFailing := tests.TestScriptSimpleFailing + + // Execute script + testFiles := map[string][]byte{ + scriptPassing.Filename: scriptPassing.Source, + scriptFailing.Filename: scriptFailing.Source, + } + flags := flagsTests{ + Name: "testSimple", + } + + result, err := testCode(testFiles, state, flags) + + assert.NoError(t, err) + assert.Len(t, result.Results, 2) + assert.NoError(t, result.Results[scriptPassing.Filename][0].Error) + assert.Error(t, result.Results[scriptFailing.Filename][0].Error) + assert.ErrorAs(t, result.Results[scriptFailing.Filename][0].Error, &stdlib.AssertionError{}) + }) + + t.Run("run specific test case by name will do nothing if not found", func(t *testing.T) { t.Parallel() // Setup @@ -633,14 +660,6 @@ Seed: 1521 result, err := testCode(testFiles, state, flags) assert.NoError(t, err) - assert.Len(t, result.Results, 1) - assert.Error(t, result.Results[script.Filename][0].Error, "cannot find function in this scope: `doesNotExist`") - - expected := "Test results: \"./testScriptSimple.cdc\"\n- FAIL: doesNotExist\n\t\tcannot find function in this scope: `doesNotExist`\n" - assert.Equal( - t, - expected, - result.Oneliner(), - ) + assert.Len(t, result.Results, 0) }) } From 4f2390e18027a45407d29f5ba80ecb085a4fdc30 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Tue, 5 Dec 2023 09:07:53 -0800 Subject: [PATCH 5/9] add one liner test --- internal/test/test_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/test/test_test.go b/internal/test/test_test.go index 6a59070c4..3c957859d 100644 --- a/internal/test/test_test.go +++ b/internal/test/test_test.go @@ -640,6 +640,11 @@ Seed: 1521 assert.NoError(t, result.Results[scriptPassing.Filename][0].Error) assert.Error(t, result.Results[scriptFailing.Filename][0].Error) assert.ErrorAs(t, result.Results[scriptFailing.Filename][0].Error, &stdlib.AssertionError{}) + assert.Equal( + t, + "Test results: \"./testScriptSimple.cdc\"\n- PASS: testSimple\nTest results: \"./testScriptSimpleFailing.cdc\"\n- FAIL: testSimple\n\t\tExecution failed:\n\t\t\terror: assertion failed\n\t\t\t --> 7465737400000000000000000000000000000000000000000000000000000000:5:12\n\t\t\t\n", + result.Oneliner(), + ) }) t.Run("run specific test case by name will do nothing if not found", func(t *testing.T) { From e0bed7d9964c262d32b184b7834068dc39a29dba Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Tue, 5 Dec 2023 09:07:59 -0800 Subject: [PATCH 6/9] refactor loop logic --- internal/test/test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/internal/test/test.go b/internal/test/test.go index 830b5c5d8..c4eaa61be 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -197,15 +197,12 @@ func testCode( if err != nil { return nil, err } - includesTest := false + for _, testFunction := range testFunctions { - if testFunction == flags.Name { - includesTest = true - break + if testFunction != flags.Name { + continue } - } - if includesTest { result, err := runner.RunTest(string(code), flags.Name) if err != nil { return nil, err From c2ed09edaa7fe572e090429843edf89ec29240c8 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Tue, 5 Dec 2023 14:54:04 -0800 Subject: [PATCH 7/9] Add no tests found message --- internal/test/test.go | 5 +++++ internal/test/test_test.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/internal/test/test.go b/internal/test/test.go index c4eaa61be..a24dc7b98 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -357,6 +357,11 @@ func (r *result) String() string { func (r *result) Oneliner() string { var builder strings.Builder + if len(r.Results) == 0 { + builder.WriteString("No tests found") + return builder.String() + } + for scriptPath, testResult := range r.Results { builder.WriteString(cdcTests.PrettyPrintResults(testResult, scriptPath)) } diff --git a/internal/test/test_test.go b/internal/test/test_test.go index 3c957859d..29d70f55c 100644 --- a/internal/test/test_test.go +++ b/internal/test/test_test.go @@ -666,5 +666,10 @@ Seed: 1521 assert.NoError(t, err) assert.Len(t, result.Results, 0) + assert.Equal( + t, + "No tests found", + result.Oneliner(), + ) }) } From 25d8c1ef97f6c09c92a442c1a3f1d8082d4ad5d9 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Tue, 5 Dec 2023 15:05:55 -0800 Subject: [PATCH 8/9] fix test --- internal/test/test_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/test/test_test.go b/internal/test/test_test.go index 29d70f55c..2684195dc 100644 --- a/internal/test/test_test.go +++ b/internal/test/test_test.go @@ -642,7 +642,7 @@ Seed: 1521 assert.ErrorAs(t, result.Results[scriptFailing.Filename][0].Error, &stdlib.AssertionError{}) assert.Equal( t, - "Test results: \"./testScriptSimple.cdc\"\n- PASS: testSimple\nTest results: \"./testScriptSimpleFailing.cdc\"\n- FAIL: testSimple\n\t\tExecution failed:\n\t\t\terror: assertion failed\n\t\t\t --> 7465737400000000000000000000000000000000000000000000000000000000:5:12\n\t\t\t\n", + "Test results: \"./testScriptSimpleFailing.cdc\"\n- FAIL: testSimple\n\t\tExecution failed:\n\t\t\terror: assertion failed\n\t\t\t --> 7465737400000000000000000000000000000000000000000000000000000000:5:12\n\t\t\t\nTest results: \"./testScriptSimple.cdc\"\n- PASS: testSimple\n", result.Oneliner(), ) }) From 93cc89e8572bd63a0115ca8ab5c03b79ab9ebf45 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Wed, 6 Dec 2023 12:18:17 -0800 Subject: [PATCH 9/9] fix test --- internal/test/test_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/test/test_test.go b/internal/test/test_test.go index 2684195dc..29d70f55c 100644 --- a/internal/test/test_test.go +++ b/internal/test/test_test.go @@ -642,7 +642,7 @@ Seed: 1521 assert.ErrorAs(t, result.Results[scriptFailing.Filename][0].Error, &stdlib.AssertionError{}) assert.Equal( t, - "Test results: \"./testScriptSimpleFailing.cdc\"\n- FAIL: testSimple\n\t\tExecution failed:\n\t\t\terror: assertion failed\n\t\t\t --> 7465737400000000000000000000000000000000000000000000000000000000:5:12\n\t\t\t\nTest results: \"./testScriptSimple.cdc\"\n- PASS: testSimple\n", + "Test results: \"./testScriptSimple.cdc\"\n- PASS: testSimple\nTest results: \"./testScriptSimpleFailing.cdc\"\n- FAIL: testSimple\n\t\tExecution failed:\n\t\t\terror: assertion failed\n\t\t\t --> 7465737400000000000000000000000000000000000000000000000000000000:5:12\n\t\t\t\n", result.Oneliner(), ) })