summaryrefslogtreecommitdiff
path: root/spew/internal_test.go
diff options
context:
space:
mode:
authorDave Collins <[email protected]>2015-06-17 22:34:22 -0500
committerDave Collins <[email protected]>2015-06-19 15:29:34 -0500
commit2df174808ee097f90d259e432cc04442cf60be21 (patch)
tree137a52652745f1dc47abb8ab3d379cb556e6e632 /spew/internal_test.go
parentf9f629a1d082960e5d1747f33c2b378612615fea (diff)
Add support for limited mode without unsafe pkg.
This commit adds support for compiling spew without the unsafe package. When compiled without the unsafe package, some of the more advanced features such as invoking stringers on pointers from non-pointer variables and unexported struct fields are not available. By default, spew will be compiled in the limited mode for Google App Engine since the unsafe package is not available there. Additionally, spew can be compiled without the unsafe package manually by specifying the "disableunsafe" build tag. Finally, a new package-level constant named "UnsafeDisabled" has been exposed which can be used to programmatically determine if spew was compiled with access to the unsafe package.
Diffstat (limited to 'spew/internal_test.go')
-rw-r--r--spew/internal_test.go69
1 files changed, 0 insertions, 69 deletions
diff --git a/spew/internal_test.go b/spew/internal_test.go
index b583bfd..1069ee2 100644
--- a/spew/internal_test.go
+++ b/spew/internal_test.go
@@ -26,7 +26,6 @@ import (
"bytes"
"reflect"
"testing"
- "unsafe"
)
// dummyFmtState implements a fake fmt.State to use for testing invalid
@@ -81,74 +80,6 @@ func TestInvalidReflectValue(t *testing.T) {
}
}
-// changeKind uses unsafe to intentionally change the kind of a reflect.Value to
-// the maximum kind value which does not exist. This is needed to test the
-// fallback code which punts to the standard fmt library for new types that
-// might get added to the language.
-func changeKind(v *reflect.Value, readOnly bool) {
- rvf := (*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + offsetFlag))
- *rvf = *rvf | ((1<<flagKindWidth - 1) << flagKindShift)
- if readOnly {
- *rvf |= flagRO
- } else {
- *rvf &= ^uintptr(flagRO)
- }
-}
-
-// TestAddedReflectValue tests functionaly of the dump and formatter code which
-// falls back to the standard fmt library for new types that might get added to
-// the language.
-func TestAddedReflectValue(t *testing.T) {
- i := 1
-
- // Dump using a reflect.Value that is exported.
- v := reflect.ValueOf(int8(5))
- changeKind(&v, false)
- buf := new(bytes.Buffer)
- d := dumpState{w: buf, cs: &Config}
- d.dump(v)
- s := buf.String()
- want := "(int8) 5"
- if s != want {
- t.Errorf("TestAddedReflectValue #%d\n got: %s want: %s", i, s, want)
- }
- i++
-
- // Dump using a reflect.Value that is not exported.
- changeKind(&v, true)
- buf.Reset()
- d.dump(v)
- s = buf.String()
- want = "(int8) <int8 Value>"
- if s != want {
- t.Errorf("TestAddedReflectValue #%d\n got: %s want: %s", i, s, want)
- }
- i++
-
- // Formatter using a reflect.Value that is exported.
- changeKind(&v, false)
- buf2 := new(dummyFmtState)
- f := formatState{value: v, cs: &Config, fs: buf2}
- f.format(v)
- s = buf2.String()
- want = "5"
- if s != want {
- t.Errorf("TestAddedReflectValue #%d got: %s want: %s", i, s, want)
- }
- i++
-
- // Formatter using a reflect.Value that is not exported.
- changeKind(&v, true)
- buf2.Reset()
- f = formatState{value: v, cs: &Config, fs: buf2}
- f.format(v)
- s = buf2.String()
- want = "<int8 Value>"
- if s != want {
- t.Errorf("TestAddedReflectValue #%d got: %s want: %s", i, s, want)
- }
-}
-
// SortValues makes the internal sortValues function available to the test
// package.
func SortValues(values []reflect.Value, cs *ConfigState) {