Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxincs committed Oct 10, 2024
1 parent 6f9db43 commit 2847cb7
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 16 deletions.
49 changes: 49 additions & 0 deletions nilaway_go123_plus_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2023 Uber Technologies, 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.

//go:build go1.23

package nilaway

import (
"testing"

"golang.org/x/tools/go/analysis/analysistest"
)

func TestNilAway_Go123(t *testing.T) {
t.Parallel()

testdata := analysistest.TestData()

// For descriptions of the purpose of each of the following tests, consult their source files
// located in testdata/src/<package>.

tests := []struct {
name string
patterns []string
}{
{name: "LoopRangeGo123", patterns: []string{"go.uber.org/looprangego123"}},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
t.Logf("Running test for packages %s", tt.patterns)

analysistest.Run(t, testdata, Analyzer, tt.patterns...)
})
}
}
16 changes: 0 additions & 16 deletions testdata/src/go.uber.org/looprange/looprange.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
// <nilaway no inference>
package looprange

import (
"maps"
"slices"
)

func dummyConsume(interface{}) {}
func dummyBool() bool { return true }

Expand Down Expand Up @@ -212,14 +207,3 @@ func testAlias(s MyAlias) {
print(myStr)
}
}

func testIter() {
i := 42
for element := range slices.Values([]*int{&i, &i, nil}) {
print(*element) // FN: we do not really handle iterators for now, the elements from iterators are assumed to be nonnil.
}
for k, v := range maps.All(map[string]*int{"abc": &i, "def": nil}) {
print(k)
print(*v) // FN: we do not really handle iterators for now, the elements from iterators are assumed to be nonnil.
}
}
33 changes: 33 additions & 0 deletions testdata/src/go.uber.org/looprangego123/looprangego123.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// 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.

// This package aims to test nilability behavior for `range` in loops.

// <nilaway no inference>
package looprange

import (
"maps"
"slices"
)

func testIter() {
i := 42
for element := range slices.Values([]*int{&i, &i, nil}) {
print(*element) // FN: we do not really handle iterators for now, the elements from iterators are assumed to be nonnil.
}
for k, v := range maps.All(map[string]*int{"abc": &i, "def": nil}) {
print(k)
print(*v) // FN: we do not really handle iterators for now, the elements from iterators are assumed to be nonnil.
}
}

0 comments on commit 2847cb7

Please sign in to comment.