mirror of https://github.com/golang/go.git
[dev.boringcrypto] all: merge master into dev.boringcrypto
This effectively reverts the golang.org/cl/161699 merge. Change-Id: I7c982a97f3ae0015e2e148d4831912d058d682f8
This commit is contained in:
commit
a10558f870
|
|
@ -457,3 +457,4 @@ pkg syscall (freebsd-arm-cgo), type Stat_t struct, Nlink uint16
|
|||
pkg syscall (freebsd-arm-cgo), type Stat_t struct, Rdev uint32
|
||||
pkg syscall (freebsd-arm-cgo), type Statfs_t struct, Mntfromname [88]int8
|
||||
pkg syscall (freebsd-arm-cgo), type Statfs_t struct, Mntonname [88]int8
|
||||
pkg text/scanner, const GoTokens = 1012
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
pkg text/scanner, const AllowNumberbars = 1024
|
||||
pkg text/scanner, const AllowNumberbars ideal-int
|
||||
pkg text/scanner, const GoTokens = 2036
|
||||
|
|
@ -18,10 +18,8 @@ underlying binary with arguments appropriate to package-level processing.
|
|||
|
||||
<p>
|
||||
The programs can also be run as stand-alone binaries, with unmodified arguments,
|
||||
using the go <code>tool</code> subcommand, such as <code>go tool vet</code>.
|
||||
This style of invocation allows, for instance, checking a single source file
|
||||
rather than an entire package: <code>go tool vet myprogram.go</code> as
|
||||
compared to <code>go vet mypackage</code>.
|
||||
using the go <code>tool</code> subcommand, such as <code>go tool cgo</code>.
|
||||
For most commands this is mainly useful for debugging.
|
||||
Some of the commands, such as <code>pprof</code>, are accessible only through
|
||||
the go <code>tool</code> subcommand.
|
||||
</p>
|
||||
|
|
@ -76,7 +74,7 @@ and rewrites them to use newer ones.</td>
|
|||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><a href="/cmd/go/">fmt</a></td>
|
||||
<td><a href="/cmd/gofmt/">fmt</a></td>
|
||||
<td> </td>
|
||||
<td>Fmt formats Go packages, it is also available as an independent <a href="/cmd/gofmt/">
|
||||
gofmt</a> command with more general options.</td>
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ We encourage all Go users to subscribe to
|
|||
<p>A <a href="/doc/devel/release.html">summary</a> of the changes between Go releases. Notes for the major releases:</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="/doc/go1.12">Go 1.12</a> <small>(February 2019)</small></li>
|
||||
<li><a href="/doc/go1.11">Go 1.11</a> <small>(August 2018)</small></li>
|
||||
<li><a href="/doc/go1.10">Go 1.10</a> <small>(February 2018)</small></li>
|
||||
<li><a href="/doc/go1.9">Go 1.9</a> <small>(August 2017)</small></li>
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ Use the <code>"l"</code> or <code>"list"</code> command to inspect source code.
|
|||
</pre>
|
||||
|
||||
<p>
|
||||
List a specific part of the source parametrizing <code>"list"</code> with a
|
||||
List a specific part of the source parameterizing <code>"list"</code> with a
|
||||
function name (it must be qualified with its package name).
|
||||
</p>
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,13 @@ in supported releases as needed by issuing minor revisions
|
|||
(for example, Go 1.6.1, Go 1.6.2, and so on).
|
||||
</p>
|
||||
|
||||
<h2 id="go1.12">go1.12 (released 2019/02/25)</h2>
|
||||
|
||||
<p>
|
||||
Go 1.12 is a major release of Go.
|
||||
Read the <a href="/doc/go1.12">Go 1.12 Release Notes</a> for more information.
|
||||
</p>
|
||||
|
||||
<h2 id="go1.11">go1.11 (released 2018/08/24)</h2>
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -15,14 +15,7 @@ Do not send CLs removing the interior tags from such phrases.
|
|||
ul li { margin: 0.5em 0; }
|
||||
</style>
|
||||
|
||||
<h2 id="introduction">DRAFT RELEASE NOTES - Introduction to Go 1.12</h2>
|
||||
|
||||
<p>
|
||||
<strong>
|
||||
Go 1.12 is not yet released. These are work-in-progress
|
||||
release notes. Go 1.12 is expected to be released in February 2019.
|
||||
</strong>
|
||||
</p>
|
||||
<h2 id="introduction">Introduction to Go 1.12</h2>
|
||||
|
||||
<p>
|
||||
The latest Go release, version 1.12, arrives six months after <a href="go1.11">Go 1.11</a>.
|
||||
|
|
@ -109,7 +102,7 @@ Do not send CLs removing the interior tags from such phrases.
|
|||
is no longer available with <code>go vet</code>. Checking for
|
||||
variable shadowing may now be done using
|
||||
<pre>
|
||||
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
|
||||
go get -u golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
|
||||
go vet -vettool=$(which shadow)
|
||||
</pre>
|
||||
</p>
|
||||
|
|
@ -121,7 +114,7 @@ The Go tour is no longer included in the main binary distribution. To
|
|||
run the tour locally, instead of running <code>go</code> <code>tool</code> <code>tour</code>,
|
||||
manually install it:
|
||||
<pre>
|
||||
go install golang.org/x/tour
|
||||
go get -u golang.org/x/tour
|
||||
tour
|
||||
</pre>
|
||||
</p>
|
||||
|
|
@ -303,7 +296,9 @@ for {
|
|||
<p>
|
||||
In Go 1.12, <code>godoc</code> no longer has a command-line interface and
|
||||
is only a web server. Users should use <code>go</code> <code>doc</code>
|
||||
for command-line help output instead.
|
||||
for command-line help output instead. Go 1.12 is the last release that will
|
||||
include the <code>godoc</code> webserver; in Go 1.13 it will be available
|
||||
via <code>go</code> <code>get</code>.
|
||||
</p>
|
||||
|
||||
<p><!-- CL 141977 -->
|
||||
|
|
@ -493,8 +488,11 @@ for {
|
|||
<dl id="crypto/rc4"><dt><a href="/pkg/crypto/rc4/">crypto/rc4</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 130397 -->
|
||||
This release removes the optimized assembly implementations. RC4 is insecure
|
||||
and should only be used for compatibility with legacy systems.
|
||||
This release removes the assembly implementations, leaving only
|
||||
the pure Go version. The Go compiler generates code that is
|
||||
either slightly better or slightly worse, depending on the exact
|
||||
CPU. RC4 is insecure and should only be used for compatibility
|
||||
with legacy systems.
|
||||
</p>
|
||||
|
||||
</dl><!-- crypto/rc4 -->
|
||||
|
|
@ -689,6 +687,20 @@ for {
|
|||
|
||||
</dl><!-- net/http -->
|
||||
|
||||
<dl id="net/url"><dt><a href="/pkg/net/url/">net/url</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 159157, CL 160178 -->
|
||||
<a href="/pkg/net/url/#Parse"><code>Parse</code></a>,
|
||||
<a href="/pkg/net/url/#ParseRequestURI"><code>ParseRequestURI</code></a>,
|
||||
and
|
||||
<a href="/pkg/net/url/#URL.Parse"><code>URL.Parse</code></a>
|
||||
now return an
|
||||
error for URLs containing ASCII control characters, which includes NULL,
|
||||
tab, and newlines.
|
||||
</p>
|
||||
|
||||
</dl><!-- net/url -->
|
||||
|
||||
<dl id="net/http/httputil"><dt><a href="/pkg/net/http/httputil/">net/http/httputil</a></dt>
|
||||
<dd>
|
||||
<p><!-- CL 146437 -->
|
||||
|
|
|
|||
|
|
@ -525,7 +525,7 @@ client.
|
|||
The <a href="/pkg/net/http/"><code>net/http</code></a> package's
|
||||
<a href="/pkg/net/http/#Request.ParseMultipartForm"><code>Request.ParseMultipartForm</code></a>
|
||||
method will now return an error if the body's <code>Content-Type</code>
|
||||
is not <code>mutipart/form-data</code>.
|
||||
is not <code>multipart/form-data</code>.
|
||||
Prior to Go 1.3 it would silently fail and return <code>nil</code>.
|
||||
Code that relies on the previous behavior should be updated.
|
||||
</li>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<!--{
|
||||
"Title": "The Go Programming Language Specification",
|
||||
"Subtitle": "Version of November 16, 2018",
|
||||
"Subtitle": "Version of February 16, 2019",
|
||||
"Path": "/ref/spec"
|
||||
}-->
|
||||
|
||||
|
|
@ -3439,7 +3439,7 @@ to the type of the other operand.
|
|||
</p>
|
||||
|
||||
<p>
|
||||
The right operand in a shift expression must have unsigned integer type
|
||||
The right operand in a shift expression must have integer type
|
||||
or be an untyped constant <a href="#Representability">representable</a> by a
|
||||
value of type <code>uint</code>.
|
||||
If the left operand of a non-constant shift expression is an untyped constant,
|
||||
|
|
@ -3586,7 +3586,9 @@ be replaced by a bitwise AND operation:
|
|||
|
||||
<p>
|
||||
The shift operators shift the left operand by the shift count specified by the
|
||||
right operand. They implement arithmetic shifts if the left operand is a signed
|
||||
right operand, which must be positive. If the shift count is negative at run time,
|
||||
a <a href="#Run_time_panics">run-time panic</a> occurs.
|
||||
The shift operators implement arithmetic shifts if the left operand is a signed
|
||||
integer and logical shifts if it is an unsigned integer.
|
||||
There is no upper limit on the shift count. Shifts behave
|
||||
as if the left operand is shifted <code>n</code> times by 1 for a shift
|
||||
|
|
@ -5921,7 +5923,7 @@ var a = complex(2, -2) // complex128
|
|||
const b = complex(1.0, -1.4) // untyped complex constant 1 - 1.4i
|
||||
x := float32(math.Cos(math.Pi/2)) // float32
|
||||
var c64 = complex(5, -x) // complex64
|
||||
var s uint = complex(1, 0) // untyped complex constant 1 + 0i can be converted to uint
|
||||
var s int = complex(1, 0) // untyped complex constant 1 + 0i can be converted to int
|
||||
_ = complex(1, 2<<s) // illegal: 2 assumes floating-point type, cannot shift
|
||||
var rl = real(c64) // float32
|
||||
var im = imag(a) // float64
|
||||
|
|
|
|||
|
|
@ -349,15 +349,7 @@ provides <b>essential setup instructions</b> for using the Go tools.
|
|||
<p>
|
||||
The source code for several Go tools (including <a href="/cmd/godoc/">godoc</a>)
|
||||
is kept in <a href="https://golang.org/x/tools">the go.tools repository</a>.
|
||||
To install all of them, run the <code>go</code> <code>get</code> command:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
$ go get golang.org/x/tools/cmd/...
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Or if you just want to install a specific command (<code>godoc</code> in this case):
|
||||
To install one of the tools (<code>godoc</code> in this case):
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
|
|
@ -374,16 +366,6 @@ You must also have a workspace (<code>GOPATH</code>) set up;
|
|||
see <a href="/doc/code.html">How to Write Go Code</a> for the details.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Note</b>: The <code>go</code> command will install the <code>godoc</code>
|
||||
binary to <code>$GOROOT/bin</code> (or <code>$GOBIN</code>) and the
|
||||
<code>cover</code> and <code>vet</code> binaries to
|
||||
<code>$GOROOT/pkg/tool/$GOOS_$GOARCH</code>.
|
||||
You can access the latter commands with
|
||||
"<code>go</code> <code>tool</code> <code>cover</code>" and
|
||||
"<code>go</code> <code>tool</code> <code>vet</code>".
|
||||
</p>
|
||||
|
||||
<h2 id="community">Community resources</h2>
|
||||
|
||||
<p>
|
||||
|
|
@ -666,7 +648,6 @@ something like this:
|
|||
</p>
|
||||
|
||||
<pre>
|
||||
export GOROOT=$HOME/go1.X
|
||||
export GOARCH=amd64
|
||||
export GOOS=linux
|
||||
</pre>
|
||||
|
|
|
|||
|
|
@ -171,11 +171,6 @@ command prompts for the change to take effect.
|
|||
<a href="/dl/">Download the zip file</a> and extract it into the directory of your choice (we suggest <code>c:\Go</code>).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
If you chose a directory other than <code>c:\Go</code>,
|
||||
you must set the <code>GOROOT</code> environment variable to your chosen path.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Add the <code>bin</code> subdirectory of your Go root (for example, <code>c:\Go\bin</code>) to your <code>PATH</code> environment variable.
|
||||
</p>
|
||||
|
|
|
|||
|
|
@ -21,21 +21,8 @@ curl -L -O https://www.iana.org/time-zones/repository/releases/tzdata$DATA.tar.g
|
|||
tar xzf tzcode$CODE.tar.gz
|
||||
tar xzf tzdata$DATA.tar.gz
|
||||
|
||||
# Turn off 64-bit output in time zone files.
|
||||
# We don't need those until 2037.
|
||||
perl -p -i -e 's/pass <= 2/pass <= 1/' zic.c
|
||||
|
||||
make CFLAGS=-DSTD_INSPIRED AWK=awk TZDIR=zoneinfo posix_only
|
||||
|
||||
# America/Los_Angeles should not be bigger than 1100 bytes.
|
||||
# If it is, we probably failed to disable the 64-bit output, which
|
||||
# triples the size of the files.
|
||||
size=$(ls -l zoneinfo/America/Los_Angeles | awk '{print $5}')
|
||||
if [ $size -gt 1200 ]; then
|
||||
echo 'zone file too large; 64-bit edit failed?' >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
cd zoneinfo
|
||||
rm -f ../../zoneinfo.zip
|
||||
zip -0 -r ../../zoneinfo.zip *
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -6,18 +6,18 @@ mobile subrepository:
|
|||
|
||||
https://github.com/golang/mobile
|
||||
|
||||
To run the standard library tests, see androidtest.bash. Run it as
|
||||
To run the standard library tests, enable Cgo and use an appropriate
|
||||
C compiler from the Android NDK. For example,
|
||||
|
||||
CC_FOR_TARGET=$STANDALONE_NDK_PATH/bin/clang GOARCH=arm64 ./androidtest.bash
|
||||
|
||||
To create a standalone android NDK tool chain, follow the instructions on
|
||||
|
||||
https://developer.android.com/ndk/guides/standalone_toolchain
|
||||
CGO_ENABLED=1 \
|
||||
GOOS=android \
|
||||
GOARCH=arm64 \
|
||||
CC=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang \
|
||||
./all.bash
|
||||
|
||||
To run tests on the Android device, add the bin directory to PATH so the
|
||||
go tool can find the go_android_$GOARCH_exec wrapper generated by
|
||||
androidtest.bash. Then, use the same GOARCH as when androidtest.bash ran
|
||||
and set GOOS to android. For example, to run the go1 benchmarks
|
||||
make.bash. For example, to run the go1 benchmarks
|
||||
|
||||
export PATH=$GOROOT/bin:$PATH
|
||||
cd $GOROOT/test/bench/go1/
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
// Copyright 2015 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.
|
||||
|
||||
// Cleaner removes anything from /data/local/tmp/goroot not on a builtin list.
|
||||
// Used by androidtest.bash.
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
const goroot = "/data/local/tmp/goroot"
|
||||
expect := make(map[string]bool)
|
||||
for _, f := range strings.Split(files, "\n") {
|
||||
expect[filepath.Join(goroot, f)] = true
|
||||
}
|
||||
|
||||
err := filepath.Walk(goroot, func(path string, info os.FileInfo, err error) error {
|
||||
if expect[path] {
|
||||
return nil
|
||||
}
|
||||
log.Printf("removing %s", path)
|
||||
if err := os.RemoveAll(path); err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
// This program can be used as go_android_GOARCH_exec by the Go tool.
|
||||
// It executes binaries on an android device using adb.
|
||||
package main
|
||||
|
|
@ -11,6 +13,7 @@ import (
|
|||
"fmt"
|
||||
"go/build"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
|
@ -57,6 +60,24 @@ func main() {
|
|||
log.SetFlags(0)
|
||||
log.SetPrefix("go_android_exec: ")
|
||||
|
||||
// Concurrent use of adb is flaky, so serialize adb commands.
|
||||
// See https://github.com/golang/go/issues/23795 or
|
||||
// https://issuetracker.google.com/issues/73230216.
|
||||
lockPath := filepath.Join(os.TempDir(), "go_android_exec-adb-lock")
|
||||
lock, err := os.OpenFile(lockPath, os.O_CREATE|os.O_RDWR, 0666)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer lock.Close()
|
||||
if err := syscall.Flock(int(lock.Fd()), syscall.LOCK_EX); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// In case we're booting a device or emulator alongside androidtest.bash
|
||||
// wait for it to be ready. adb wait-for-device is not enough, we have to
|
||||
// wait for sys.boot_completed.
|
||||
run("wait-for-device", "shell", "while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;")
|
||||
|
||||
// Prepare a temporary directory that will be cleaned up at the end.
|
||||
deviceGotmp := fmt.Sprintf("/data/local/tmp/%s-%d",
|
||||
filepath.Base(os.Args[1]), os.Getpid())
|
||||
|
|
@ -71,21 +92,20 @@ func main() {
|
|||
deviceCwd := filepath.Join(deviceGoroot, subdir)
|
||||
if !inGoRoot {
|
||||
deviceCwd = filepath.Join(deviceGopath, subdir)
|
||||
} else {
|
||||
adbSyncGoroot()
|
||||
}
|
||||
run("shell", "mkdir", "-p", deviceCwd)
|
||||
|
||||
// Binary names can conflict.
|
||||
// E.g. template.test from the {html,text}/template packages.
|
||||
binName := fmt.Sprintf("%s-%d", filepath.Base(os.Args[1]), os.Getpid())
|
||||
deviceBin := fmt.Sprintf("%s/%s", deviceGotmp, binName)
|
||||
run("push", os.Args[1], deviceBin)
|
||||
|
||||
// The push of the binary happens in parallel with other tests.
|
||||
// Unfortunately, a simultaneous call to adb shell hold open
|
||||
// file descriptors, so it is necessary to push then move to
|
||||
// avoid a "text file busy" error on execution.
|
||||
// https://code.google.com/p/android/issues/detail?id=65857
|
||||
run("push", os.Args[1], deviceBin+"-tmp")
|
||||
run("shell", "cp '"+deviceBin+"-tmp' '"+deviceBin+"'")
|
||||
run("shell", "rm '"+deviceBin+"-tmp'")
|
||||
if _, err := os.Stat("testdata"); err == nil {
|
||||
run("push", "testdata", deviceCwd)
|
||||
}
|
||||
|
||||
// Forward SIGQUIT from the go command to show backtraces from
|
||||
// the binary instead of from this wrapper.
|
||||
|
|
@ -157,3 +177,46 @@ func subdir() (pkgpath string, underGoRoot bool) {
|
|||
cwd, runtime.GOROOT(), build.Default.GOPATH)
|
||||
return "", false
|
||||
}
|
||||
|
||||
// adbSyncGoroot ensures that files necessary for testing the Go standard
|
||||
// packages are present on the attached device.
|
||||
func adbSyncGoroot() {
|
||||
// Also known by cmd/dist. The bootstrap command deletes the file.
|
||||
statPath := filepath.Join(os.TempDir(), "go_android_exec-adb-sync-status")
|
||||
stat, err := os.OpenFile(statPath, os.O_CREATE|os.O_RDWR, 0666)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer stat.Close()
|
||||
// Serialize check and syncing.
|
||||
if err := syscall.Flock(int(stat.Fd()), syscall.LOCK_EX); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
s, err := ioutil.ReadAll(stat)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if string(s) == "done" {
|
||||
return
|
||||
}
|
||||
devRoot := "/data/local/tmp/goroot"
|
||||
run("shell", "rm", "-rf", devRoot)
|
||||
run("shell", "mkdir", "-p", devRoot+"/pkg")
|
||||
goroot := runtime.GOROOT()
|
||||
goCmd := filepath.Join(goroot, "bin", "go")
|
||||
runtimea, err := exec.Command(goCmd, "list", "-f", "{{.Target}}", "runtime").Output()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
pkgdir := filepath.Dir(string(runtimea))
|
||||
if pkgdir == "" {
|
||||
log.Fatal("could not find android pkg dir")
|
||||
}
|
||||
for _, dir := range []string{"src", "test", "lib"} {
|
||||
run("push", filepath.Join(goroot, dir), filepath.Join(devRoot))
|
||||
}
|
||||
run("push", filepath.Join(pkgdir), filepath.Join(devRoot, "pkg/"))
|
||||
if _, err := stat.Write([]byte("done")); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import (
|
|||
)
|
||||
|
||||
func path(file string) string {
|
||||
return filepath.Join("src", file)
|
||||
return filepath.Join("testdata", file)
|
||||
}
|
||||
|
||||
func check(t *testing.T, file string) {
|
||||
|
|
|
|||
|
|
@ -444,8 +444,8 @@ func testOne(t *testing.T, pt ptrTest) {
|
|||
}
|
||||
defer os.RemoveAll(gopath)
|
||||
|
||||
src := filepath.Join(gopath, "src")
|
||||
if err := os.Mkdir(src, 0777); err != nil {
|
||||
src := filepath.Join(gopath, "src", "ptrtest")
|
||||
if err := os.MkdirAll(src, 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
@ -490,6 +490,11 @@ func testOne(t *testing.T, pt ptrTest) {
|
|||
}
|
||||
}
|
||||
|
||||
gomod := fmt.Sprintf("module %s\n", filepath.Base(src))
|
||||
if err := ioutil.WriteFile(filepath.Join(src, "go.mod"), []byte(gomod), 0666); err != nil {
|
||||
t.Fatalf("writing go.mod: %v", err)
|
||||
}
|
||||
|
||||
args := func(cmd *exec.Cmd) string {
|
||||
return strings.Join(cmd.Args, " ")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
// Copyright 2019 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 life_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
log.SetFlags(log.Lshortfile)
|
||||
os.Exit(testMain(m))
|
||||
}
|
||||
|
||||
func testMain(m *testing.M) int {
|
||||
GOPATH, err := ioutil.TempDir("", "cgolife")
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
defer os.RemoveAll(GOPATH)
|
||||
os.Setenv("GOPATH", GOPATH)
|
||||
|
||||
// Copy testdata into GOPATH/src/cgolife, along with a go.mod file
|
||||
// declaring the same path.
|
||||
modRoot := filepath.Join(GOPATH, "src", "cgolife")
|
||||
if err := overlayDir(modRoot, "testdata"); err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
if err := os.Chdir(modRoot); err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
os.Setenv("PWD", modRoot)
|
||||
if err := ioutil.WriteFile("go.mod", []byte("module cgolife\n"), 0666); err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
return m.Run()
|
||||
}
|
||||
|
||||
func TestTestRun(t *testing.T) {
|
||||
out, err := exec.Command("go", "env", "GOROOT").Output()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
GOROOT := string(bytes.TrimSpace(out))
|
||||
|
||||
cmd := exec.Command("go", "run", filepath.Join(GOROOT, "test", "run.go"), "-", ".")
|
||||
out, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %s\n%s", strings.Join(cmd.Args, " "), err, out)
|
||||
}
|
||||
t.Logf("%s:\n%s", strings.Join(cmd.Args, " "), out)
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
// Copyright 2019 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 life_test
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// overlayDir makes a minimal-overhead copy of srcRoot in which new files may be added.
|
||||
//
|
||||
// TODO: Once we no longer need to support the misc module in GOPATH mode,
|
||||
// factor this function out into a package to reduce duplication.
|
||||
func overlayDir(dstRoot, srcRoot string) error {
|
||||
dstRoot = filepath.Clean(dstRoot)
|
||||
if err := os.MkdirAll(dstRoot, 0777); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
symBase, err := filepath.Rel(srcRoot, dstRoot)
|
||||
if err != nil {
|
||||
symBase, err = filepath.Abs(srcRoot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
|
||||
if err != nil || srcPath == srcRoot {
|
||||
return err
|
||||
}
|
||||
|
||||
suffix := strings.TrimPrefix(srcPath, srcRoot)
|
||||
for len(suffix) > 0 && suffix[0] == filepath.Separator {
|
||||
suffix = suffix[1:]
|
||||
}
|
||||
dstPath := filepath.Join(dstRoot, suffix)
|
||||
|
||||
perm := info.Mode() & os.ModePerm
|
||||
if info.Mode()&os.ModeSymlink != 0 {
|
||||
info, err = os.Stat(srcPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
perm = info.Mode() & os.ModePerm
|
||||
}
|
||||
|
||||
// Always copy directories (don't symlink them).
|
||||
// If we add a file in the overlay, we don't want to add it in the original.
|
||||
if info.IsDir() {
|
||||
return os.Mkdir(dstPath, perm)
|
||||
}
|
||||
|
||||
// If the OS supports symlinks, use them instead of copying bytes.
|
||||
if err := os.Symlink(filepath.Join(symBase, suffix), dstPath); err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Otherwise, copy the bytes.
|
||||
src, err := os.Open(srcPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
dst, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = io.Copy(dst, src)
|
||||
if closeErr := dst.Close(); err == nil {
|
||||
err = closeErr
|
||||
}
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package life
|
||||
package cgolife
|
||||
|
||||
// #include "life.h"
|
||||
import "C"
|
||||
|
|
@ -14,7 +14,7 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
|
||||
"."
|
||||
"cgolife"
|
||||
)
|
||||
|
||||
const MAXDIM = 100
|
||||
|
|
@ -34,7 +34,7 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
life.Run(*gen, *dim, *dim, a[:])
|
||||
cgolife.Run(*gen, *dim, *dim, a[:])
|
||||
|
||||
for i := 0; i < *dim; i++ {
|
||||
for j := 0; j < *dim; j++ {
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
// Copyright 2019 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 stdio_test
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// overlayDir makes a minimal-overhead copy of srcRoot in which new files may be added.
|
||||
//
|
||||
// TODO: Once we no longer need to support the misc module in GOPATH mode,
|
||||
// factor this function out into a package to reduce duplication.
|
||||
func overlayDir(dstRoot, srcRoot string) error {
|
||||
dstRoot = filepath.Clean(dstRoot)
|
||||
if err := os.MkdirAll(dstRoot, 0777); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
symBase, err := filepath.Rel(srcRoot, dstRoot)
|
||||
if err != nil {
|
||||
symBase, err = filepath.Abs(srcRoot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
|
||||
if err != nil || srcPath == srcRoot {
|
||||
return err
|
||||
}
|
||||
|
||||
suffix := strings.TrimPrefix(srcPath, srcRoot)
|
||||
for len(suffix) > 0 && suffix[0] == filepath.Separator {
|
||||
suffix = suffix[1:]
|
||||
}
|
||||
dstPath := filepath.Join(dstRoot, suffix)
|
||||
|
||||
perm := info.Mode() & os.ModePerm
|
||||
if info.Mode()&os.ModeSymlink != 0 {
|
||||
info, err = os.Stat(srcPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
perm = info.Mode() & os.ModePerm
|
||||
}
|
||||
|
||||
// Always copy directories (don't symlink them).
|
||||
// If we add a file in the overlay, we don't want to add it in the original.
|
||||
if info.IsDir() {
|
||||
return os.Mkdir(dstPath, perm)
|
||||
}
|
||||
|
||||
// If the OS supports symlinks, use them instead of copying bytes.
|
||||
if err := os.Symlink(filepath.Join(symBase, suffix), dstPath); err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Otherwise, copy the bytes.
|
||||
src, err := os.Open(srcPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
dst, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = io.Copy(dst, src)
|
||||
if closeErr := dst.Close(); err == nil {
|
||||
err = closeErr
|
||||
}
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
// Copyright 2019 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 stdio_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
log.SetFlags(log.Lshortfile)
|
||||
os.Exit(testMain(m))
|
||||
}
|
||||
|
||||
func testMain(m *testing.M) int {
|
||||
GOPATH, err := ioutil.TempDir("", "cgostdio")
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
defer os.RemoveAll(GOPATH)
|
||||
os.Setenv("GOPATH", GOPATH)
|
||||
|
||||
// Copy testdata into GOPATH/src/cgostdio, along with a go.mod file
|
||||
// declaring the same path.
|
||||
modRoot := filepath.Join(GOPATH, "src", "cgostdio")
|
||||
if err := overlayDir(modRoot, "testdata"); err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
if err := os.Chdir(modRoot); err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
os.Setenv("PWD", modRoot)
|
||||
if err := ioutil.WriteFile("go.mod", []byte("module cgostdio\n"), 0666); err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
return m.Run()
|
||||
}
|
||||
|
||||
func TestTestRun(t *testing.T) {
|
||||
out, err := exec.Command("go", "env", "GOROOT").Output()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
GOROOT := string(bytes.TrimSpace(out))
|
||||
|
||||
cmd := exec.Command("go", "run", filepath.Join(GOROOT, "test", "run.go"), "-", ".")
|
||||
out, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %s\n%s", strings.Join(cmd.Args, " "), err, out)
|
||||
}
|
||||
t.Logf("%s:\n%s", strings.Join(cmd.Args, " "), out)
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ import (
|
|||
"runtime"
|
||||
"strconv"
|
||||
|
||||
"../stdio"
|
||||
"cgostdio/stdio"
|
||||
)
|
||||
|
||||
const N = 10
|
||||
|
|
@ -17,7 +17,7 @@ import (
|
|||
"runtime"
|
||||
"strconv"
|
||||
|
||||
"../stdio"
|
||||
"cgostdio/stdio"
|
||||
)
|
||||
|
||||
func fibber(c, out chan int64, i int64) {
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
package main
|
||||
|
||||
import "../stdio"
|
||||
import "cgostdio/stdio"
|
||||
|
||||
func main() {
|
||||
stdio.Stdout.WriteString(stdio.Greeting + "\n")
|
||||
|
|
@ -209,6 +209,10 @@ func testCallbackCallers(t *testing.T) {
|
|||
if strings.HasPrefix(fname, "_") {
|
||||
fname = path.Base(f.Name()[1:])
|
||||
}
|
||||
// In module mode, this package has a fully-qualified import path.
|
||||
// Remove it if present.
|
||||
fname = strings.TrimPrefix(fname, "misc/cgo/")
|
||||
|
||||
namei := ""
|
||||
if i < len(name) {
|
||||
namei = name[i]
|
||||
|
|
|
|||
|
|
@ -9,4 +9,3 @@ import "testing"
|
|||
func TestSetgid(t *testing.T) { testSetgid(t) }
|
||||
func Test6997(t *testing.T) { test6997(t) }
|
||||
func TestBuildID(t *testing.T) { testBuildID(t) }
|
||||
func Test9400(t *testing.T) { test9400(t) }
|
||||
|
|
|
|||
|
|
@ -10,91 +10,85 @@ import "testing"
|
|||
// so that they can use cgo (import "C").
|
||||
// These wrappers are here for gotest to find.
|
||||
|
||||
func TestAlign(t *testing.T) { testAlign(t) }
|
||||
func TestConst(t *testing.T) { testConst(t) }
|
||||
func TestEnum(t *testing.T) { testEnum(t) }
|
||||
func TestAtol(t *testing.T) { testAtol(t) }
|
||||
func TestErrno(t *testing.T) { testErrno(t) }
|
||||
func TestMultipleAssign(t *testing.T) { testMultipleAssign(t) }
|
||||
func TestUnsignedInt(t *testing.T) { testUnsignedInt(t) }
|
||||
func TestCallback(t *testing.T) { testCallback(t) }
|
||||
func TestCallbackGC(t *testing.T) { testCallbackGC(t) }
|
||||
func TestCallbackPanic(t *testing.T) { testCallbackPanic(t) }
|
||||
func TestCallbackPanicLoop(t *testing.T) { testCallbackPanicLoop(t) }
|
||||
func TestCallbackPanicLocked(t *testing.T) { testCallbackPanicLocked(t) }
|
||||
func TestPanicFromC(t *testing.T) { testPanicFromC(t) }
|
||||
func TestZeroArgCallback(t *testing.T) { testZeroArgCallback(t) }
|
||||
func TestBlocking(t *testing.T) { testBlocking(t) }
|
||||
func Test1328(t *testing.T) { test1328(t) }
|
||||
func TestParallelSleep(t *testing.T) { testParallelSleep(t) }
|
||||
func TestSetEnv(t *testing.T) { testSetEnv(t) }
|
||||
func TestHelpers(t *testing.T) { testHelpers(t) }
|
||||
func TestLibgcc(t *testing.T) { testLibgcc(t) }
|
||||
func Test1635(t *testing.T) { test1635(t) }
|
||||
func TestPrintf(t *testing.T) { testPrintf(t) }
|
||||
func Test4029(t *testing.T) { test4029(t) }
|
||||
func TestBoolAlign(t *testing.T) { testBoolAlign(t) }
|
||||
func Test3250(t *testing.T) { test3250(t) }
|
||||
func Test3729(t *testing.T) { test3729(t) }
|
||||
func Test3775(t *testing.T) { test3775(t) }
|
||||
func TestCthread(t *testing.T) { testCthread(t) }
|
||||
func TestCallbackCallers(t *testing.T) { testCallbackCallers(t) }
|
||||
func Test4029(t *testing.T) { test4029(t) }
|
||||
func Test4339(t *testing.T) { test4339(t) }
|
||||
func Test5227(t *testing.T) { test5227(t) }
|
||||
func TestCflags(t *testing.T) { testCflags(t) }
|
||||
func Test5242(t *testing.T) { test5242(t) }
|
||||
func Test5337(t *testing.T) { test5337(t) }
|
||||
func Test5548(t *testing.T) { test5548(t) }
|
||||
func Test5603(t *testing.T) { test5603(t) }
|
||||
func Test6833(t *testing.T) { test6833(t) }
|
||||
func Test3250(t *testing.T) { test3250(t) }
|
||||
func TestCallbackStack(t *testing.T) { testCallbackStack(t) }
|
||||
func TestFpVar(t *testing.T) { testFpVar(t) }
|
||||
func Test4339(t *testing.T) { test4339(t) }
|
||||
func Test6390(t *testing.T) { test6390(t) }
|
||||
func Test5986(t *testing.T) { test5986(t) }
|
||||
func Test7665(t *testing.T) { test7665(t) }
|
||||
func TestNaming(t *testing.T) { testNaming(t) }
|
||||
func Test6390(t *testing.T) { test6390(t) }
|
||||
func Test6833(t *testing.T) { test6833(t) }
|
||||
func Test6907(t *testing.T) { test6907(t) }
|
||||
func Test6907Go(t *testing.T) { test6907Go(t) }
|
||||
func Test7560(t *testing.T) { test7560(t) }
|
||||
func Test5242(t *testing.T) { test5242(t) }
|
||||
func Test8092(t *testing.T) { test8092(t) }
|
||||
func Test7665(t *testing.T) { test7665(t) }
|
||||
func Test7978(t *testing.T) { test7978(t) }
|
||||
func Test8694(t *testing.T) { test8694(t) }
|
||||
func Test8092(t *testing.T) { test8092(t) }
|
||||
func Test8517(t *testing.T) { test8517(t) }
|
||||
func Test8694(t *testing.T) { test8694(t) }
|
||||
func Test8811(t *testing.T) { test8811(t) }
|
||||
func TestReturnAfterGrow(t *testing.T) { testReturnAfterGrow(t) }
|
||||
func TestReturnAfterGrowFromGo(t *testing.T) { testReturnAfterGrowFromGo(t) }
|
||||
func Test9026(t *testing.T) { test9026(t) }
|
||||
func Test9510(t *testing.T) { test9510(t) }
|
||||
func Test9557(t *testing.T) { test9557(t) }
|
||||
func Test10303(t *testing.T) { test10303(t, 10) }
|
||||
func Test11925(t *testing.T) { test11925(t) }
|
||||
func Test12030(t *testing.T) { test12030(t) }
|
||||
func TestGCC68255(t *testing.T) { testGCC68255(t) }
|
||||
func TestCallGoWithString(t *testing.T) { testCallGoWithString(t) }
|
||||
func Test14838(t *testing.T) { test14838(t) }
|
||||
func Test8756(t *testing.T) { test8756(t) }
|
||||
func Test17065(t *testing.T) { test17065(t) }
|
||||
func TestThreadLock(t *testing.T) { testThreadLockFunc(t) }
|
||||
func TestCheckConst(t *testing.T) { testCheckConst(t) }
|
||||
func Test17537(t *testing.T) { test17537(t) }
|
||||
func Test18126(t *testing.T) { test18126(t) }
|
||||
func Test20369(t *testing.T) { test20369(t) }
|
||||
func Test18720(t *testing.T) { test18720(t) }
|
||||
func Test20266(t *testing.T) { test20266(t) }
|
||||
func Test20129(t *testing.T) { test20129(t) }
|
||||
func Test20369(t *testing.T) { test20369(t) }
|
||||
func Test20910(t *testing.T) { test20910(t) }
|
||||
func Test21708(t *testing.T) { test21708(t) }
|
||||
func Test21809(t *testing.T) { test21809(t) }
|
||||
func Test6907(t *testing.T) { test6907(t) }
|
||||
func Test6907Go(t *testing.T) { test6907Go(t) }
|
||||
func Test21897(t *testing.T) { test21897(t) }
|
||||
func Test22906(t *testing.T) { test22906(t) }
|
||||
func Test23356(t *testing.T) { test23356(t) }
|
||||
func Test24206(t *testing.T) { test24206(t) }
|
||||
func Test25143(t *testing.T) { test25143(t) }
|
||||
func Test23356(t *testing.T) { test23356(t) }
|
||||
func Test26066(t *testing.T) { test26066(t) }
|
||||
func Test26213(t *testing.T) { test26213(t) }
|
||||
func Test27660(t *testing.T) { test27660(t) }
|
||||
func Test28896(t *testing.T) { test28896(t) }
|
||||
func Test30065(t *testing.T) { test30065(t) }
|
||||
func TestAlign(t *testing.T) { testAlign(t) }
|
||||
func TestAtol(t *testing.T) { testAtol(t) }
|
||||
func TestBlocking(t *testing.T) { testBlocking(t) }
|
||||
func TestBoolAlign(t *testing.T) { testBoolAlign(t) }
|
||||
func TestCallGoWithString(t *testing.T) { testCallGoWithString(t) }
|
||||
func TestCallback(t *testing.T) { testCallback(t) }
|
||||
func TestCallbackCallers(t *testing.T) { testCallbackCallers(t) }
|
||||
func TestCallbackGC(t *testing.T) { testCallbackGC(t) }
|
||||
func TestCallbackPanic(t *testing.T) { testCallbackPanic(t) }
|
||||
func TestCallbackPanicLocked(t *testing.T) { testCallbackPanicLocked(t) }
|
||||
func TestCallbackPanicLoop(t *testing.T) { testCallbackPanicLoop(t) }
|
||||
func TestCallbackStack(t *testing.T) { testCallbackStack(t) }
|
||||
func TestCflags(t *testing.T) { testCflags(t) }
|
||||
func TestCheckConst(t *testing.T) { testCheckConst(t) }
|
||||
func TestConst(t *testing.T) { testConst(t) }
|
||||
func TestCthread(t *testing.T) { testCthread(t) }
|
||||
func TestEnum(t *testing.T) { testEnum(t) }
|
||||
func TestErrno(t *testing.T) { testErrno(t) }
|
||||
func TestFpVar(t *testing.T) { testFpVar(t) }
|
||||
func TestHelpers(t *testing.T) { testHelpers(t) }
|
||||
func TestLibgcc(t *testing.T) { testLibgcc(t) }
|
||||
func TestMultipleAssign(t *testing.T) { testMultipleAssign(t) }
|
||||
func TestNaming(t *testing.T) { testNaming(t) }
|
||||
func TestPanicFromC(t *testing.T) { testPanicFromC(t) }
|
||||
func TestParallelSleep(t *testing.T) { testParallelSleep(t) }
|
||||
func TestPrintf(t *testing.T) { testPrintf(t) }
|
||||
func TestReturnAfterGrow(t *testing.T) { testReturnAfterGrow(t) }
|
||||
func TestReturnAfterGrowFromGo(t *testing.T) { testReturnAfterGrowFromGo(t) }
|
||||
func TestSetEnv(t *testing.T) { testSetEnv(t) }
|
||||
func TestThreadLock(t *testing.T) { testThreadLockFunc(t) }
|
||||
func TestUnsignedInt(t *testing.T) { testUnsignedInt(t) }
|
||||
func TestZeroArgCallback(t *testing.T) { testZeroArgCallback(t) }
|
||||
|
||||
func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
|
||||
func BenchmarkGoString(b *testing.B) { benchGoString(b) }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,81 @@
|
|||
// Copyright 2019 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 cgotest
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// overlayDir makes a minimal-overhead copy of srcRoot in which new files may be added.
|
||||
//
|
||||
// TODO: Once we no longer need to support the misc module in GOPATH mode,
|
||||
// factor this function out into a package to reduce duplication.
|
||||
func overlayDir(dstRoot, srcRoot string) error {
|
||||
dstRoot = filepath.Clean(dstRoot)
|
||||
if err := os.MkdirAll(dstRoot, 0777); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
symBase, err := filepath.Rel(srcRoot, dstRoot)
|
||||
if err != nil {
|
||||
symBase, err = filepath.Abs(srcRoot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
|
||||
if err != nil || srcPath == srcRoot {
|
||||
return err
|
||||
}
|
||||
|
||||
suffix := strings.TrimPrefix(srcPath, srcRoot)
|
||||
for len(suffix) > 0 && suffix[0] == filepath.Separator {
|
||||
suffix = suffix[1:]
|
||||
}
|
||||
dstPath := filepath.Join(dstRoot, suffix)
|
||||
|
||||
perm := info.Mode() & os.ModePerm
|
||||
if info.Mode()&os.ModeSymlink != 0 {
|
||||
info, err = os.Stat(srcPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
perm = info.Mode() & os.ModePerm
|
||||
}
|
||||
|
||||
// Always copy directories (don't symlink them).
|
||||
// If we add a file in the overlay, we don't want to add it in the original.
|
||||
if info.IsDir() {
|
||||
return os.Mkdir(dstPath, perm)
|
||||
}
|
||||
|
||||
// If the OS supports symlinks, use them instead of copying bytes.
|
||||
if err := os.Symlink(filepath.Join(symBase, suffix), dstPath); err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Otherwise, copy the bytes.
|
||||
src, err := os.Open(srcPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
dst, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, perm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = io.Copy(dst, src)
|
||||
if closeErr := dst.Close(); err == nil {
|
||||
err = closeErr
|
||||
}
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
// Copyright 2019 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 cgotest
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestCrossPackageTests compiles and runs tests that depend on imports of other
|
||||
// local packages, using source code stored in the testdata directory.
|
||||
//
|
||||
// The tests in the misc directory tree do not have a valid import path in
|
||||
// GOPATH mode, so they previously used relative imports. However, relative
|
||||
// imports do not work in module mode. In order to make the test work in both
|
||||
// modes, we synthesize a GOPATH in which the module paths are equivalent, and
|
||||
// run the tests as a subprocess.
|
||||
//
|
||||
// If and when we no longer support these tests in GOPATH mode, we can remove
|
||||
// this shim and move the tests currently located in testdata back into the
|
||||
// parent directory.
|
||||
func TestCrossPackageTests(t *testing.T) {
|
||||
if runtime.GOOS == "darwin" {
|
||||
switch runtime.GOARCH {
|
||||
case "arm", "arm64":
|
||||
t.Skip("Can't exec cmd/go subprocess on iOS.")
|
||||
}
|
||||
}
|
||||
|
||||
GOPATH, err := ioutil.TempDir("", "cgotest")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(GOPATH)
|
||||
|
||||
modRoot := filepath.Join(GOPATH, "src", "cgotest")
|
||||
if err := overlayDir(modRoot, "testdata"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ioutil.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgotest\n"), 0666); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cmd := exec.Command("go", "test")
|
||||
if testing.Verbose() {
|
||||
cmd.Args = append(cmd.Args, "-v")
|
||||
}
|
||||
if testing.Short() {
|
||||
cmd.Args = append(cmd.Args, "-short")
|
||||
}
|
||||
cmd.Dir = modRoot
|
||||
cmd.Env = append(os.Environ(), "GOPATH="+GOPATH)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err == nil {
|
||||
t.Logf("%s:\n%s", strings.Join(cmd.Args, " "), out)
|
||||
} else {
|
||||
t.Fatalf("%s: %s\n%s", strings.Join(cmd.Args, " "), err, out)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
// 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 cgotest
|
||||
|
||||
import "testing"
|
||||
|
||||
func Test9400(t *testing.T) { test9400(t) }
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright 2011 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 cgotest
|
||||
|
||||
import "testing"
|
||||
|
||||
// The actual test functions are in non-_test.go files
|
||||
// so that they can use cgo (import "C").
|
||||
// These wrappers are here for gotest to find.
|
||||
|
||||
func Test8756(t *testing.T) { test8756(t) }
|
||||
func Test9026(t *testing.T) { test9026(t) }
|
||||
func Test9510(t *testing.T) { test9510(t) }
|
||||
func Test20266(t *testing.T) { test20266(t) }
|
||||
func Test26213(t *testing.T) { test26213(t) }
|
||||
func TestGCC68255(t *testing.T) { testGCC68255(t) }
|
||||
|
|
@ -7,7 +7,7 @@ package cgotest
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"./gcc68255"
|
||||
"cgotest/gcc68255"
|
||||
)
|
||||
|
||||
func testGCC68255(t *testing.T) {
|
||||
|
|
@ -7,5 +7,5 @@
|
|||
|
||||
package cgotest
|
||||
|
||||
import _ "./issue23555a"
|
||||
import _ "./issue23555b"
|
||||
import _ "cgotest/issue23555a"
|
||||
import _ "cgotest/issue23555b"
|
||||
|
|
@ -15,11 +15,11 @@ package cgotest
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"./issue24161arg"
|
||||
"./issue24161e0"
|
||||
"./issue24161e1"
|
||||
"./issue24161e2"
|
||||
"./issue24161res"
|
||||
"cgotest/issue24161arg"
|
||||
"cgotest/issue24161e0"
|
||||
"cgotest/issue24161e1"
|
||||
"cgotest/issue24161e2"
|
||||
"cgotest/issue24161res"
|
||||
)
|
||||
|
||||
func Test24161Arg(t *testing.T) {
|
||||
|
|
@ -7,4 +7,4 @@
|
|||
|
||||
package cgotest
|
||||
|
||||
import _ "./issue26430"
|
||||
import _ "cgotest/issue26430"
|
||||
|
|
@ -7,4 +7,4 @@
|
|||
|
||||
package cgotest
|
||||
|
||||
import _ "./issue26743"
|
||||
import _ "cgotest/issue26743"
|
||||
|
|
@ -7,6 +7,6 @@
|
|||
|
||||
package cgotest
|
||||
|
||||
import "./issue27340"
|
||||
import "cgotest/issue27340"
|
||||
|
||||
var issue27340Var = issue27340.Issue27340GoFunc
|
||||
|
|
@ -8,7 +8,7 @@ import "C"
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"./issue8756"
|
||||
"cgotest/issue8756"
|
||||
)
|
||||
|
||||
func test8756(t *testing.T) {
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
package cgotest
|
||||
|
||||
import "./issue8828"
|
||||
import "cgotest/issue8828"
|
||||
|
||||
func p() {
|
||||
issue8828.Bar()
|
||||
|
|
@ -3,7 +3,7 @@ package cgotest
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"./issue9026"
|
||||
"cgotest/issue9026"
|
||||
)
|
||||
|
||||
func test9026(t *testing.T) { issue9026.Test(t) }
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue