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

Fix Windows tests #1555

Merged
merged 5 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 9 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ on:
- master
- 'feature/**'

# We need to set this explicitly to make sure the CI works on Windows
# Default shell does not terminate on error in GitHub Actions
# https://github.com/actions/runner-images/issues/6668
defaults:
run:
shell: bash

jobs:
test:
strategy:
Expand All @@ -22,7 +29,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20"
- name: Run tests
Expand All @@ -40,7 +47,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20"
- name: generate
Expand Down
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ binary: $(BINARY)

.PHONY: install-tools
install-tools:
cd ${GOPATH}; \
mkdir -p ${GOPATH}; \
cd '${GOPATH}'; \
mkdir -p '${GOPATH}'; \
GO111MODULE=on go install github.com/axw/gocov/gocov@latest; \
GO111MODULE=on go install github.com/matm/gocov-html/cmd/gocov-html@latest; \
GO111MODULE=on go install github.com/sanderhahn/gozip/cmd/gozip@latest; \
Expand Down Expand Up @@ -86,10 +86,6 @@ publish:
clean:
rm ./cmd/flow/flow*

.PHONY: install-linter
install-linter:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GOPATH}/bin v1.47.2

.PHONY: lint
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use this at all anymore, it's part of install-tools

lint: generate
golangci-lint run -v ./...
Expand Down
18 changes: 11 additions & 7 deletions internal/super/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package super

import (
"fmt"
"path/filepath"
"testing"

"github.com/onflow/flow-cli/internal/util"
Expand Down Expand Up @@ -64,13 +66,14 @@ access(all) fun testContract() {
Test.expect(err, Test.beNil())
}`

assert.Equal(t, expectedContent, string(fileContent))
assert.Equal(t, expectedTestContent, string(testContent))
assert.Equal(t, expectedContent, util.NormalizeLineEndings(string(fileContent)))
assert.Equal(t, expectedTestContent, util.NormalizeLineEndings(string(testContent)))

// Test file already exists scenario
_, err = generateNew([]string{"TestContract"}, "contract", logger, state)
assert.Error(t, err)
assert.Equal(t, "file already exists: cadence/contracts/TestContract.cdc", err.Error())
expectedError := fmt.Sprintf("file already exists: %s", filepath.FromSlash("cadence/contracts/TestContract.cdc"))
assert.Equal(t, expectedError, err.Error())
}

func TestGenerateNewContractSkipTests(t *testing.T) {
Expand Down Expand Up @@ -129,7 +132,8 @@ func TestGenerateNewContractFileAlreadyExists(t *testing.T) {
// Test file already exists scenario
_, err = generateNew([]string{"TestContract"}, "contract", logger, state)
assert.Error(t, err)
assert.Equal(t, "file already exists: cadence/contracts/TestContract.cdc", err.Error())
expectedError := fmt.Sprintf("file already exists: %s", filepath.FromSlash("cadence/contracts/TestContract.cdc"))
assert.Equal(t, expectedError, err.Error())
}

func TestGenerateNewContractWithFileExtension(t *testing.T) {
Expand Down Expand Up @@ -160,7 +164,7 @@ func TestGenerateNewScript(t *testing.T) {
fun main() {
// Script details here
}`
assert.Equal(t, expectedContent, string(content))
assert.Equal(t, expectedContent, util.NormalizeLineEndings(string(content)))
}

func TestGenerateNewTransaction(t *testing.T) {
Expand All @@ -179,7 +183,7 @@ func TestGenerateNewTransaction(t *testing.T) {

execute {}
}`
assert.Equal(t, expectedContent, string(content))
assert.Equal(t, expectedContent, util.NormalizeLineEndings(string(content)))
}

func TestGenerateNewWithDirFlag(t *testing.T) {
Expand All @@ -200,5 +204,5 @@ func TestGenerateNewWithDirFlag(t *testing.T) {
contract TestContract {
init() {}
}`
assert.Equal(t, expectedContent, string(content))
assert.Equal(t, expectedContent, util.NormalizeLineEndings(string(content)))
}
12 changes: 6 additions & 6 deletions internal/transactions/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,10 @@ Fee Events (hidden, use --include fee-events)`, output.OkEmoji()), "\n")
t.Run("Result without fee events", func(t *testing.T) {
result := transactionResult{tx: tx, result: txResultFeeEvents}

assert.Equal(t, strings.TrimPrefix(`
assert.Equal(t, strings.TrimPrefix(fmt.Sprintf(`
Block ID 7aa74143741c1c3b837d389fcffa7a5e251b67b4ffef6d6887b40cd9c803f537
Block Height 1
Status SEALED
Status %s SEALED
ID e913d1f3e431c7df49c99845bea9ebff9db11bbf25d507b9ad0fad45652d515f
Payer 0000000000000002
Authorizers []
Expand All @@ -477,15 +477,15 @@ Code (hidden, use --include code)

Payload (hidden, use --include payload)

Fee Events (hidden, use --include fee-events)`, "\n"), result.String())
Fee Events (hidden, use --include fee-events)`, output.OkEmoji()), "\n"), result.String())
})
t.Run("Result with fee events", func(t *testing.T) {
result := transactionResult{tx: tx, result: txResultFeeEvents, include: []string{"fee-events"}}

assert.Equal(t, strings.TrimPrefix(`
assert.Equal(t, strings.TrimPrefix(fmt.Sprintf(`
Block ID 7aa74143741c1c3b837d389fcffa7a5e251b67b4ffef6d6887b40cd9c803f537
Block Height 1
Status SEALED
Status %s SEALED
ID e913d1f3e431c7df49c99845bea9ebff9db11bbf25d507b9ad0fad45652d515f
Payer 0000000000000002
Authorizers []
Expand Down Expand Up @@ -528,6 +528,6 @@ Events:

Code (hidden, use --include code)

Payload (hidden, use --include payload)`, "\n"), result.String())
Payload (hidden, use --include payload)`, output.OkEmoji()), "\n"), result.String())
})
}
4 changes: 4 additions & 0 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,7 @@ func removeFromStringArray(s []string, el string) []string {

return s
}

func NormalizeLineEndings(s string) string {
return strings.ReplaceAll(s, "\r\n", "\n")
}
Loading