mirror of
https://github.com/golang/go.git
synced 2025-05-28 02:41:30 +00:00
test: restore tests for the reject unsafe code option
Tests in test/safe were neglected after moving to the run.go framework. This change restores them. These tests are skipped for go/types via -+ option. Fixes #25668 Change-Id: I8fe26574a76fa7afa8664c467d7c2e6334f1bba9 Reviewed-on: https://go-review.googlesource.com/124660 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
43704759b4
commit
1484270aec
@ -1,14 +0,0 @@
|
||||
// true
|
||||
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
// can't use local path with -u, use -I. instead
|
||||
import "pkg" // ERROR "import unsafe package"
|
||||
|
||||
func main() {
|
||||
print(pkg.Float32bits(1.0))
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
// $G $D/pkg.go && pack grc pkg.a pkg.$A 2> /dev/null && rm pkg.$A && errchk $G -I . -u $D/main.go
|
||||
// rm -f pkg.a
|
||||
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ignored
|
@ -1,16 +0,0 @@
|
||||
// true
|
||||
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// a package that uses unsafe on the inside but not in it's api
|
||||
|
||||
package pkg
|
||||
|
||||
import "unsafe"
|
||||
|
||||
// this should be inlinable
|
||||
func Float32bits(f float32) uint32 {
|
||||
return *(*uint32)(unsafe.Pointer(&f))
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
// $G $D/pkg.go && pack grcS pkg.a pkg.$A 2> /dev/null && rm pkg.$A && $G -I . -u $D/main.go
|
||||
// rm -f pkg.a
|
||||
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ignored
|
16
test/unsafereject1.go
Normal file
16
test/unsafereject1.go
Normal file
@ -0,0 +1,16 @@
|
||||
// errorcheck -u -+
|
||||
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Check that we cannot import a package that uses "unsafe" internally
|
||||
// when -u is supplied.
|
||||
|
||||
package main
|
||||
|
||||
import "syscall" // ERROR "import unsafe package"
|
||||
|
||||
func main() {
|
||||
print(syscall.Environ())
|
||||
}
|
15
test/unsafereject2.go
Normal file
15
test/unsafereject2.go
Normal file
@ -0,0 +1,15 @@
|
||||
// errorcheck -u -+
|
||||
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Check that we cannot import the "unsafe" package when -u is supplied.
|
||||
|
||||
package a
|
||||
|
||||
import "unsafe" // ERROR "import package unsafe"
|
||||
|
||||
func Float32bits(f float32) uint32 {
|
||||
return *(*uint32)(unsafe.Pointer(&f))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user