1
0
mirror of https://github.com/golang/go synced 2024-11-26 07:07:57 -07:00

- update functionality for printer test

- moved test files from data to testdata
- use tabs instead of spaces for layout

R=rsc
DELTA=129  (67 added, 60 deleted, 2 changed)
OCL=31353
CL=31360
This commit is contained in:
Robert Griesemer 2009-07-08 14:57:51 -07:00
parent e7af3b8e05
commit 2ad7958b7e
5 changed files with 40 additions and 33 deletions

View File

@ -1,25 +0,0 @@
package main
import "fmt" // fmt
const c0 = 0 // zero
const (
c1 = iota; // c1
c2 // c2
)
type T struct {
a, b, c int // 3 fields
}
var x int // x
var ()
func f0() {
const pi = 3.14;
var s1 struct {}
var s2 struct {} = struct {}{};
x := pi
}

View File

@ -6,6 +6,7 @@ package printer
import (
"bytes";
"flag";
"io";
"go/ast";
"go/parser";
@ -18,12 +19,16 @@ import (
const (
dataDir = "testdata";
tabwidth = 4;
padding = 1;
tabchar = ' ';
tabchar = '\t';
)
var update = flag.Bool("update", false, "update golden files");
func lineString(text []byte, i int) string {
i0 := i;
for i < len(text) && text[i] != '\n' {
@ -60,6 +65,14 @@ func check(t *testing.T, source, golden string, exports bool) {
w.Flush();
res := buf.Data();
// update golden files if necessary
if *update {
if err := io.WriteFile(golden, res, 0644); err != nil {
t.Error(err);
}
return;
}
// get golden
gld, err := io.ReadFile(golden);
if err != nil {
@ -89,18 +102,12 @@ func check(t *testing.T, source, golden string, exports bool) {
}
const dataDir = "data";
type entry struct {
source, golden string;
exports bool;
}
// Use gofmt to create/update the respective golden files:
//
// gofmt source.go > golden.go
// gofmt -x source.go > golden.x
//
// Use gotest -update to create/update the respective golden files.
var data = []entry{
entry{ "source1.go", "golden1.go", false },
entry{ "source1.go", "golden1.x", true },

25
src/pkg/go/printer/testdata/golden1.go vendored Normal file
View File

@ -0,0 +1,25 @@
package main
import "fmt" // fmt
const c0 = 0 // zero
const (
c1 = iota; // c1
c2 // c2
)
type T struct {
a, b, c int // 3 fields
}
var x int // x
var ()
func f0() {
const pi = 3.14;
var s1 struct {}
var s2 struct {} = struct {}{};
x := pi
}