Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
39208939
Commit
39208939
authored
Jun 15, 2011
by
Andrew Gerrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/build: better, self-contained tests
R=golang-dev, r CC=golang-dev
https://golang.org/cl/4576063
parent
bee3b035
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
95 additions
and
67 deletions
+95
-67
Makefile
src/pkg/go/build/Makefile
+1
-1
build_test.go
src/pkg/go/build/build_test.go
+32
-21
cgotest.go
src/pkg/go/build/cgotest/cgotest.go
+12
-0
file.go
src/pkg/go/build/cgotest/file.go
+0
-45
main.go
src/pkg/go/build/cmdtest/main.go
+12
-0
pkgtest.go
src/pkg/go/build/pkgtest/pkgtest.go
+9
-0
sqrt_386.s
src/pkg/go/build/pkgtest/sqrt_386.s
+10
-0
sqrt_amd64.s
src/pkg/go/build/pkgtest/sqrt_amd64.s
+9
-0
sqrt_arm.s
src/pkg/go/build/pkgtest/sqrt_arm.s
+10
-0
No files found.
src/pkg/go/build/Makefile
View file @
39208939
...
...
@@ -11,7 +11,7 @@ GOFILES=\
path.go
\
syslist.go
\
CLEANFILES
+=
syslist.go cgotest/_obj
CLEANFILES
+=
syslist.go
pkgtest/_obj cmdtest/_obj
cgotest/_obj
include
../../../Make.pkg
...
...
src/pkg/go/build/build_test.go
View file @
39208939
...
...
@@ -5,53 +5,64 @@
package
build
import
(
"exec"
"path/filepath"
"runtime"
"strings"
"testing"
)
// TODO(adg): test building binaries
var
buildPkgs
=
[]
string
{
"
path
"
,
"
big
"
,
"
go/build/pkgtest
"
,
"
go/build/cmdtest
"
,
"go/build/cgotest"
,
}
const
cmdtestOutput
=
"3"
func
TestBuild
(
t
*
testing
.
T
)
{
for
_
,
pkg
:=
range
buildPkgs
{
if
runtime
.
GOARCH
==
"arm"
&&
strings
.
Contains
(
pkg
,
"/cgo"
)
{
// no cgo for arm, yet.
continue
}
tree
:=
Path
[
0
]
// Goroot
testBuild
(
t
,
tree
,
pkg
)
}
}
func
testBuild
(
t
*
testing
.
T
,
tree
*
Tree
,
pkg
string
)
{
tree
:=
Path
[
0
]
// Goroot
dir
:=
filepath
.
Join
(
tree
.
SrcDir
(),
pkg
)
info
,
err
:=
ScanDir
(
dir
,
true
)
if
err
!=
nil
{
t
.
Error
(
err
)
return
t
.
Error
(
"ScanDir:"
,
err
)
continue
}
s
,
err
:=
Build
(
tree
,
pkg
,
info
)
if
err
!=
nil
{
t
.
Error
(
err
)
return
t
.
Error
(
"Build:"
,
err
)
continue
}
for
_
,
c
:=
range
s
.
Cmd
{
t
.
Log
(
"Run:"
,
c
)
err
=
c
.
Run
()
if
err
:=
s
.
Run
();
err
!=
nil
{
t
.
Error
(
"Run:"
,
err
)
continue
}
if
pkg
==
"go/build/cmdtest"
{
bin
:=
s
.
Output
[
0
]
b
,
err
:=
exec
.
Command
(
bin
)
.
CombinedOutput
()
if
err
!=
nil
{
t
.
Error
(
c
,
err
)
return
t
.
Errorf
(
"exec: %s: %v"
,
bin
,
err
)
continue
}
if
string
(
b
)
!=
cmdtestOutput
{
t
.
Errorf
(
"cmdtest output: %s want: %s"
,
b
,
cmdtestOutput
)
}
}
if
err
:=
s
.
Clean
();
err
!=
nil
{
t
.
Errorf
(
"cleaning: %v"
,
err
)
t
.
Logf
(
"Intermediate: %v"
,
s
.
Intermediate
)
defer
func
(
s
*
Script
)
{
if
err
:=
s
.
Nuke
();
err
!=
nil
{
t
.
Errorf
(
"nuking: %v"
,
err
)
}
}(
s
)
}
}
src/pkg/go/build/cgotest/cgotest.go
0 → 100644
View file @
39208939
// 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
/*
char* greeting = "hello, world";
*/
import
"C"
var
Greeting
=
C
.
GoString
(
C
.
greeting
)
src/pkg/go/build/cgotest/file.go
deleted
100644 → 0
View file @
bee3b035
// Copyright 2009 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 trivial example of wrapping a C library in Go.
For a more complex example and explanation,
see ../gmp/gmp.go.
*/
package
stdio
/*
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <errno.h>
char* greeting = "hello, world";
*/
import
"C"
import
"unsafe"
type
File
C
.
FILE
// TODO(brainman): uncomment once stdout and stderr references are working on Windows.
//var Stdout = (*File)(C.stdout)
//var Stderr = (*File)(C.stderr)
// Test reference to library symbol.
// Stdout and stderr are too special to be a reliable test.
var
myerr
=
C
.
sys_errlist
func
(
f
*
File
)
WriteString
(
s
string
)
{
p
:=
C
.
CString
(
s
)
C
.
fputs
(
p
,
(
*
C
.
FILE
)(
f
))
C
.
free
(
unsafe
.
Pointer
(
p
))
f
.
Flush
()
}
func
(
f
*
File
)
Flush
()
{
C
.
fflush
((
*
C
.
FILE
)(
f
))
}
var
Greeting
=
C
.
GoString
(
C
.
greeting
)
src/pkg/go/build/cmdtest/main.go
0 → 100644
View file @
39208939
// 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
main
import
"go/build/pkgtest"
func
main
()
{
pkgtest
.
Foo
()
print
(
int
(
pkgtest
.
Sqrt
(
9
)))
}
src/pkg/go/build/pkgtest/pkgtest.go
0 → 100644
View file @
39208939
// 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
pkgtest
func
Foo
()
{}
func
Sqrt
(
x
float64
)
float64
src/pkg/go/build/pkgtest/sqrt_386.s
0 → 100644
View file @
39208939
// Copyright 2009 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.
// func Sqrt(x float64) float64
TEXT ·Sqrt(SB),7,$0
FMOVD x+0(FP),F0
FSQRT
FMOVDP F0,r+8(FP)
RET
src/pkg/go/build/pkgtest/sqrt_amd64.s
0 → 100644
View file @
39208939
// Copyright 2009 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.
// func Sqrt(x float64) float64
TEXT ·Sqrt(SB),7,$0
SQRTSD x+0(FP), X0
MOVSD X0, r+8(FP)
RET
src/pkg/go/build/pkgtest/sqrt_arm.s
0 → 100644
View file @
39208939
// 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.
// func Sqrt(x float64) float64
TEXT ·Sqrt(SB),7,$0
MOVD x+0(FP),F0
SQRTD F0,F0
MOVD F0,r+8(FP)
RET
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment