Bumping k8s dependencies to 1.13

This commit is contained in:
Cheng Xing
2018-11-16 14:08:25 -08:00
parent 305407125c
commit b4c0b68ec7
8002 changed files with 884099 additions and 276228 deletions

149
vendor/golang.org/x/tools/go/expect/expect.go generated vendored Normal file
View File

@@ -0,0 +1,149 @@
// Copyright 2018 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.
/*
Package expect provides support for interpreting structured comments in Go
source code as test expectations.
This is primarily intended for writing tests of things that process Go source
files, although it does not directly depend on the testing package.
Collect notes with the Extract or Parse functions, and use the
MatchBefore function to find matches within the lines the comments were on.
The interpretation of the notes depends on the application.
For example, the test suite for a static checking tool might
use a @diag note to indicate an expected diagnostic:
fmt.Printf("%s", 1) //@ diag("%s wants a string, got int")
By contrast, the test suite for a source code navigation tool
might use notes to indicate the positions of features of
interest, the actions to be performed by the test,
and their expected outcomes:
var x = 1 //@ x_decl
...
print(x) //@ definition("x", x_decl)
print(x) //@ typeof("x", "int")
Note comment syntax
Note comments always start with the special marker @, which must be the
very first character after the comment opening pair, so //@ or /*@ with no
spaces.
This is followed by a comma separated list of notes.
A note always starts with an identifier, which is optionally followed by an
argument list. The argument list is surrounded with parentheses and contains a
comma-separated list of arguments.
The empty parameter list and the missing parameter list are distinguishable if
needed; they result in a nil or an empty list in the Args parameter respectively.
Arguments are either identifiers or literals.
The literals supported are the basic value literals, of string, float, integer
true, false or nil. All the literals match the standard go conventions, with
all bases of integers, and both quote and backtick strings.
There is one extra literal type, which is a string literal preceded by the
identifier "re" which is compiled to a regular expression.
*/
package expect
import (
"bytes"
"fmt"
"go/token"
"regexp"
)
// Note is a parsed note from an expect comment.
// It knows the position of the start of the comment, and the name and
// arguments that make up the note.
type Note struct {
Pos token.Pos // The position at which the note identifier appears
Name string // the name associated with the note
Args []interface{} // the arguments for the note
}
// ReadFile is the type of a function that can provide file contents for a
// given filename.
// This is used in MatchBefore to look up the content of the file in order to
// find the line to match the pattern against.
type ReadFile func(filename string) ([]byte, error)
// MatchBefore attempts to match a pattern in the line before the supplied pos.
// It uses the FileSet and the ReadFile to work out the contents of the line
// that end is part of, and then matches the pattern against the content of the
// start of that line up to the supplied position.
// The pattern may be either a simple string, []byte or a *regexp.Regexp.
// MatchBefore returns the range of the line that matched the pattern, and
// invalid positions if there was no match, or an error if the line could not be
// found.
func MatchBefore(fset *token.FileSet, readFile ReadFile, end token.Pos, pattern interface{}) (token.Pos, token.Pos, error) {
f := fset.File(end)
content, err := readFile(f.Name())
if err != nil {
return token.NoPos, token.NoPos, fmt.Errorf("invalid file: %v", err)
}
position := f.Position(end)
startOffset := f.Offset(lineStart(f, position.Line))
endOffset := f.Offset(end)
line := content[startOffset:endOffset]
matchStart, matchEnd := -1, -1
switch pattern := pattern.(type) {
case string:
bytePattern := []byte(pattern)
matchStart = bytes.Index(line, bytePattern)
if matchStart >= 0 {
matchEnd = matchStart + len(bytePattern)
}
case []byte:
matchStart = bytes.Index(line, pattern)
if matchStart >= 0 {
matchEnd = matchStart + len(pattern)
}
case *regexp.Regexp:
match := pattern.FindIndex(line)
if len(match) > 0 {
matchStart = match[0]
matchEnd = match[1]
}
}
if matchStart < 0 {
return token.NoPos, token.NoPos, nil
}
return f.Pos(startOffset + matchStart), f.Pos(startOffset + matchEnd), nil
}
// this functionality was borrowed from the analysisutil package
func lineStart(f *token.File, line int) token.Pos {
// Use binary search to find the start offset of this line.
//
// TODO(adonovan): eventually replace this function with the
// simpler and more efficient (*go/token.File).LineStart, added
// in go1.12.
min := 0 // inclusive
max := f.Size() // exclusive
for {
offset := (min + max) / 2
pos := f.Pos(offset)
posn := f.Position(pos)
if posn.Line == line {
return pos - (token.Pos(posn.Column) - 1)
}
if min+1 >= max {
return token.NoPos
}
if posn.Line < line {
min = offset
} else {
max = offset
}
}
}

135
vendor/golang.org/x/tools/go/expect/expect_test.go generated vendored Normal file
View File

@@ -0,0 +1,135 @@
// Copyright 2018 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.
package expect_test
import (
"bytes"
"go/token"
"io/ioutil"
"testing"
"golang.org/x/tools/go/expect"
)
func TestMarker(t *testing.T) {
const filename = "testdata/test.go"
content, err := ioutil.ReadFile(filename)
if err != nil {
t.Fatal(err)
}
const expectNotes = 11
expectMarkers := map[string]string{
"αSimpleMarker": "α",
"OffsetMarker": "β",
"RegexMarker": "γ",
"εMultiple": "ε",
"ζMarkers": "ζ",
"ηBlockMarker": "η",
"Declared": "η",
"Comment": "ι",
"NonIdentifier": "+",
}
expectChecks := map[string][]interface{}{
"αSimpleMarker": nil,
"StringAndInt": []interface{}{"Number %d", int64(12)},
"Bool": []interface{}{true},
}
readFile := func(string) ([]byte, error) { return content, nil }
markers := make(map[string]token.Pos)
for name, tok := range expectMarkers {
offset := bytes.Index(content, []byte(tok))
markers[name] = token.Pos(offset + 1)
end := bytes.Index(content[offset+1:], []byte(tok))
if end > 0 {
markers[name+"@"] = token.Pos(offset + end + 2)
}
}
fset := token.NewFileSet()
notes, err := expect.Parse(fset, filename, nil)
if err != nil {
t.Fatalf("Failed to extract notes: %v", err)
}
if len(notes) != expectNotes {
t.Errorf("Expected %v notes, got %v", expectNotes, len(notes))
}
for _, n := range notes {
switch {
case n.Args == nil:
// A //@foo note associates the name foo with the position of the
// first match of "foo" on the current line.
checkMarker(t, fset, readFile, markers, n.Pos, n.Name, n.Name)
case n.Name == "mark":
// A //@mark(name, "pattern") note associates the specified name
// with the position on the first match of pattern on the current line.
if len(n.Args) != 2 {
t.Errorf("%v: expected 2 args to mark, got %v", fset.Position(n.Pos), len(n.Args))
continue
}
ident, ok := n.Args[0].(expect.Identifier)
if !ok {
t.Errorf("%v: identifier, got %T", fset.Position(n.Pos), n.Args[0])
continue
}
checkMarker(t, fset, readFile, markers, n.Pos, string(ident), n.Args[1])
case n.Name == "check":
// A //@check(args, ...) note specifies some hypothetical action to
// be taken by the test driver and its expected outcome.
// In this test, the action is to compare the arguments
// against expectChecks.
if len(n.Args) < 1 {
t.Errorf("%v: expected 1 args to check, got %v", fset.Position(n.Pos), len(n.Args))
continue
}
ident, ok := n.Args[0].(expect.Identifier)
if !ok {
t.Errorf("%v: identifier, got %T", fset.Position(n.Pos), n.Args[0])
continue
}
args, ok := expectChecks[string(ident)]
if !ok {
t.Errorf("%v: unexpected check %v", fset.Position(n.Pos), ident)
continue
}
if len(n.Args) != len(args)+1 {
t.Errorf("%v: expected %v args to check, got %v", fset.Position(n.Pos), len(args)+1, len(n.Args))
continue
}
for i, got := range n.Args[1:] {
if args[i] != got {
t.Errorf("%v: arg %d expected %v, got %v", fset.Position(n.Pos), i, args[i], got)
}
}
default:
t.Errorf("Unexpected note %v at %v", n.Name, fset.Position(n.Pos))
}
}
}
func checkMarker(t *testing.T, fset *token.FileSet, readFile expect.ReadFile, markers map[string]token.Pos, pos token.Pos, name string, pattern interface{}) {
start, end, err := expect.MatchBefore(fset, readFile, pos, pattern)
if err != nil {
t.Errorf("%v: MatchBefore failed: %v", fset.Position(pos), err)
return
}
if start == token.NoPos {
t.Errorf("%v: Pattern %v did not match", fset.Position(pos), pattern)
return
}
expectStart, ok := markers[name]
if !ok {
t.Errorf("%v: unexpected marker %v", fset.Position(pos), name)
return
}
if start != expectStart {
t.Errorf("%v: Expected %v got %v", fset.Position(pos), fset.Position(expectStart), fset.Position(start))
}
if expectEnd, ok := markers[name+"@"]; ok && end != expectEnd {
t.Errorf("%v: Expected end %v got %v", fset.Position(pos), fset.Position(expectEnd), fset.Position(end))
}
}

221
vendor/golang.org/x/tools/go/expect/extract.go generated vendored Normal file
View File

@@ -0,0 +1,221 @@
// Copyright 2018 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.
package expect
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"regexp"
"strconv"
"strings"
"text/scanner"
)
const (
commentStart = "@"
)
// Identifier is the type for an identifier in an Note argument list.
type Identifier string
// Parse collects all the notes present in a file.
// If content is nil, the filename specified is read and parsed, otherwise the
// content is used and the filename is used for positions and error messages.
// Each comment whose text starts with @ is parsed as a comma-separated
// sequence of notes.
// See the package documentation for details about the syntax of those
// notes.
func Parse(fset *token.FileSet, filename string, content []byte) ([]*Note, error) {
var src interface{}
if content != nil {
src = content
}
// TODO: We should write this in terms of the scanner.
// there are ways you can break the parser such that it will not add all the
// comments to the ast, which may result in files where the tests are silently
// not run.
file, err := parser.ParseFile(fset, filename, src, parser.ParseComments)
if file == nil {
return nil, err
}
return Extract(fset, file)
}
// Extract collects all the notes present in an AST.
// Each comment whose text starts with @ is parsed as a comma-separated
// sequence of notes.
// See the package documentation for details about the syntax of those
// notes.
func Extract(fset *token.FileSet, file *ast.File) ([]*Note, error) {
var notes []*Note
for _, g := range file.Comments {
for _, c := range g.List {
text := c.Text
if strings.HasPrefix(text, "/*") {
text = strings.TrimSuffix(text, "*/")
}
text = text[2:] // remove "//" or "/*" prefix
if !strings.HasPrefix(text, commentStart) {
continue
}
text = text[len(commentStart):]
parsed, err := parse(fset, c.Pos()+4, text)
if err != nil {
return nil, err
}
notes = append(notes, parsed...)
}
}
return notes, nil
}
func parse(fset *token.FileSet, base token.Pos, text string) ([]*Note, error) {
var scanErr error
s := new(scanner.Scanner).Init(strings.NewReader(text))
s.Mode = scanner.GoTokens
s.Error = func(s *scanner.Scanner, msg string) {
scanErr = fmt.Errorf("%v:%s", fset.Position(base+token.Pos(s.Position.Offset)), msg)
}
notes, err := parseComment(s)
if err != nil {
return nil, fmt.Errorf("%v:%s", fset.Position(base+token.Pos(s.Position.Offset)), err)
}
if scanErr != nil {
return nil, scanErr
}
for _, n := range notes {
n.Pos += base
}
return notes, nil
}
func parseComment(s *scanner.Scanner) ([]*Note, error) {
var notes []*Note
for {
n, err := parseNote(s)
if err != nil {
return nil, err
}
notes = append(notes, n)
tok := s.Scan()
switch tok {
case ',':
// continue
case scanner.EOF:
return notes, nil
default:
return nil, fmt.Errorf("unexpected %s parsing comment", scanner.TokenString(tok))
}
}
}
func parseNote(s *scanner.Scanner) (*Note, error) {
if tok := s.Scan(); tok != scanner.Ident {
return nil, fmt.Errorf("expected identifier, got %s", scanner.TokenString(tok))
}
n := &Note{
Pos: token.Pos(s.Position.Offset),
Name: s.TokenText(),
}
switch s.Peek() {
case ',', scanner.EOF:
// no argument list present
return n, nil
case '(':
// parse the argument list
if tok := s.Scan(); tok != '(' {
return nil, fmt.Errorf("expected ( got %s", scanner.TokenString(tok))
}
// special case the empty argument list
if s.Peek() == ')' {
if tok := s.Scan(); tok != ')' {
return nil, fmt.Errorf("expected ) got %s", scanner.TokenString(tok))
}
n.Args = []interface{}{} // @name() is represented by a non-nil empty slice.
return n, nil
}
// handle a normal argument list
for {
arg, err := parseArgument(s)
if err != nil {
return nil, err
}
n.Args = append(n.Args, arg)
switch s.Peek() {
case ')':
if tok := s.Scan(); tok != ')' {
return nil, fmt.Errorf("expected ) got %s", scanner.TokenString(tok))
}
return n, nil
case ',':
if tok := s.Scan(); tok != ',' {
return nil, fmt.Errorf("expected , got %s", scanner.TokenString(tok))
}
// continue
default:
return nil, fmt.Errorf("unexpected %s parsing argument list", scanner.TokenString(s.Scan()))
}
}
default:
return nil, fmt.Errorf("unexpected %s parsing note", scanner.TokenString(s.Scan()))
}
}
func parseArgument(s *scanner.Scanner) (interface{}, error) {
tok := s.Scan()
switch tok {
case scanner.Ident:
v := s.TokenText()
switch v {
case "true":
return true, nil
case "false":
return false, nil
case "nil":
return nil, nil
case "re":
tok := s.Scan()
switch tok {
case scanner.String, scanner.RawString:
pattern, _ := strconv.Unquote(s.TokenText()) // can't fail
re, err := regexp.Compile(pattern)
if err != nil {
return nil, fmt.Errorf("invalid regular expression %s: %v", pattern, err)
}
return re, nil
default:
return nil, fmt.Errorf("re must be followed by string, got %s", scanner.TokenString(tok))
}
default:
return Identifier(v), nil
}
case scanner.String, scanner.RawString:
v, _ := strconv.Unquote(s.TokenText()) // can't fail
return v, nil
case scanner.Int:
v, err := strconv.ParseInt(s.TokenText(), 0, 0)
if err != nil {
return nil, fmt.Errorf("cannot convert %v to int: %v", s.TokenText(), err)
}
return v, nil
case scanner.Float:
v, err := strconv.ParseFloat(s.TokenText(), 64)
if err != nil {
return nil, fmt.Errorf("cannot convert %v to float: %v", s.TokenText(), err)
}
return v, nil
case scanner.Char:
return nil, fmt.Errorf("unexpected char literal %s", s.TokenText())
default:
return nil, fmt.Errorf("unexpected %s parsing argument", scanner.TokenString(tok))
}
}

30
vendor/golang.org/x/tools/go/expect/testdata/test.go generated vendored Normal file
View File

@@ -0,0 +1,30 @@
// Copyright 2018 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.
package fake1
// The greek letters in this file mark points we use for marker tests.
// We use unique markers so we can make the tests stable against changes to
// this file.
const (
_ int = iota
αSimpleMarkerα //@αSimpleMarker
offsetββMarker //@mark(OffsetMarker, "β")
regexγMaγrker //@mark(RegexMarker, re`\p{Greek}Ma`)
εMultipleεζMarkersζ //@εMultiple,ζMarkers
ηBlockMarkerη /*@ηBlockMarker*/
)
/*Marker ι inside ι a comment*/ //@mark(Comment,"ι inside ")
func someFunc(a, b int) int {
// The line below must be the first occurrence of the plus operator
return a + b + 1 //@mark(NonIdentifier, re`\+[^\+]*`)
}
// And some extra checks for interesting action parameters
//@check(αSimpleMarker)
//@check(StringAndInt, "Number %d", 12)
//@check(Bool, true)