]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: make TestManual work for directories
authorRobert Griesemer <gri@golang.org>
Fri, 30 Apr 2021 17:47:24 +0000 (10:47 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 5 May 2021 15:54:39 +0000 (15:54 +0000)
If no source argument is provided, test testdata/manual.go2
instead.

Remove testdata/check/tmp/go2 in favor of testdata/manual.go2.

These changes affect testing only.

Change-Id: I49aba4d8fc4cc5964911e38c55b4c5d013710aeb
Reviewed-on: https://go-review.googlesource.com/c/go/+/315769
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/check_test.go
src/cmd/compile/internal/types2/testdata/check/tmp.go2 [deleted file]
src/cmd/compile/internal/types2/testdata/manual.go2 [new file with mode: 0644]

index a3a0eea0cc51e0d94192d9b4b52a6cbc1b37d0e8..41b0c54702d8d782ad42d4cf0c129f9540919253 100644 (file)
@@ -96,7 +96,7 @@ func asGoVersion(s string) string {
        return ""
 }
 
-func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uint, manual bool) {
+func testFiles(t *testing.T, filenames []string, colDelta uint, manual bool) {
        if len(filenames) == 0 {
                t.Fatal("no source files")
        }
@@ -114,6 +114,7 @@ func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uin
        }
 
        // if no Go version is given, consider the package name
+       goVersion := *goVersion
        if goVersion == "" {
                goVersion = asGoVersion(pkgName)
        }
@@ -239,35 +240,54 @@ func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uin
        }
 }
 
-// TestManual is for manual testing of input files, provided as a list
-// of arguments after the test arguments (and a separating "--"). For
-// instance, to check the files foo.go and bar.go, use:
+// TestManual is for manual testing of a package - either provided
+// as a list of filenames belonging to the package, or a directory
+// name containing the package files - after the test arguments
+// (and a separating "--"). For instance, to test the package made
+// of the files foo.go and bar.go, use:
 //
 //     go test -run Manual -- foo.go bar.go
 //
-// Provide the -verify flag to verify errors against ERROR comments in
-// the input files rather than having a list of errors reported.
-// The accepted Go language version can be controlled with the -lang flag.
+// If no source arguments are provided, the file testdata/manual.go2
+// is used instead.
+// Provide the -verify flag to verify errors against ERROR comments
+// in the input files rather than having a list of errors reported.
+// The accepted Go language version can be controlled with the -lang
+// flag.
 func TestManual(t *testing.T) {
+       testenv.MustHaveGoBuild(t)
+
        filenames := flag.Args()
        if len(filenames) == 0 {
-               return
+               filenames = []string{filepath.FromSlash("testdata/manual.go2")}
        }
-       testenv.MustHaveGoBuild(t)
+
+       info, err := os.Stat(filenames[0])
+       if err != nil {
+               t.Fatalf("TestManual: %v", err)
+       }
+
        DefPredeclaredTestFuncs()
-       checkFiles(t, filenames, *goVersion, 0, true)
+       if info.IsDir() {
+               if len(filenames) > 1 {
+                       t.Fatal("TestManual: must have only one directory argument")
+               }
+               testDir(t, filenames[0], 0, true)
+       } else {
+               testFiles(t, filenames, 0, true)
+       }
 }
 
 // TODO(gri) go/types has extra TestLongConstants and TestIndexRepresentability tests
 
-func TestCheck(t *testing.T)     { DefPredeclaredTestFuncs(); testDir(t, "check", 75) } // TODO(gri) narrow column tolerance
-func TestExamples(t *testing.T)  { testDir(t, "examples", 0) }
-func TestFixedbugs(t *testing.T) { testDir(t, "fixedbugs", 0) }
+func TestCheck(t *testing.T)     { DefPredeclaredTestFuncs(); testDirFiles(t, "testdata/check", 75, false) } // TODO(gri) narrow column tolerance
+func TestExamples(t *testing.T)  { testDirFiles(t, "testdata/examples", 0, false) }
+func TestFixedbugs(t *testing.T) { testDirFiles(t, "testdata/fixedbugs", 0, false) }
 
-func testDir(t *testing.T, dir string, colDelta uint) {
+func testDirFiles(t *testing.T, dir string, colDelta uint, manual bool) {
        testenv.MustHaveGoBuild(t)
+       dir = filepath.FromSlash(dir)
 
-       dir = filepath.Join("testdata", dir)
        fis, err := os.ReadDir(dir)
        if err != nil {
                t.Error(err)
@@ -277,23 +297,30 @@ func testDir(t *testing.T, dir string, colDelta uint) {
        for _, fi := range fis {
                path := filepath.Join(dir, fi.Name())
 
-               // if fi is a directory, its files make up a single package
-               var filenames []string
+               // If fi is a directory, its files make up a single package.
                if fi.IsDir() {
-                       fis, err := os.ReadDir(path)
-                       if err != nil {
-                               t.Error(err)
-                               continue
-                       }
-                       for _, fi := range fis {
-                               filenames = append(filenames, filepath.Join(path, fi.Name()))
-                       }
+                       testDir(t, path, colDelta, manual)
                } else {
-                       filenames = []string{path}
+                       t.Run(filepath.Base(path), func(t *testing.T) {
+                               testFiles(t, []string{path}, colDelta, manual)
+                       })
                }
+       }
+}
+
+func testDir(t *testing.T, dir string, colDelta uint, manual bool) {
+       fis, err := os.ReadDir(dir)
+       if err != nil {
+               t.Error(err)
+               return
+       }
 
-               t.Run(filepath.Base(path), func(t *testing.T) {
-                       checkFiles(t, filenames, *goVersion, colDelta, false)
-               })
+       var filenames []string
+       for _, fi := range fis {
+               filenames = append(filenames, filepath.Join(dir, fi.Name()))
        }
+
+       t.Run(filepath.Base(dir), func(t *testing.T) {
+               testFiles(t, filenames, colDelta, manual)
+       })
 }
diff --git a/src/cmd/compile/internal/types2/testdata/check/tmp.go2 b/src/cmd/compile/internal/types2/testdata/check/tmp.go2
deleted file mode 100644 (file)
index dae78ca..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2020 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.
-
-// This file is meant as "dumping ground" for debugging code.
-
-package p
-
-// fun test case
-type C[P interface{m()}] P
-
-func (r C[P]) m() { r.m() }
-
-func f[T interface{m(); n()}](x T) {
-       y := C[T](x)
-       y.m()
-}
diff --git a/src/cmd/compile/internal/types2/testdata/manual.go2 b/src/cmd/compile/internal/types2/testdata/manual.go2
new file mode 100644 (file)
index 0000000..efe13cf
--- /dev/null
@@ -0,0 +1,8 @@
+// Copyright 2021 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.
+
+// This file is tested when running "go test -run Manual"
+// without source arguments. Use for one-off debugging.
+
+package p