Commit 2ad7958b authored by Robert Griesemer's avatar Robert Griesemer

- 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
parent e7af3b8e
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
}
......@@ -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 },
......
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
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment