Skip to content

Commit

Permalink
Add lost unsafeptr tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonboom committed Oct 6, 2024
1 parent 289392e commit 7fa49a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestNilNil_Flags_CheckedTypes(t *testing.T) {
t.Parallel()

anlzr := analyzer.New()
if err := anlzr.Flags.Set("checked-types", "ptr"); err != nil {
if err := anlzr.Flags.Set("checked-types", "ptr,uintptr"); err != nil {
t.Fatal(err)
}
analysistest.Run(t, analysistest.TestData(), anlzr, "pointers-only")
Expand Down
9 changes: 8 additions & 1 deletion pkg/analyzer/testdata/src/opposite-chan-map-only/positive.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package examples

import "io"
import (
"io"
"unsafe"
)

type User struct{}

Expand All @@ -16,6 +19,10 @@ func uintPtr0o() (uintptr, error) {
return 0o000, io.EOF
}

func unsafePtr() (unsafe.Pointer, error) {
return nil, nil
}

func chBi() (chan int, error) {
return make(chan int), io.EOF // want "return both a non-nil error and a valid value: use separate returns instead"
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/analyzer/testdata/src/pointers-only/positive.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package examples

import "unsafe"

type User struct{}

func primitivePtr() (*int, error) {
Expand All @@ -10,8 +12,12 @@ func structPtr() (*User, error) {
return nil, nil // want "return both a `nil` error and an invalid value: use a sentinel error instead"
}

func unsafePtr() (unsafe.Pointer, error) {
return nil, nil
}

func uintPtr0o() (uintptr, error) {
return 0o000, nil
return 0o000, nil // want "return both a `nil` error and an invalid value: use a sentinel error instead"
}

func chBi() (chan int, error) {
Expand Down

0 comments on commit 7fa49a5

Please sign in to comment.