Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
a236804c
Commit
a236804c
authored
Nov 23, 2014
by
Russ Cox
Browse files
Options
Browse Files
Download
Plain Diff
[dev.cc] all: merge default (95f5614b4648) into dev.cc
TBR=austin CC=golang-codereviews
https://golang.org/cl/177220044
parents
0d768874
04923042
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
36 deletions
+72
-36
src/cmd/go/tool.go
src/cmd/go/tool.go
+1
-11
src/go/parser/error_test.go
src/go/parser/error_test.go
+13
-14
src/go/parser/parser_test.go
src/go/parser/parser_test.go
+9
-11
src/image/jpeg/reader.go
src/image/jpeg/reader.go
+3
-0
src/image/jpeg/reader_test.go
src/image/jpeg/reader_test.go
+46
-0
No files found.
src/cmd/go/tool.go
View file @
a236804c
...
...
@@ -47,7 +47,7 @@ const toolWindowsExtension = ".exe"
func
tool
(
toolName
string
)
string
{
toolPath
:=
filepath
.
Join
(
toolDir
,
toolName
)
if
toolIsWindows
&&
toolName
!=
"pprof"
{
if
toolIsWindows
{
toolPath
+=
toolWindowsExtension
}
// Give a nice message if there is no tool with that name.
...
...
@@ -91,16 +91,6 @@ func runTool(cmd *Command, args []string) {
if
toolPath
==
""
{
return
}
if
toolIsWindows
&&
toolName
==
"pprof"
{
args
=
append
([]
string
{
"perl"
,
toolPath
},
args
[
1
:
]
...
)
var
err
error
toolPath
,
err
=
exec
.
LookPath
(
"perl"
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"go tool: perl not found
\n
"
)
setExitStatus
(
3
)
return
}
}
if
toolN
{
fmt
.
Printf
(
"%s %s
\n
"
,
toolPath
,
strings
.
Join
(
args
[
1
:
],
" "
))
return
...
...
src/go/parser/error_test.go
View file @
a236804c
...
...
@@ -34,11 +34,9 @@ import (
const
testdata
=
"testdata"
var
fsetErrs
=
token
.
NewFileSet
()
// getFile assumes that each filename occurs at most once
func
getFile
(
filename
string
)
(
file
*
token
.
File
)
{
fset
Errs
.
Iterate
(
func
(
f
*
token
.
File
)
bool
{
func
getFile
(
f
set
*
token
.
FileSet
,
f
ilename
string
)
(
file
*
token
.
File
)
{
fset
.
Iterate
(
func
(
f
*
token
.
File
)
bool
{
if
f
.
Name
()
==
filename
{
if
file
!=
nil
{
panic
(
filename
+
" used multiple times"
)
...
...
@@ -50,8 +48,8 @@ func getFile(filename string) (file *token.File) {
return
file
}
func
getPos
(
filename
string
,
offset
int
)
token
.
Pos
{
if
f
:=
getFile
(
filename
);
f
!=
nil
{
func
getPos
(
f
set
*
token
.
FileSet
,
f
ilename
string
,
offset
int
)
token
.
Pos
{
if
f
:=
getFile
(
f
set
,
f
ilename
);
f
!=
nil
{
return
f
.
Pos
(
offset
)
}
return
token
.
NoPos
...
...
@@ -68,14 +66,14 @@ var errRx = regexp.MustCompile(`^/\* *ERROR *(HERE)? *"([^"]*)" *\*/$`)
// expectedErrors collects the regular expressions of ERROR comments found
// in files and returns them as a map of error positions to error messages.
//
func
expectedErrors
(
t
*
testing
.
T
,
filename
string
,
src
[]
byte
)
map
[
token
.
Pos
]
string
{
func
expectedErrors
(
t
*
testing
.
T
,
f
set
*
token
.
FileSet
,
f
ilename
string
,
src
[]
byte
)
map
[
token
.
Pos
]
string
{
errors
:=
make
(
map
[
token
.
Pos
]
string
)
var
s
scanner
.
Scanner
// file was parsed already - do not add it again to the file
// set otherwise the position information returned here will
// not match the position information collected by the parser
s
.
Init
(
getFile
(
filename
),
src
,
nil
,
scanner
.
ScanComments
)
s
.
Init
(
getFile
(
f
set
,
f
ilename
),
src
,
nil
,
scanner
.
ScanComments
)
var
prev
token
.
Pos
// position of last non-comment, non-semicolon token
var
here
token
.
Pos
// position immediately after the token at position prev
...
...
@@ -109,11 +107,11 @@ func expectedErrors(t *testing.T, filename string, src []byte) map[token.Pos]str
// compareErrors compares the map of expected error messages with the list
// of found errors and reports discrepancies.
//
func
compareErrors
(
t
*
testing
.
T
,
expected
map
[
token
.
Pos
]
string
,
found
scanner
.
ErrorList
)
{
func
compareErrors
(
t
*
testing
.
T
,
fset
*
token
.
FileSet
,
expected
map
[
token
.
Pos
]
string
,
found
scanner
.
ErrorList
)
{
for
_
,
error
:=
range
found
{
// error.Pos is a token.Position, but we want
// a token.Pos so we can do a map lookup
pos
:=
getPos
(
error
.
Pos
.
Filename
,
error
.
Pos
.
Offset
)
pos
:=
getPos
(
fset
,
error
.
Pos
.
Filename
,
error
.
Pos
.
Offset
)
if
msg
,
found
:=
expected
[
pos
];
found
{
// we expect a message at pos; check if it matches
rx
,
err
:=
regexp
.
Compile
(
msg
)
...
...
@@ -140,7 +138,7 @@ func compareErrors(t *testing.T, expected map[token.Pos]string, found scanner.Er
if
len
(
expected
)
>
0
{
t
.
Errorf
(
"%d errors not reported:"
,
len
(
expected
))
for
pos
,
msg
:=
range
expected
{
t
.
Errorf
(
"%s: %s
\n
"
,
fset
Errs
.
Position
(
pos
),
msg
)
t
.
Errorf
(
"%s: %s
\n
"
,
fset
.
Position
(
pos
),
msg
)
}
}
}
...
...
@@ -152,7 +150,8 @@ func checkErrors(t *testing.T, filename string, input interface{}) {
return
}
_
,
err
=
ParseFile
(
fsetErrs
,
filename
,
src
,
DeclarationErrors
|
AllErrors
)
fset
:=
token
.
NewFileSet
()
_
,
err
=
ParseFile
(
fset
,
filename
,
src
,
DeclarationErrors
|
AllErrors
)
found
,
ok
:=
err
.
(
scanner
.
ErrorList
)
if
err
!=
nil
&&
!
ok
{
t
.
Error
(
err
)
...
...
@@ -162,10 +161,10 @@ func checkErrors(t *testing.T, filename string, input interface{}) {
// we are expecting the following errors
// (collect these after parsing a file so that it is found in the file set)
expected
:=
expectedErrors
(
t
,
filename
,
src
)
expected
:=
expectedErrors
(
t
,
f
set
,
f
ilename
,
src
)
// verify errors returned by the parser
compareErrors
(
t
,
expected
,
found
)
compareErrors
(
t
,
fset
,
expected
,
found
)
}
func
TestErrors
(
t
*
testing
.
T
)
{
...
...
src/go/parser/parser_test.go
View file @
a236804c
...
...
@@ -14,8 +14,6 @@ import (
"testing"
)
var
fset
=
token
.
NewFileSet
()
var
validFiles
=
[]
string
{
"parser.go"
,
"parser_test.go"
,
...
...
@@ -25,7 +23,7 @@ var validFiles = []string{
func
TestParse
(
t
*
testing
.
T
)
{
for
_
,
filename
:=
range
validFiles
{
_
,
err
:=
ParseFile
(
fset
,
filename
,
nil
,
DeclarationErrors
)
_
,
err
:=
ParseFile
(
token
.
NewFileSet
()
,
filename
,
nil
,
DeclarationErrors
)
if
err
!=
nil
{
t
.
Fatalf
(
"ParseFile(%s): %v"
,
filename
,
err
)
}
...
...
@@ -46,7 +44,7 @@ func dirFilter(f os.FileInfo) bool { return nameFilter(f.Name()) }
func
TestParseDir
(
t
*
testing
.
T
)
{
path
:=
"."
pkgs
,
err
:=
ParseDir
(
fset
,
path
,
dirFilter
,
0
)
pkgs
,
err
:=
ParseDir
(
token
.
NewFileSet
()
,
path
,
dirFilter
,
0
)
if
err
!=
nil
{
t
.
Fatalf
(
"ParseDir(%s): %v"
,
path
,
err
)
}
...
...
@@ -131,7 +129,7 @@ func TestParseExpr(t *testing.T) {
}
func
TestColonEqualsScope
(
t
*
testing
.
T
)
{
f
,
err
:=
ParseFile
(
fset
,
""
,
`package p; func f() { x, y, z := x, y, z }`
,
0
)
f
,
err
:=
ParseFile
(
token
.
NewFileSet
()
,
""
,
`package p; func f() { x, y, z := x, y, z }`
,
0
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -153,7 +151,7 @@ func TestColonEqualsScope(t *testing.T) {
}
func
TestVarScope
(
t
*
testing
.
T
)
{
f
,
err
:=
ParseFile
(
fset
,
""
,
`package p; func f() { var x, y, z = x, y, z }`
,
0
)
f
,
err
:=
ParseFile
(
token
.
NewFileSet
()
,
""
,
`package p; func f() { var x, y, z = x, y, z }`
,
0
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -183,7 +181,7 @@ var x int
func f() { L: }
`
f
,
err
:=
ParseFile
(
fset
,
""
,
src
,
0
)
f
,
err
:=
ParseFile
(
token
.
NewFileSet
()
,
""
,
src
,
0
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -221,7 +219,7 @@ func f() { L: }
}
func
TestUnresolved
(
t
*
testing
.
T
)
{
f
,
err
:=
ParseFile
(
fset
,
""
,
`
f
,
err
:=
ParseFile
(
token
.
NewFileSet
()
,
""
,
`
package p
//
func f1a(int)
...
...
@@ -316,7 +314,7 @@ var imports = map[string]bool{
func
TestImports
(
t
*
testing
.
T
)
{
for
path
,
isValid
:=
range
imports
{
src
:=
fmt
.
Sprintf
(
"package p; import %s"
,
path
)
_
,
err
:=
ParseFile
(
fset
,
""
,
src
,
0
)
_
,
err
:=
ParseFile
(
token
.
NewFileSet
()
,
""
,
src
,
0
)
switch
{
case
err
!=
nil
&&
isValid
:
t
.
Errorf
(
"ParseFile(%s): got %v; expected no error"
,
src
,
err
)
...
...
@@ -327,7 +325,7 @@ func TestImports(t *testing.T) {
}
func
TestCommentGroups
(
t
*
testing
.
T
)
{
f
,
err
:=
ParseFile
(
fset
,
""
,
`
f
,
err
:=
ParseFile
(
token
.
NewFileSet
()
,
""
,
`
package p /* 1a */ /* 1b */ /* 1c */ // 1d
/* 2a
*/
...
...
@@ -421,7 +419,7 @@ func checkFieldComments(t *testing.T, file *ast.File, fieldname, lead, line stri
}
func
TestLeadAndLineComments
(
t
*
testing
.
T
)
{
f
,
err
:=
ParseFile
(
fset
,
""
,
`
f
,
err
:=
ParseFile
(
token
.
NewFileSet
()
,
""
,
`
package p
type T struct {
/* F1 lead comment */
...
...
src/image/jpeg/reader.go
View file @
a236804c
...
...
@@ -143,6 +143,9 @@ func (d *decoder) fill() error {
// Fill in the rest of the buffer.
n
,
err
:=
d
.
r
.
Read
(
d
.
bytes
.
buf
[
d
.
bytes
.
j
:
])
d
.
bytes
.
j
+=
n
if
n
>
0
{
err
=
nil
}
return
err
}
...
...
src/image/jpeg/reader_test.go
View file @
a236804c
...
...
@@ -9,6 +9,7 @@ import (
"fmt"
"image"
"image/color"
"io"
"io/ioutil"
"math/rand"
"os"
...
...
@@ -88,6 +89,51 @@ func decodeFile(filename string) (image.Image, error) {
return
Decode
(
f
)
}
type
eofReader
struct
{
data
[]
byte
// deliver from Read without EOF
dataEOF
[]
byte
// then deliver from Read with EOF on last chunk
lenAtEOF
int
}
func
(
r
*
eofReader
)
Read
(
b
[]
byte
)
(
n
int
,
err
error
)
{
if
len
(
r
.
data
)
>
0
{
n
=
copy
(
b
,
r
.
data
)
r
.
data
=
r
.
data
[
n
:
]
}
else
{
n
=
copy
(
b
,
r
.
dataEOF
)
r
.
dataEOF
=
r
.
dataEOF
[
n
:
]
if
len
(
r
.
dataEOF
)
==
0
{
err
=
io
.
EOF
if
r
.
lenAtEOF
==
-
1
{
r
.
lenAtEOF
=
n
}
}
}
return
}
func
TestDecodeEOF
(
t
*
testing
.
T
)
{
// Check that if reader returns final data and EOF at same time, jpeg handles it.
data
,
err
:=
ioutil
.
ReadFile
(
"../testdata/video-001.jpeg"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
n
:=
len
(
data
)
for
i
:=
0
;
i
<
n
;
{
r
:=
&
eofReader
{
data
[
:
n
-
i
],
data
[
n
-
i
:
],
-
1
}
_
,
err
:=
Decode
(
r
)
if
err
!=
nil
{
t
.
Errorf
(
"Decode with Read() = %d, EOF: %v"
,
r
.
lenAtEOF
,
err
)
}
if
i
==
0
{
i
=
1
}
else
{
i
*=
2
}
}
}
// check checks that the two pix data are equal, within the given bounds.
func
check
(
bounds
image
.
Rectangle
,
pix0
,
pix1
[]
byte
,
stride0
,
stride1
int
)
error
{
if
stride0
<=
0
||
stride0
%
8
!=
0
{
...
...
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