]> Cypherpunks.ru repositories - gostls13.git/commitdiff
errchk: allow multiple patterns
authorRuss Cox <rsc@golang.org>
Tue, 16 Aug 2011 15:14:26 +0000 (11:14 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 16 Aug 2011 15:14:26 +0000 (11:14 -0400)
// ERROR "pattern1" "pattern2"

means that there has to be one or more
lines matching pattern1 and then excluding
those, there have to be one or more lines
matching pattern2.  So if you expect two
different error messages from a particular
line, writing two separate patterns checks
that both errors are produced.

Also, errchk now flags lines that produce
more errors than expected.  Before, as long as
at least one error matched the pattern, all the
others were ignored.

Revise tests to expect or silence these
additional errors.

R=lvd, r, iant
CC=golang-dev
https://golang.org/cl/4869044

16 files changed:
test/declbad.go
test/errchk
test/fixedbugs/bug205.go
test/fixedbugs/bug228.go
test/fixedbugs/bug229.go
test/fixedbugs/bug231.go
test/fixedbugs/bug297.go
test/fixedbugs/bug351.go
test/fixedbugs/bug359.go
test/import1.go
test/initializerr.go
test/interface/explicit.go
test/interface/pointer.go
test/nul1.go
test/rename1.go
test/shift1.go

index 5e5e145011040dc7f974012b20e4db67a378c133..09f1dfb576fe2334c1d06c8af3c6f4358c3c18b9 100644 (file)
@@ -40,7 +40,7 @@ func main() {
        {
                // single redeclaration
                i, f, s := f3()
-               i := f1() // ERROR "redeclared|no new|incompatible"
+               i := 1 // ERROR "redeclared|no new|incompatible"
                _, _, _ = i, f, s
        }
        // double redeclaration
index 8fdf77a30a35e8b6d5bb9004abae76854ed27e9f..6b00570bdec9f150872352b718ff710120646f51 100755 (executable)
@@ -88,41 +88,46 @@ sub chk {
                $line++;
                next if $src =~ m|////|;  # double comment disables ERROR
                next unless $src =~ m|// (GC_)?ERROR (.*)|;
-               $regexp = $2;
-               if($regexp !~ /^"([^"]*)"/) {
+               my $all = $2;
+               if($all !~ /^"([^"]*)"/) {
                        print STDERR "$file:$line: malformed regexp\n";
                        next;
                }
-               $regexp = $1;
-               
-               # Turn relative line number in message into absolute line number.
-               if($regexp =~ /LINE(([+-])([0-9]+))?/) {
-                       my $n = $line;
-                       if(defined($1)) {
-                               if($2 eq "+") {
-                                       $n += int($3);
-                               } else {
-                                       $n -= int($3);
-                               }
-                       }
-                       $regexp = "$`$file:$n$'";
-               }
-
                @errmsg = grep { /$file:$line[:[]/ } @out;
                @out = grep { !/$file:$line[:[]/ } @out;
                if(@errmsg == 0) {
                        bug();
-                       print STDERR "errchk: $file:$line: missing expected error: '$regexp'\n";
+                       print STDERR "errchk: $file:$line: missing expected error: '$all'\n";
                        next;
                }
-               @match = grep { /$regexp/ } @errmsg;
-               if(@match == 0) {
+               foreach my $regexp ($all =~ /"([^"]*)"/g) {
+                       # Turn relative line number in message into absolute line number.
+                       if($regexp =~ /LINE(([+-])([0-9]+))?/) {
+                               my $n = $line;
+                               if(defined($1)) {
+                                       if($2 eq "+") {
+                                               $n += int($3);
+                                       } else {
+                                               $n -= int($3);
+                                       }
+                               }
+                               $regexp = "$`$file:$n$'";
+                       }
+       
+                       @match = grep { /$regexp/ } @errmsg;
+                       if(@match == 0) {
+                               bug();
+                               print STDERR "errchk: $file:$line: error messages do not match '$regexp'\n";
+                               next;
+                       }
+                       @errmsg = grep { !/$regexp/ } @errmsg;
+               }
+               if(@errmsg != 0) {
                        bug();
-                       print STDERR "errchk: $file:$line: error message does not match '$regexp'\n";
+                       print STDERR "errchk: $file:$line: unmatched error messages:\n";
                        foreach my $l (@errmsg) {
                                print STDERR "> $l";
                        }
-                       next;
                }
        }
 }
index 4262ec10dce26b9565aee69ca160fa2c90b3ce57..e12be72f925b7aa93241998caa824cdda6ee3aa9 100644 (file)
@@ -12,7 +12,7 @@ var m map[string]int;
 
 func main() {
        println(t["hi"]);       // ERROR "integer"
-       println(s["hi"]);       // ERROR "integer"
+       println(s["hi"]);       // ERROR "integer" "to type uint"
        println(m[0]);  // ERROR "map index"
 }
 
index 81bc908569ef4f47a2686572ced52d7c0e0cbd71..da335dbc05a942fcf3ee8cfdb503479262d0a207 100644 (file)
@@ -8,7 +8,7 @@ package main
 
 func f(x int, y ...int)        // ok
 
-func g(x int, y float) (...)   // ERROR "[.][.][.]"
+func g(x int, y float) (...)   // ERROR "[.][.][.]" "final argument"
 
 func h(x, y ...int)            // ERROR "[.][.][.]"
 
index fe0f0d8c7552cd366a2cbd833a254efb43288000..6c9de9ba93eb85ba7cdbc6ee9f71c3962f9e24e2 100644 (file)
@@ -16,5 +16,5 @@ func main() {
 
        t.ch = nil      // ERROR "unexported"
        
-       println(testing.anyLowercaseName("asdf"))       // ERROR "unexported"
+       println(testing.anyLowercaseName("asdf"))       // ERROR "unexported" "undefined: testing.anyLowercaseName"
 }
index 91996d313c8dd3a8c0283fb44c59c8bd065cca1c..9500e582bbeb3841aa1b85f72d6c69717780c936 100644 (file)
@@ -17,6 +17,6 @@ func main() {
        var i I
        
        i = m
-       i = t   // ERROR "not a method|has no methods"
+       i = t   // ERROR "not a method|has no methods" "does not implement I"
        _ = i
 }
index ba029427f2447589b6c5c3d975d3ac60c768b331..8767cdfea5459476f6075be3a57c5e660d9ddfd5 100644 (file)
@@ -11,5 +11,5 @@ package main
 type ByteSize float64
 const (
        _ = iota;   // ignore first value by assigning to blank identifier
-       KB ByteSize = 1<<(10*X) // ERROR "undefined"
+       KB ByteSize = 1<<(10*X) // ERROR "undefined" "as type ByteSize"
 )
index c33e28271ef590b1ba7c1b9bcfa4548cd756dd8b..2f631bbbbc5a98570d4ac31f297058891aca63d4 100644 (file)
@@ -6,6 +6,8 @@
 
 package main
 
+var x int
+
 func main() {
        (x) := 0  // ERROR "non-name [(]x[)]"
 }
index 6ced608bcccf22b5fe0f35a82402d22fb5869013..7f34672f1d9f12ce1ae7f3556de635432be90214 100644 (file)
@@ -16,7 +16,7 @@ type Painting struct {
 }
 
 func (p Painting) Foo() {
-       for e := p.fragments; e.Front() != nil; e = e.Next() {  // ERROR "unexported field"
+       for e := p.fragments; e.Front() != nil; {  // ERROR "unexported field"
        }
 }
 
index 8bb2a94a24fd7f13a5ba8a41707d09765f4c2df0..ebd704ef9959e21e690baa52f59bccf7936a5570 100644 (file)
@@ -9,9 +9,9 @@
 package main
 
 import "bufio" // GCCGO_ERROR "previous|not used"
-import bufio "os"      // ERROR "redeclared|redefinition|incompatible"
+import bufio "os"      // ERROR "redeclared|redefinition|incompatible" "imported and not used"
 
 import (
        "fmt"   // GCCGO_ERROR "previous|not used"
-       fmt "math"      // ERROR "redeclared|redefinition|incompatible"
+       fmt "math"      // ERROR "redeclared|redefinition|incompatible" "imported and not used"
 )
index 37f8a602db68bcc81d1e5a9d40a98750596df856..e7f8b0e92fe30a83397f45129a2da036856fe600 100644 (file)
@@ -17,7 +17,7 @@ type T struct {
 var x = 1
 var a1 = S { 0, X: 1 } // ERROR "mixture|undefined"
 var a2 = S { Y: 3, Z: 2, Y: 3 } // ERROR "duplicate"
-var a3 = T { 1, 2, 3, 4, 5, 6 }        // ERROR "convert|too many"
+var a3 = T { S{}, 2, 3, 4, 5, 6 }      // ERROR "convert|too many"
 var a4 = [5]byte{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }      // ERROR "index|too many"
 var a5 = []byte { x: 2 }       // ERROR "index"
 
index b6a582fffba8700287add0f3f9bf01f3c868ced2..daae59b36182dafea0b136ad14539925b1024c4f 100644 (file)
@@ -48,7 +48,7 @@ func main() {
        i2 = I2(i) // ERROR "invalid|missing N method"
 
        e = E(t) // ok
-       t = T(e) // ERROR "need explicit|need type assertion|incompatible"
+       t = T(e) // ERROR "need explicit|need type assertion|incompatible" "as type [*]T"
 }
 
 type M interface {
index 076469c8dee2a63167de2fc7c4617d0892f8b71f..fe4d8e3ef9182879a3ddadbe4c2d4380d3d93e8a 100644 (file)
@@ -33,5 +33,5 @@ func main() {
        print("call addinst\n")
        var x Inst = AddInst(new(Start)) // ERROR "pointer to interface"
        print("return from  addinst\n")
-       var x *Inst = new(Start)  // ERROR "pointer to interface"
+       var y *Inst = new(Start)  // ERROR "pointer to interface"
 }
index 9cf51125bcc6f11de4d8cb67abbb8af71a719e3f..142d4deb1f4d3e9bcc8bbf7000fb37689a60f9f3 100644 (file)
@@ -39,7 +39,7 @@ var y = ` + "`in raw string \x00 foo`" + `  // ERROR "NUL"
 
 /* in other comment ` + "\x00" + ` */ // ERROR "NUL"
 
-/* in source code */ ` + "\x00" + `// ERROR "NUL"
+/* in source code */ ` + "\x00" + `// ERROR "NUL" "illegal character"
 
 var xx = "in string ` + "\xc2\xff" + `" // ERROR "UTF-8"
 
@@ -50,9 +50,9 @@ var yy = ` + "`in raw string \xff foo`" + `  // ERROR "UTF-8"
 /* in other comment ` + "\xe0\x00\x00" + ` */ // ERROR "UTF-8|NUL"
 
 /* in variable name */
-var z` + "\xc1\x81" + ` int // ERROR "UTF-8"
+var z` + "\xc1\x81" + ` int // ERROR "UTF-8" "invalid identifier character"
 
-/* in source code */ ` + "\xc2A" + `// ERROR "UTF-8"
+/* in source code */ ` + "var \xc2A int" + `// ERROR "UTF-8" "invalid identifier character"
 
 `)
 }
index f239999986078934d4b85195f56249cd636ab745..3e78bfca0bc505bd70acf826295292c4a2ab41bc 100644 (file)
@@ -10,7 +10,7 @@ func main() {
        var n byte       // ERROR "not a type|expected type"
        var y = float(0) // ERROR "cannot call|expected function"
        const (
-               a = 1 + iota // ERROR "string|incompatible types"
+               a = 1 + iota // ERROR "string|incompatible types" "convert iota"
        )
 
 }
index 8fa48a03cf1dfbe05e8ebe499dbc4b0262f8d6b1..6a8e26e5e616742a0999c61970a78f198d803379 100644 (file)
@@ -16,13 +16,13 @@ func h(x float64) int     { return 0 }
 var (
        s uint    = 33
        u         = 1.0 << s // ERROR "invalid operation"
-       v float32 = 1 << s   // ERROR "invalid operation"
+       v float32 = 1 << s   // ERROR "invalid operation" "as type float32"
 )
 
 // non-constant shift expressions
 var (
-       e1       = g(2.0 << s) // ERROR "invalid operation"
-       f1       = h(2 << s)   // ERROR "invalid operation"
+       e1       = g(2.0 << s) // ERROR "invalid operation" "as type interface"
+       f1       = h(2 << s)   // ERROR "invalid operation" "as type float64"
        g1 int64 = 1.1 << s    // ERROR "truncated"
 )