]> Cypherpunks repositories - gostls13.git/commitdiff
test: restore tests for the reject unsafe code option
authorYury Smolsky <yury@smolsky.by>
Wed, 18 Jul 2018 10:05:29 +0000 (13:05 +0300)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 22 Aug 2018 17:54:09 +0000 (17:54 +0000)
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>

test/safe/main.go [deleted file]
test/safe/nousesafe.go [deleted file]
test/safe/pkg.go [deleted file]
test/safe/usesafe.go [deleted file]
test/unsafereject1.go [new file with mode: 0644]
test/unsafereject2.go [new file with mode: 0644]

diff --git a/test/safe/main.go b/test/safe/main.go
deleted file mode 100644 (file)
index d173ed9..0000000
+++ /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 (file)
index fcd25af..0000000
+++ /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 (file)
index bebc43a..0000000
+++ /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 (file)
index 5d0829e..0000000
+++ /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 (file)
index 0000000..12f77f9
--- /dev/null
@@ -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 (file)
index 0000000..04ad057
--- /dev/null
@@ -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))
+}