cmd/compile/internal/syntax: add -skip flag to exclude files from TestStdLib

TestStdLib reports parsed lines and lines/s information. To make
it easier to compare apples to apples when making changes in the
std lib, a regular expression provided via the -skip flag filters
files we don't want to process.

Change-Id: I27d9c32032eac4e78581205892e4f26947c91bd9
Reviewed-on: https://go-review.googlesource.com/c/go/+/221600
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
Robert Griesemer 2020-02-28 22:25:39 -08:00
parent 9828c43288
commit 2001685ec0

View file

@ -10,6 +10,7 @@ import (
"fmt"
"io/ioutil"
"path/filepath"
"regexp"
"runtime"
"strings"
"sync"
@ -17,9 +18,12 @@ import (
"time"
)
var fast = flag.Bool("fast", false, "parse package files in parallel")
var src_ = flag.String("src", "parser.go", "source file to parse")
var verify = flag.Bool("verify", false, "verify idempotent printing")
var (
fast = flag.Bool("fast", false, "parse package files in parallel")
verify = flag.Bool("verify", false, "verify idempotent printing")
src_ = flag.String("src", "parser.go", "source file to parse")
skip = flag.String("skip", "", "files matching this regular expression are skipped by TestStdLib")
)
func TestParse(t *testing.T) {
ParseFile(*src_, func(err error) { t.Error(err) }, nil, 0)
@ -30,6 +34,15 @@ func TestStdLib(t *testing.T) {
t.Skip("skipping test in short mode")
}
var skipRx *regexp.Regexp
if *skip != "" {
var err error
skipRx, err = regexp.Compile(*skip)
if err != nil {
t.Fatalf("invalid argument for -skip (%v)", err)
}
}
var m1 runtime.MemStats
runtime.ReadMemStats(&m1)
start := time.Now()
@ -46,6 +59,12 @@ func TestStdLib(t *testing.T) {
runtime.GOROOT(),
} {
walkDirs(t, dir, func(filename string) {
if skipRx != nil && skipRx.MatchString(filename) {
// Always report skipped files since regexp
// typos can lead to surprising results.
fmt.Printf("skipping %s\n", filename)
return
}
if debug {
fmt.Printf("parsing %s\n", filename)
}