OLD | NEW |
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 package main | 5 package main |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "io/ioutil" | 9 "io/ioutil" |
10 "path/filepath" | 10 "path/filepath" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 t.Error(err) | 49 t.Error(err) |
50 return | 50 return |
51 } | 51 } |
52 | 52 |
53 expected, err := ioutil.ReadFile(out) | 53 expected, err := ioutil.ReadFile(out) |
54 if err != nil { | 54 if err != nil { |
55 t.Error(err) | 55 t.Error(err) |
56 return | 56 return |
57 } | 57 } |
58 | 58 |
59 » if got := buf.Bytes(); bytes.Compare(got, expected) != 0 { | 59 » if got := buf.Bytes(); !bytes.Equal(got, expected) { |
60 t.Errorf("(gofmt %s) != %s (see %s.gofmt)", in, out, in) | 60 t.Errorf("(gofmt %s) != %s (see %s.gofmt)", in, out, in) |
61 d, err := diff(expected, got) | 61 d, err := diff(expected, got) |
62 if err == nil { | 62 if err == nil { |
63 t.Errorf("%s", d) | 63 t.Errorf("%s", d) |
64 } | 64 } |
65 ioutil.WriteFile(in+".gofmt", got, 0666) | 65 ioutil.WriteFile(in+".gofmt", got, 0666) |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 var tests = []struct { | 69 var tests = []struct { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } | 121 } |
122 | 122 |
123 data, err = ioutil.ReadFile(golden) | 123 data, err = ioutil.ReadFile(golden) |
124 if err != nil { | 124 if err != nil { |
125 t.Error(err) | 125 t.Error(err) |
126 } | 126 } |
127 if bytes.Index(data, []byte("\r")) >= 0 { | 127 if bytes.Index(data, []byte("\r")) >= 0 { |
128 t.Errorf("%s contains CR's", golden) | 128 t.Errorf("%s contains CR's", golden) |
129 } | 129 } |
130 } | 130 } |
OLD | NEW |