~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to test/fixedbugs/issue4562.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// run
 
2
 
 
3
// Copyright 2012 The Go Authors.  All rights reserved.
 
4
// Use of this source code is governed by a BSD-style
 
5
// license that can be found in the LICENSE file.
 
6
 
 
7
package main
 
8
 
 
9
import (
 
10
        "fmt"
 
11
        "runtime"
 
12
        "strings"
 
13
)
 
14
 
 
15
type T struct {
 
16
        val int
 
17
}
 
18
 
 
19
func main() {
 
20
        defer expectError(22)
 
21
        var pT *T
 
22
        switch pT.val { // error should be here - line 22
 
23
        case 0:
 
24
                fmt.Println("0")
 
25
        case 1: // used to show up here instead
 
26
                fmt.Println("1")
 
27
        case 2:
 
28
                fmt.Println("2")
 
29
        }
 
30
        fmt.Println("finished")
 
31
}
 
32
 
 
33
func expectError(expectLine int) {
 
34
        if recover() == nil {
 
35
                panic("did not crash")
 
36
        }
 
37
        for i := 1;; i++ {
 
38
                _, file, line, ok := runtime.Caller(i)
 
39
                if !ok {
 
40
                        panic("cannot find issue4562.go on stack")
 
41
                }
 
42
                if strings.HasSuffix(file, "issue4562.go") {
 
43
                        if line != expectLine {
 
44
                                panic(fmt.Sprintf("crashed at line %d, wanted line %d", line, expectLine))
 
45
                        }
 
46
                        break
 
47
                }
 
48
        }
 
49
}