Skip to content

Commit 65697ce

Browse files
Merge pull request #1827 from ccoveille-forks/vendor-gospew
chore: vendor go-spew from https://github.com/davecgh/go-spew
2 parents 429ee0b + 3987752 commit 65697ce

23 files changed

+5774
-6
lines changed

assert/assertions.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ import (
1717
"unicode"
1818
"unicode/utf8"
1919

20-
"github.com/davecgh/go-spew/spew"
21-
"github.com/stretchr/testify/internal/difflib"
22-
2320
// Wrapper around gopkg.in/yaml.v3
2421
"github.com/stretchr/testify/assert/yaml"
22+
"github.com/stretchr/testify/internal/difflib"
23+
"github.com/stretchr/testify/internal/spew"
2524
)
2625

2726
//go:generate sh -c "cd ../_codegen && go build && cd - && ../_codegen/_codegen -output-package=assert -template=assertion_format.go.tmpl"

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module github.com/stretchr/testify
55
go 1.17
66

77
require (
8-
github.com/davecgh/go-spew v1.1.1
98
github.com/stretchr/objx v0.5.2 // To avoid a cycle the version of testify used by objx should be excluded below
109
gopkg.in/yaml.v3 v3.0.1
1110
)

go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
21
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
32
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
43
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=

internal/spew/LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ISC License
2+
3+
Copyright (c) 2012-2016 Dave Collins <[email protected]>
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

internal/spew/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
go-spew
2+
=======
3+
4+
[![ISC License](http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
5+
6+
Go-spew implements a deep pretty printer for Go data structures to aid in
7+
debugging. A comprehensive suite of tests with 100% test coverage is provided
8+
to ensure proper functionality.
9+
10+
## License
11+
12+
Go-spew is licensed under the [copyfree](http://copyfree.org) ISC License.

internal/spew/bypass.go

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// Copyright (c) 2015-2016 Dave Collins <[email protected]>
2+
//
3+
// Permission to use, copy, modify, and distribute this software for any
4+
// purpose with or without fee is hereby granted, provided that the above
5+
// copyright notice and this permission notice appear in all copies.
6+
//
7+
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8+
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10+
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12+
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13+
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14+
15+
// NOTE: Due to the following build constraints, this file will only be compiled
16+
// when the code is not running on Google App Engine, compiled by GopherJS, and
17+
// "-tags safe" is not added to the go build command line. The "disableunsafe"
18+
// tag is deprecated and thus should not be used.
19+
// Go versions prior to 1.4 are disabled because they use a different layout
20+
// for interfaces which make the implementation of unsafeReflectValue more complex.
21+
//go:build !js && !appengine && !safe && !disableunsafe && go1.4
22+
// +build !js,!appengine,!safe,!disableunsafe,go1.4
23+
24+
package spew
25+
26+
import (
27+
"reflect"
28+
"unsafe"
29+
)
30+
31+
const (
32+
// UnsafeDisabled is a build-time constant which specifies whether or
33+
// not access to the unsafe package is available.
34+
UnsafeDisabled = false
35+
36+
// ptrSize is the size of a pointer on the current arch.
37+
ptrSize = unsafe.Sizeof((*byte)(nil))
38+
)
39+
40+
type flag uintptr
41+
42+
var (
43+
// flagRO indicates whether the value field of a reflect.Value
44+
// is read-only.
45+
flagRO flag
46+
47+
// flagAddr indicates whether the address of the reflect.Value's
48+
// value may be taken.
49+
flagAddr flag
50+
)
51+
52+
// flagKindMask holds the bits that make up the kind
53+
// part of the flags field. In all the supported versions,
54+
// it is in the lower 5 bits.
55+
const flagKindMask = flag(0x1f)
56+
57+
// Different versions of Go have used different
58+
// bit layouts for the flags type. This table
59+
// records the known combinations.
60+
var okFlags = []struct {
61+
ro, addr flag
62+
}{{
63+
// From Go 1.4 to 1.5
64+
ro: 1 << 5,
65+
addr: 1 << 7,
66+
}, {
67+
// Up to Go tip.
68+
ro: 1<<5 | 1<<6,
69+
addr: 1 << 8,
70+
}}
71+
72+
var flagValOffset = func() uintptr {
73+
field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag")
74+
if !ok {
75+
panic("reflect.Value has no flag field")
76+
}
77+
return field.Offset
78+
}()
79+
80+
// flagField returns a pointer to the flag field of a reflect.Value.
81+
func flagField(v *reflect.Value) *flag {
82+
return (*flag)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + flagValOffset))
83+
}
84+
85+
// unsafeReflectValue converts the passed reflect.Value into a one that bypasses
86+
// the typical safety restrictions preventing access to unaddressable and
87+
// unexported data. It works by digging the raw pointer to the underlying
88+
// value out of the protected value and generating a new unprotected (unsafe)
89+
// reflect.Value to it.
90+
//
91+
// This allows us to check for implementations of the Stringer and error
92+
// interfaces to be used for pretty printing ordinarily unaddressable and
93+
// inaccessible values such as unexported struct fields.
94+
func unsafeReflectValue(v reflect.Value) reflect.Value {
95+
if !v.IsValid() || (v.CanInterface() && v.CanAddr()) {
96+
return v
97+
}
98+
flagFieldPtr := flagField(&v)
99+
*flagFieldPtr &^= flagRO
100+
*flagFieldPtr |= flagAddr
101+
return v
102+
}
103+
104+
// Sanity checks against future reflect package changes
105+
// to the type or semantics of the Value.flag field.
106+
func init() {
107+
field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag")
108+
if !ok {
109+
panic("reflect.Value has no flag field")
110+
}
111+
if field.Type.Kind() != reflect.TypeOf(flag(0)).Kind() {
112+
panic("reflect.Value flag field has changed kind")
113+
}
114+
type t0 int
115+
var t struct {
116+
A t0
117+
// t0 will have flagEmbedRO set.
118+
t0
119+
// a will have flagStickyRO set
120+
a t0
121+
}
122+
vA := reflect.ValueOf(t).FieldByName("A")
123+
va := reflect.ValueOf(t).FieldByName("a")
124+
vt0 := reflect.ValueOf(t).FieldByName("t0")
125+
126+
// Infer flagRO from the difference between the flags
127+
// for the (otherwise identical) fields in t.
128+
flagPublic := *flagField(&vA)
129+
flagWithRO := *flagField(&va) | *flagField(&vt0)
130+
flagRO = flagPublic ^ flagWithRO
131+
132+
// Infer flagAddr from the difference between a value
133+
// taken from a pointer and not.
134+
vPtrA := reflect.ValueOf(&t).Elem().FieldByName("A")
135+
flagNoPtr := *flagField(&vA)
136+
flagPtr := *flagField(&vPtrA)
137+
flagAddr = flagNoPtr ^ flagPtr
138+
139+
// Check that the inferred flags tally with one of the known versions.
140+
for _, f := range okFlags {
141+
if flagRO == f.ro && flagAddr == f.addr {
142+
return
143+
}
144+
}
145+
panic("reflect.Value read-only flag has changed semantics")
146+
}

internal/spew/bypasssafe.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2015-2016 Dave Collins <[email protected]>
2+
//
3+
// Permission to use, copy, modify, and distribute this software for any
4+
// purpose with or without fee is hereby granted, provided that the above
5+
// copyright notice and this permission notice appear in all copies.
6+
//
7+
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8+
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10+
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12+
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13+
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14+
15+
// NOTE: Due to the following build constraints, this file will only be compiled
16+
// when the code is running on Google App Engine, compiled by GopherJS, or
17+
// "-tags safe" is added to the go build command line. The "disableunsafe"
18+
// tag is deprecated and thus should not be used.
19+
//go:build js || appengine || safe || disableunsafe || !go1.4
20+
// +build js appengine safe disableunsafe !go1.4
21+
22+
package spew
23+
24+
import "reflect"
25+
26+
const (
27+
// UnsafeDisabled is a build-time constant which specifies whether or
28+
// not access to the unsafe package is available.
29+
UnsafeDisabled = true
30+
)
31+
32+
// unsafeReflectValue typically converts the passed reflect.Value into a one
33+
// that bypasses the typical safety restrictions preventing access to
34+
// unaddressable and unexported data. However, doing this relies on access to
35+
// the unsafe package. This is a stub version which simply returns the passed
36+
// reflect.Value when the unsafe package is not available.
37+
func unsafeReflectValue(v reflect.Value) reflect.Value {
38+
return v
39+
}

0 commit comments

Comments
 (0)