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 ( ...@@ -11,6 +11,7 @@ import (
"fmt" "fmt"
"go/scanner" "go/scanner"
"go/token" "go/token"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
...@@ -76,34 +77,46 @@ func main() { ...@@ -76,34 +77,46 @@ func main() {
flag.Parse() flag.Parse()
var ( var (
filename string name string
src []byte r io.Reader
err error
) )
switch flag.NArg() { switch flag.NArg() {
case 0: case 0:
filename = "<stdin>" name, r = "<stdin>", os.Stdin
src, err = ioutil.ReadAll(os.Stdin)
case 1: case 1:
filename = flag.Arg(0) name = flag.Arg(0)
src, err = ioutil.ReadFile(filename)
default: default:
usage() usage()
} }
if err != nil {
if err := verify(name, *start, r); err != nil {
report(err) report(err)
} }
}
if filepath.Ext(filename) == ".html" || bytes.Index(src, open) >= 0 { func verify(name, start string, r io.Reader) error {
src = extractEBNF(src) 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 { if err != nil {
report(err) return err
} }
if err = ebnf.Verify(grammar, *start); err != nil { if filepath.Ext(name) == ".html" || bytes.Index(src, open) >= 0 {
report(err) 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