| 1 |
# spew |
| 2 |
|
| 3 |
Originally copied from |
| 4 |
[github.com/davecgh/go-spew](https://github.com/davecgh/go-spew), it |
| 5 |
has been patched to fit go-testdeep needs as the original repository |
| 6 |
seems to have no activity anymore. |
| 7 |
|
| 8 |
spew implements a deep pretty printer for Go data structures to aid |
| 9 |
in debugging. A comprehensive suite of tests with 100% test coverage |
| 10 |
is provided to ensure proper functionality. This directory and its |
| 11 |
sub-directories are licensed under the [copyfree](http://copyfree.org) |
| 12 |
[ISC License](internal/spew/LICENSE), so it may be used in open |
| 13 |
source or commercial projects. |
| 14 |
|
| 15 |
If you're interested in reading about how the original go-spew package |
| 16 |
came to life and some of the challenges involved in providing a deep |
| 17 |
pretty printer, there is a blog post about it |
| 18 |
[here](https://web.archive.org/web/20160304013555/https://blog.cyphertite.com/go-spew-a-journey-into-dumping-go-data-structures/). |
| 19 |
|
| 20 |
## Documentation |
| 21 |
|
| 22 |
https://pkg.go.dev/github.com/maxatome/go-testdeep/internal/spew |
| 23 |
|
| 24 |
## Quick Start |
| 25 |
|
| 26 |
Add this import line to the file you're working in: |
| 27 |
|
| 28 |
```go |
| 29 |
import "github.com/maxatome/go-testdeep/internal/spew" |
| 30 |
``` |
| 31 |
|
| 32 |
To dump a variable with full newlines, indentation, type and pointer |
| 33 |
information use Sdump: |
| 34 |
|
| 35 |
```go |
| 36 |
str := spew.Sdump(myVar1) |
| 37 |
``` |
| 38 |
|
| 39 |
## Sample Sdump Output |
| 40 |
|
| 41 |
``` |
| 42 |
(main.Foo) { |
| 43 |
unexportedField: (*main.Bar)(0xf84002e210)({ |
| 44 |
flag: (main.Flag) flagTwo, |
| 45 |
data: (uintptr) <nil> |
| 46 |
}), |
| 47 |
ExportedField: (map[interface {}]interface {}) { |
| 48 |
(string) "one": (bool) true |
| 49 |
} |
| 50 |
} |
| 51 |
([]uint8) { |
| 52 |
00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 |............... | |
| 53 |
00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 |!"#$%&'()*+,-./0| |
| 54 |
00000020 31 32 |12| |
| 55 |
} |
| 56 |
``` |
| 57 |
|
| 58 |
## Configuration Options |
| 59 |
|
| 60 |
Configuration of spew is handled by fields in the ConfigState type. For |
| 61 |
convenience, all of the top-level functions use a global state available via the |
| 62 |
spew.Config global. |
| 63 |
|
| 64 |
It is also possible to create a ConfigState instance that provides methods |
| 65 |
equivalent to the top-level functions. This allows concurrent configuration |
| 66 |
options. See the ConfigState documentation for more details. |
| 67 |
|
| 68 |
``` |
| 69 |
* Indent |
| 70 |
String to use for each indentation level for Sdump function. |
| 71 |
It is a single space by default. A popular alternative is "\t". |
| 72 |
|
| 73 |
* MaxDepth |
| 74 |
Maximum number of levels to descend into nested data structures. |
| 75 |
There is no limit by default. |
| 76 |
|
| 77 |
* DisableMethods |
| 78 |
Disables invocation of error and fmt.Stringer interface methods. |
| 79 |
Method invocation is enabled by default. |
| 80 |
|
| 81 |
* DisablePointerMethods |
| 82 |
Disables invocation of error and fmt.Stringer interface methods on types |
| 83 |
which only accept pointer receivers from non-pointer variables. This option |
| 84 |
relies on access to the unsafe package, so it will not have any effect when |
| 85 |
running in environments without access to the unsafe package such as Google |
| 86 |
App Engine or with the "safe" build tag specified. |
| 87 |
Pointer method invocation is enabled by default. |
| 88 |
|
| 89 |
* DisablePointerAddresses |
| 90 |
DisablePointerAddresses specifies whether to disable the printing of |
| 91 |
pointer addresses. This is useful when diffing data structures in tests. |
| 92 |
|
| 93 |
* EnableCapacities |
| 94 |
EnableCapacities specifies whether to enable the printing of capacities |
| 95 |
for arrays, slices and channels. |
| 96 |
``` |
| 97 |
|
| 98 |
## Unsafe Package Dependency |
| 99 |
|
| 100 |
This package relies on the unsafe package to perform some of the more advanced |
| 101 |
features, however it also supports a "limited" mode which allows it to work in |
| 102 |
environments where the unsafe package is not available. By default, it will |
| 103 |
operate in this mode on Google App Engine and when compiled with GopherJS. The |
| 104 |
"safe" build tag may also be specified to force the package to build without |
| 105 |
using the unsafe package. |
| 106 |
|
| 107 |
## License |
| 108 |
|
| 109 |
This directory and its sub-directories are licensed under the |
| 110 |
[copyfree](http://copyfree.org) [ISC License](internal/spew/LICENSE), |
| 111 |
so it may be used in open source or commercial projects. |