]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/syntax: add -skip flag to exclude files from TestStdLib
authorRobert Griesemer <gri@golang.org>
Sat, 29 Feb 2020 06:25:39 +0000 (22:25 -0800)
committerRobert Griesemer <gri@golang.org>
Tue, 3 Mar 2020 01:01:45 +0000 (01:01 +0000)
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>
src/cmd/compile/internal/syntax/parser_test.go

index 673339d667c18075d9dafbcade05e2c2b506853e..81945faee95e2d55ac2dfca3f7ffdd2e5901d552 100644 (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)
                                }