Skip to content

Commit

Permalink
cmd/compile/internal/syntax: add -skip flag to exclude files from Tes…
Browse files Browse the repository at this point in the history
…tStdLib

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>
  • Loading branch information
griesemer committed Mar 3, 2020
1 parent 9828c43 commit 2001685
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/cmd/compile/internal/syntax/parser_test.go
Expand Up @@ -10,16 +10,20 @@ import (
"fmt"
"io/ioutil"
"path/filepath"
"regexp"
"runtime"
"strings"
"sync"
"testing"
"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)
Expand All @@ -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()
Expand All @@ -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)
}
Expand Down

0 comments on commit 2001685

Please sign in to comment.