func TestRewrite(t *testing.T) {
	match, err := filepath.Glob("testdata/*.in")
	if err != nil {
		t.Fatal(err)
	}
	for _, in := range match {
		out := in  
		if strings.HasSuffix(in, ".in") {
			out = in[:len(in)-len(".in")] + ".golden"
		}
		runTest(t, in, out)
		if in != out {
			runTest(t, out, out)
		}
	}
}
TestRewrite processes testdata/*.input files and compares them to the
corresponding testdata/*.golden files. The gofmt flags used to process
a file must be provided via a comment of the form

//gofmt flags

in the processed file within the first 20 lines, if any.
package asmfmt
import (
	"bytes"
	"flag"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
	"testing"
)
var update = flag.Bool("update", false, "update .golden files")
func TestMain(m *testing.M) {
	flag.Parse()
	os.Exit(m.Run())
}
func runTest(t *testing.T, in, out string) {
	f, err := os.Open(in)
	if err != nil {
		t.Error(err)
		return
	}
	defer f.Close()
	got, err := Format(f)
	if err != nil {
		t.Error(in, "-", err)
		return
	}
	expected, err := ioutil.ReadFile(out)
	if err != nil && !*update {
		t.Error(out, "-", err)
		return
	}
	expected = []byte(strings.Replace(string(expected), "\r\n", "\n", -1))
	if !bytes.Equal(got, expected) {
		if *update {
			if in != out {
				if err := ioutil.WriteFile(out, got, 0666); err != nil {
					t.Error(err)
				}
				return
			}
			t.Errorf("WARNING: -update did not rewrite input file %s", in)
		}
		t.Errorf("(gofmt %s) != %s (see %s.asmfmt)", in, out, in)
		d, err := diff(expected, got)
		if err == nil {
			t.Errorf("%s", d)
		}
		if err := ioutil.WriteFile(in+".asmfmt", got, 0666); err != nil {
			t.Error(err)
		}
	}
}