Skip to content

Commit

Permalink
SONARGO-35 Support Go 1.23 (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
petertrr authored Dec 10, 2024
1 parent 89c0b47 commit 8494424
Show file tree
Hide file tree
Showing 8 changed files with 656 additions and 391 deletions.
2 changes: 1 addition & 1 deletion sonar-go-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ shadowJar {
exclude 'tmp/**'
}
doLast {
enforceJarSizeAndCheckContent(shadowJar.archiveFile.get().asFile, 8_000_000L, 8_500_000L)
enforceJarSizeAndCheckContent(shadowJar.archiveFile.get().asFile, 9_000_000L, 9_500_000L)
}
}

Expand Down
2 changes: 1 addition & 1 deletion sonar-go-to-slang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ To perform the tests, run:

go test

To update test results, use the method `fix_all_go_files_test_automatically` in `goparser_test.go`
To update expected test data, use the method `fix_all_go_files_test_automatically` in `goparser_test.go`
10 changes: 9 additions & 1 deletion sonar-go-to-slang/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module github.com/SonarSource/slang/sonar-go-to-slang

go 1.21
go 1.23.4

require github.com/stretchr/testify v1.10.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
10 changes: 10 additions & 0 deletions sonar-go-to-slang/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8 changes: 2 additions & 6 deletions sonar-go-to-slang/goparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ package main

import (
"encoding/json"
"fmt"
"github.com/stretchr/testify/assert"
"go/ast"
"go/token"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
)
Expand Down Expand Up @@ -88,10 +87,7 @@ func Test_all_go_files(t *testing.T) {
panic(err2)
}

if !reflect.DeepEqual(jsonExpected, jsonActual) {
fmt.Printf("Failed to match expected results for file: %#v\n", file)
t.Fatalf("got: %#v\nexpected: %#v", jsonActual, jsonExpected)
}
assert.Equal(t, string(expectedData), actual, "Failed to match expected results for file: %#v\n", file)
}
}

Expand Down
2 changes: 1 addition & 1 deletion sonar-go-to-slang/make.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env bash
set -euox pipefail

readonly GO_VERSION="1.21.1"
readonly GO_VERSION="1.23.4"
readonly DEFAULT_GO_BINARY_DIRECTORY="${GOPATH:=${HOME}/go}/bin"
readonly DEFAULT_GO_BINARY="${DEFAULT_GO_BINARY_DIRECTORY}/go"

Expand Down
21 changes: 21 additions & 0 deletions sonar-go-to-slang/resources/ast/loops.go.source
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package ast

import (
"fmt"
"slices"
)

func foo() {
for i := 0; i < 10; i++ {
}
Expand Down Expand Up @@ -43,4 +48,20 @@ OUTER:
for i, j, s := 0, 5, "a"; i < 3 && j < 100 && s != "aaaaa"; i, j, s = i+1, j+1, s+"a" {
fmt.Println("Value of i, j, s:", i, j, s)
}

// range over integer; requires Go 1.22+
for i := range 10 {
fmt.Println(10 - i)
}

// range over an iterator, requires Go 1.23+
l := []int{1, 2, 3}
for v := range slices.Values(l) {
fmt.Println(v)
}

m := map[int]string{}
for k, v := range maps.All(m) {
fmt.Println("Key:", k, "Value:", v)
}
}
992 changes: 611 additions & 381 deletions sonar-go-to-slang/resources/ast/loops.json

Large diffs are not rendered by default.

0 comments on commit 8494424

Please sign in to comment.