Commit 4417bc37 authored by Russ Cox's avatar Russ Cox

exp/ebnflint: test spec during 'go test'

This avoids the need for a custom Makefile.

R=gri
CC=golang-dev
https://golang.org/cl/5575045
parent 1cfae8bc
......@@ -11,6 +11,7 @@ import (
"fmt"
"go/scanner"
"go/token"
"io"
"io/ioutil"
"os"
"path/filepath"
......@@ -76,34 +77,46 @@ func main() {
flag.Parse()
var (
filename string
src []byte
err error
name string
r io.Reader
)
switch flag.NArg() {
case 0:
filename = "<stdin>"
src, err = ioutil.ReadAll(os.Stdin)
name, r = "<stdin>", os.Stdin
case 1:
filename = flag.Arg(0)
src, err = ioutil.ReadFile(filename)
name = flag.Arg(0)
default:
usage()
}
if err != nil {
if err := verify(name, *start, r); err != nil {
report(err)
}
}
if filepath.Ext(filename) == ".html" || bytes.Index(src, open) >= 0 {
src = extractEBNF(src)
func verify(name, start string, r io.Reader) error {
if r == nil {
f, err := os.Open(name)
if err != nil {
return err
}
defer f.Close()
r = f
}
grammar, err := ebnf.Parse(filename, bytes.NewBuffer(src))
src, err := ioutil.ReadAll(r)
if err != nil {
report(err)
return err
}
if err = ebnf.Verify(grammar, *start); err != nil {
report(err)
if filepath.Ext(name) == ".html" || bytes.Index(src, open) >= 0 {
src = extractEBNF(src)
}
grammar, err := ebnf.Parse(name, bytes.NewBuffer(src))
if err != nil {
return err
}
return ebnf.Verify(grammar, start)
}
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"runtime"
"testing"
)
func TestSpec(t *testing.T) {
if err := verify(runtime.GOROOT()+"/doc/go_spec.html", "SourceFile", nil); err != nil {
t.Fatal(err)
}
}
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