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
dfb1af4b
Commit
dfb1af4b
authored
Mar 08, 2012
by
Mikio Hara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/gofmt: fix race in long test
Fixes #3249. R=rsc CC=golang-dev
https://golang.org/cl/5792043
parent
a40065ac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
10 deletions
+12
-10
src/cmd/gofmt/gofmt.go
src/cmd/gofmt/gofmt.go
+5
-5
src/cmd/gofmt/long_test.go
src/cmd/gofmt/long_test.go
+7
-5
No files found.
src/cmd/gofmt/gofmt.go
View file @
dfb1af4b
...
...
@@ -41,7 +41,7 @@ var (
)
var
(
f
set
=
token
.
NewFileSet
()
f
ileSet
=
token
.
NewFileSet
()
// per process FileSet
exitCode
=
0
rewrite
func
(
*
ast
.
File
)
*
ast
.
File
parserMode
parser
.
Mode
...
...
@@ -98,7 +98,7 @@ func processFile(filename string, in io.Reader, out io.Writer, stdin bool) error
return
err
}
file
,
adjust
,
err
:=
parse
(
filename
,
src
,
stdin
)
file
,
adjust
,
err
:=
parse
(
file
Set
,
file
name
,
src
,
stdin
)
if
err
!=
nil
{
return
err
}
...
...
@@ -111,14 +111,14 @@ func processFile(filename string, in io.Reader, out io.Writer, stdin bool) error
}
}
ast
.
SortImports
(
f
s
et
,
file
)
ast
.
SortImports
(
f
ileS
et
,
file
)
if
*
simplifyAST
{
simplify
(
file
)
}
var
buf
bytes
.
Buffer
err
=
(
&
printer
.
Config
{
Mode
:
printerMode
,
Tabwidth
:
*
tabWidth
})
.
Fprint
(
&
buf
,
f
s
et
,
file
)
err
=
(
&
printer
.
Config
{
Mode
:
printerMode
,
Tabwidth
:
*
tabWidth
})
.
Fprint
(
&
buf
,
f
ileS
et
,
file
)
if
err
!=
nil
{
return
err
}
...
...
@@ -254,7 +254,7 @@ func diff(b1, b2 []byte) (data []byte, err error) {
// parse parses src, which was read from filename,
// as a Go source file or statement list.
func
parse
(
filename
string
,
src
[]
byte
,
stdin
bool
)
(
*
ast
.
File
,
func
(
orig
,
src
[]
byte
)
[]
byte
,
error
)
{
func
parse
(
f
set
*
token
.
FileSet
,
f
ilename
string
,
src
[]
byte
,
stdin
bool
)
(
*
ast
.
File
,
func
(
orig
,
src
[]
byte
)
[]
byte
,
error
)
{
// Try as whole source file.
file
,
err
:=
parser
.
ParseFile
(
fset
,
filename
,
src
,
parserMode
)
if
err
==
nil
{
...
...
src/cmd/gofmt/long_test.go
View file @
dfb1af4b
...
...
@@ -14,6 +14,7 @@ import (
"fmt"
"go/ast"
"go/printer"
"go/token"
"io"
"os"
"path/filepath"
...
...
@@ -30,8 +31,8 @@ var (
nfiles
int
// number of files processed
)
func
gofmt
(
filename
string
,
src
*
bytes
.
Buffer
)
error
{
f
,
_
,
err
:=
parse
(
filename
,
src
.
Bytes
(),
false
)
func
gofmt
(
f
set
*
token
.
FileSet
,
f
ilename
string
,
src
*
bytes
.
Buffer
)
error
{
f
,
_
,
err
:=
parse
(
f
set
,
f
ilename
,
src
.
Bytes
(),
false
)
if
err
!=
nil
{
return
err
}
...
...
@@ -58,7 +59,8 @@ func testFile(t *testing.T, b1, b2 *bytes.Buffer, filename string) {
}
// exclude files w/ syntax errors (typically test cases)
if
_
,
_
,
err
=
parse
(
filename
,
b1
.
Bytes
(),
false
);
err
!=
nil
{
fset
:=
token
.
NewFileSet
()
if
_
,
_
,
err
=
parse
(
fset
,
filename
,
b1
.
Bytes
(),
false
);
err
!=
nil
{
if
*
verbose
{
fmt
.
Fprintf
(
os
.
Stderr
,
"ignoring %s
\n
"
,
err
)
}
...
...
@@ -66,7 +68,7 @@ func testFile(t *testing.T, b1, b2 *bytes.Buffer, filename string) {
}
// gofmt file
if
err
=
gofmt
(
filename
,
b1
);
err
!=
nil
{
if
err
=
gofmt
(
f
set
,
f
ilename
,
b1
);
err
!=
nil
{
t
.
Errorf
(
"1st gofmt failed: %v"
,
err
)
return
}
...
...
@@ -76,7 +78,7 @@ func testFile(t *testing.T, b1, b2 *bytes.Buffer, filename string) {
b2
.
Write
(
b1
.
Bytes
())
// gofmt result again
if
err
=
gofmt
(
filename
,
b2
);
err
!=
nil
{
if
err
=
gofmt
(
f
set
,
f
ilename
,
b2
);
err
!=
nil
{
t
.
Errorf
(
"2nd gofmt failed: %v"
,
err
)
return
}
...
...
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