Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1251)

Delta Between Two Patch Sets: src/cmd/gofmt/long_test.go

Issue 142360043: code review 142360043: go/format, cmd/gofmt: fix issues with partial Go code w... (Closed)
Left Patch Set: diff -r 48355ec55578b156b58c7df974acf132ab2e9d73 https://code.google.com/p/go Created 9 years, 6 months ago
Right Patch Set: diff -r 8f36a32a9d036f86fb956c8538142eb384bd1a4a https://code.google.com/p/go Created 9 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/cmd/gofmt/gofmt.go ('k') | src/cmd/gofmt/testdata/stdin6.golden » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // This test applies gofmt to all Go files under -root. 5 // This test applies gofmt to all Go files under -root.
6 // To test specific files provide a list of comma-separated 6 // To test specific files provide a list of comma-separated
7 // filenames via the -files flag: go test -files=gofmt.go . 7 // filenames via the -files flag: go test -files=gofmt.go .
8 8
9 package main 9 package main
10 10
(...skipping 14 matching lines...) Expand all
25 25
26 var ( 26 var (
27 root = flag.String("root", runtime.GOROOT(), "test root directory") 27 root = flag.String("root", runtime.GOROOT(), "test root directory")
28 files = flag.String("files", "", "comma-separated list of files to tes t") 28 files = flag.String("files", "", "comma-separated list of files to tes t")
29 ngo = flag.Int("n", runtime.NumCPU(), "number of goroutines used") 29 ngo = flag.Int("n", runtime.NumCPU(), "number of goroutines used")
30 verbose = flag.Bool("verbose", false, "verbose mode") 30 verbose = flag.Bool("verbose", false, "verbose mode")
31 nfiles int // number of files processed 31 nfiles int // number of files processed
32 ) 32 )
33 33
34 func gofmt(fset *token.FileSet, filename string, src *bytes.Buffer) error { 34 func gofmt(fset *token.FileSet, filename string, src *bytes.Buffer) error {
35 » f, _, err := parse(fset, filename, src.Bytes(), false) 35 » f, _, _, err := parse(fset, filename, src.Bytes(), false)
36 if err != nil { 36 if err != nil {
37 return err 37 return err
38 } 38 }
39 ast.SortImports(fset, f) 39 ast.SortImports(fset, f)
40 src.Reset() 40 src.Reset()
41 return (&printer.Config{Mode: printerMode, Tabwidth: tabWidth}).Fprint(s rc, fset, f) 41 return (&printer.Config{Mode: printerMode, Tabwidth: tabWidth}).Fprint(s rc, fset, f)
42 } 42 }
43 43
44 func testFile(t *testing.T, b1, b2 *bytes.Buffer, filename string) { 44 func testFile(t *testing.T, b1, b2 *bytes.Buffer, filename string) {
45 // open file 45 // open file
46 f, err := os.Open(filename) 46 f, err := os.Open(filename)
47 if err != nil { 47 if err != nil {
48 t.Error(err) 48 t.Error(err)
49 return 49 return
50 } 50 }
51 51
52 // read file 52 // read file
53 b1.Reset() 53 b1.Reset()
54 _, err = io.Copy(b1, f) 54 _, err = io.Copy(b1, f)
55 f.Close() 55 f.Close()
56 if err != nil { 56 if err != nil {
57 t.Error(err) 57 t.Error(err)
58 return 58 return
59 } 59 }
60 60
61 // exclude files w/ syntax errors (typically test cases) 61 // exclude files w/ syntax errors (typically test cases)
62 fset := token.NewFileSet() 62 fset := token.NewFileSet()
63 » if _, _, err = parse(fset, filename, b1.Bytes(), false); err != nil { 63 » if _, _, _, err = parse(fset, filename, b1.Bytes(), false); err != nil {
64 if *verbose { 64 if *verbose {
65 fmt.Fprintf(os.Stderr, "ignoring %s\n", err) 65 fmt.Fprintf(os.Stderr, "ignoring %s\n", err)
66 } 66 }
67 return 67 return
68 } 68 }
69 69
70 // gofmt file 70 // gofmt file
71 if err = gofmt(fset, filename, b1); err != nil { 71 if err = gofmt(fset, filename, b1); err != nil {
72 t.Errorf("1st gofmt failed: %v", err) 72 t.Errorf("1st gofmt failed: %v", err)
73 return 73 return
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 // wait for all test goroutines to complete 151 // wait for all test goroutines to complete
152 for i := 0; i < *ngo; i++ { 152 for i := 0; i < *ngo; i++ {
153 <-done 153 <-done
154 } 154 }
155 155
156 if *verbose { 156 if *verbose {
157 fmt.Printf("processed %d files\n", nfiles) 157 fmt.Printf("processed %d files\n", nfiles)
158 } 158 }
159 } 159 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b