From 1484270aec14b9d971b94832d0fac9d3db382cf9 Mon Sep 17 00:00:00 2001 From: Yury Smolsky Date: Wed, 18 Jul 2018 13:05:29 +0300 Subject: [PATCH] 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 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- test/safe/main.go | 14 -------------- test/safe/nousesafe.go | 8 -------- test/safe/pkg.go | 16 ---------------- test/safe/usesafe.go | 8 -------- test/unsafereject1.go | 16 ++++++++++++++++ test/unsafereject2.go | 15 +++++++++++++++ 6 files changed, 31 insertions(+), 46 deletions(-) delete mode 100644 test/safe/main.go delete mode 100644 test/safe/nousesafe.go delete mode 100644 test/safe/pkg.go delete mode 100644 test/safe/usesafe.go create mode 100644 test/unsafereject1.go create mode 100644 test/unsafereject2.go diff --git a/test/safe/main.go b/test/safe/main.go deleted file mode 100644 index d173ed9266..0000000000 --- a/test/safe/main.go +++ /dev/null @@ -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)) -} diff --git a/test/safe/nousesafe.go b/test/safe/nousesafe.go deleted file mode 100644 index fcd25af315..0000000000 --- a/test/safe/nousesafe.go +++ /dev/null @@ -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 diff --git a/test/safe/pkg.go b/test/safe/pkg.go deleted file mode 100644 index bebc43a214..0000000000 --- a/test/safe/pkg.go +++ /dev/null @@ -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)) -} \ No newline at end of file diff --git a/test/safe/usesafe.go b/test/safe/usesafe.go deleted file mode 100644 index 5d0829e290..0000000000 --- a/test/safe/usesafe.go +++ /dev/null @@ -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 diff --git a/test/unsafereject1.go b/test/unsafereject1.go new file mode 100644 index 0000000000..12f77f963f --- /dev/null +++ b/test/unsafereject1.go @@ -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()) +} diff --git a/test/unsafereject2.go b/test/unsafereject2.go new file mode 100644 index 0000000000..04ad0578c9 --- /dev/null +++ b/test/unsafereject2.go @@ -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)) +}