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

« back to all changes in this revision

Viewing changes to src/cmd/api/goapi_test.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:
5
5
package main
6
6
 
7
7
import (
 
8
        "bytes"
8
9
        "flag"
9
10
        "fmt"
10
11
        "io/ioutil"
73
74
                }
74
75
        }
75
76
}
 
77
 
 
78
func TestCompareAPI(t *testing.T) {
 
79
        tests := []struct {
 
80
                name                                    string
 
81
                features, required, optional, exception []string
 
82
                ok                                      bool   // want
 
83
                out                                     string // want
 
84
        }{
 
85
                {
 
86
                        name:     "feature added",
 
87
                        features: []string{"A", "B", "C", "D", "E", "F"},
 
88
                        required: []string{"B", "D"},
 
89
                        ok:       true,
 
90
                        out:      "+A\n+C\n+E\n+F\n",
 
91
                },
 
92
                {
 
93
                        name:     "feature removed",
 
94
                        features: []string{"C", "A"},
 
95
                        required: []string{"A", "B", "C"},
 
96
                        ok:       false,
 
97
                        out:      "-B\n",
 
98
                },
 
99
                {
 
100
                        name:     "feature added then removed",
 
101
                        features: []string{"A", "C"},
 
102
                        optional: []string{"B"},
 
103
                        required: []string{"A", "C"},
 
104
                        ok:       true,
 
105
                        out:      "±B\n",
 
106
                },
 
107
                {
 
108
                        name:      "exception removal",
 
109
                        required:  []string{"A", "B", "C"},
 
110
                        features:  []string{"A", "C"},
 
111
                        exception: []string{"B"},
 
112
                        ok:        true,
 
113
                        out:       "~B\n",
 
114
                },
 
115
                {
 
116
                        // http://golang.org/issue/4303
 
117
                        name: "contexts reconverging",
 
118
                        required: []string{
 
119
                                "A",
 
120
                                "pkg syscall (darwin-386), type RawSockaddrInet6 struct",
 
121
                                "pkg syscall (darwin-amd64), type RawSockaddrInet6 struct",
 
122
                        },
 
123
                        features: []string{
 
124
                                "A",
 
125
                                "pkg syscall, type RawSockaddrInet6 struct",
 
126
                        },
 
127
                        ok:  true,
 
128
                        out: "+pkg syscall, type RawSockaddrInet6 struct\n",
 
129
                },
 
130
        }
 
131
        for _, tt := range tests {
 
132
                buf := new(bytes.Buffer)
 
133
                gotok := compareAPI(buf, tt.features, tt.required, tt.optional, tt.exception)
 
134
                if gotok != tt.ok {
 
135
                        t.Errorf("%s: ok = %v; want %v", tt.name, gotok, tt.ok)
 
136
                }
 
137
                if got := buf.String(); got != tt.out {
 
138
                        t.Errorf("%s: output differs\nGOT:\n%s\nWANT:\n%s", tt.name, got, tt.out)
 
139
                }
 
140
        }
 
141
}