dump_test.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. /*
  2. * Copyright (c) 2013 Dave Collins <dave@davec.name>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /*
  17. Test Summary:
  18. NOTE: For each test, a nil pointer, a single pointer and double pointer to the
  19. base test element are also tested to ensure proper indirection across all types.
  20. - Max int8, int16, int32, int64, int
  21. - Max uint8, uint16, uint32, uint64, uint
  22. - Boolean true and false
  23. - Standard complex64 and complex128
  24. - Array containing standard ints
  25. - Array containing type with custom formatter on pointer receiver only
  26. - Array containing interfaces
  27. - Array containing bytes
  28. - Slice containing standard float32 values
  29. - Slice containing type with custom formatter on pointer receiver only
  30. - Slice containing interfaces
  31. - Slice containing bytes
  32. - Standard string
  33. - Nil interface
  34. - Sub-interface
  35. - Map with string keys and int vals
  36. - Map with custom formatter type on pointer receiver only keys and vals
  37. - Map with interface keys and values
  38. - Map with nil interface value
  39. - Struct with primitives
  40. - Struct that contains another struct
  41. - Struct that contains custom type with Stringer pointer interface via both
  42. exported and unexported fields
  43. - Struct that contains embedded struct and field to same struct
  44. - Uintptr to 0 (null pointer)
  45. - Uintptr address of real variable
  46. - Unsafe.Pointer to 0 (null pointer)
  47. - Unsafe.Pointer to address of real variable
  48. - Nil channel
  49. - Standard int channel
  50. - Function with no params and no returns
  51. - Function with param and no returns
  52. - Function with multiple params and multiple returns
  53. - Struct that is circular through self referencing
  54. - Structs that are circular through cross referencing
  55. - Structs that are indirectly circular
  56. - Type that panics in its Stringer interface
  57. */
  58. package spew_test
  59. import (
  60. "bytes"
  61. "fmt"
  62. "github.com/davecgh/go-spew/spew"
  63. "testing"
  64. "unsafe"
  65. )
  66. // dumpTest is used to describe a test to be perfomed against the Dump method.
  67. type dumpTest struct {
  68. in interface{}
  69. wants []string
  70. }
  71. // dumpTests houses all of the tests to be performed against the Dump method.
  72. var dumpTests = make([]dumpTest, 0)
  73. // addDumpTest is a helper method to append the passed input and desired result
  74. // to dumpTests
  75. func addDumpTest(in interface{}, wants ...string) {
  76. test := dumpTest{in, wants}
  77. dumpTests = append(dumpTests, test)
  78. }
  79. func addIntDumpTests() {
  80. // Max int8.
  81. v := int8(127)
  82. nv := (*int8)(nil)
  83. pv := &v
  84. vAddr := fmt.Sprintf("%p", pv)
  85. pvAddr := fmt.Sprintf("%p", &pv)
  86. vt := "int8"
  87. vs := "127"
  88. addDumpTest(v, "("+vt+") "+vs+"\n")
  89. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
  90. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  91. addDumpTest(nv, "(*"+vt+")(<nil>)\n")
  92. // Max int16.
  93. v2 := int16(32767)
  94. nv2 := (*int16)(nil)
  95. pv2 := &v2
  96. v2Addr := fmt.Sprintf("%p", pv2)
  97. pv2Addr := fmt.Sprintf("%p", &pv2)
  98. v2t := "int16"
  99. v2s := "32767"
  100. addDumpTest(v2, "("+v2t+") "+v2s+"\n")
  101. addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n")
  102. addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n")
  103. addDumpTest(nv2, "(*"+v2t+")(<nil>)\n")
  104. // Max int32.
  105. v3 := int32(2147483647)
  106. nv3 := (*int32)(nil)
  107. pv3 := &v3
  108. v3Addr := fmt.Sprintf("%p", pv3)
  109. pv3Addr := fmt.Sprintf("%p", &pv3)
  110. v3t := "int32"
  111. v3s := "2147483647"
  112. addDumpTest(v3, "("+v3t+") "+v3s+"\n")
  113. addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n")
  114. addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n")
  115. addDumpTest(nv3, "(*"+v3t+")(<nil>)\n")
  116. // Max int64.
  117. v4 := int64(9223372036854775807)
  118. nv4 := (*int64)(nil)
  119. pv4 := &v4
  120. v4Addr := fmt.Sprintf("%p", pv4)
  121. pv4Addr := fmt.Sprintf("%p", &pv4)
  122. v4t := "int64"
  123. v4s := "9223372036854775807"
  124. addDumpTest(v4, "("+v4t+") "+v4s+"\n")
  125. addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n")
  126. addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n")
  127. addDumpTest(nv4, "(*"+v4t+")(<nil>)\n")
  128. // Max int.
  129. v5 := int(2147483647)
  130. nv5 := (*int)(nil)
  131. pv5 := &v5
  132. v5Addr := fmt.Sprintf("%p", pv5)
  133. pv5Addr := fmt.Sprintf("%p", &pv5)
  134. v5t := "int"
  135. v5s := "2147483647"
  136. addDumpTest(v5, "("+v5t+") "+v5s+"\n")
  137. addDumpTest(pv5, "(*"+v5t+")("+v5Addr+")("+v5s+")\n")
  138. addDumpTest(&pv5, "(**"+v5t+")("+pv5Addr+"->"+v5Addr+")("+v5s+")\n")
  139. addDumpTest(nv5, "(*"+v5t+")(<nil>)\n")
  140. }
  141. func addUintDumpTests() {
  142. // Max uint8.
  143. v := uint8(255)
  144. nv := (*uint8)(nil)
  145. pv := &v
  146. vAddr := fmt.Sprintf("%p", pv)
  147. pvAddr := fmt.Sprintf("%p", &pv)
  148. vt := "uint8"
  149. vs := "255"
  150. addDumpTest(v, "("+vt+") "+vs+"\n")
  151. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
  152. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  153. addDumpTest(nv, "(*"+vt+")(<nil>)\n")
  154. // Max uint16.
  155. v2 := uint16(65535)
  156. nv2 := (*uint16)(nil)
  157. pv2 := &v2
  158. v2Addr := fmt.Sprintf("%p", pv2)
  159. pv2Addr := fmt.Sprintf("%p", &pv2)
  160. v2t := "uint16"
  161. v2s := "65535"
  162. addDumpTest(v2, "("+v2t+") "+v2s+"\n")
  163. addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n")
  164. addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n")
  165. addDumpTest(nv2, "(*"+v2t+")(<nil>)\n")
  166. // Max uint32.
  167. v3 := uint32(4294967295)
  168. nv3 := (*uint32)(nil)
  169. pv3 := &v3
  170. v3Addr := fmt.Sprintf("%p", pv3)
  171. pv3Addr := fmt.Sprintf("%p", &pv3)
  172. v3t := "uint32"
  173. v3s := "4294967295"
  174. addDumpTest(v3, "("+v3t+") "+v3s+"\n")
  175. addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n")
  176. addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n")
  177. addDumpTest(nv3, "(*"+v3t+")(<nil>)\n")
  178. // Max uint64.
  179. v4 := uint64(18446744073709551615)
  180. nv4 := (*uint64)(nil)
  181. pv4 := &v4
  182. v4Addr := fmt.Sprintf("%p", pv4)
  183. pv4Addr := fmt.Sprintf("%p", &pv4)
  184. v4t := "uint64"
  185. v4s := "18446744073709551615"
  186. addDumpTest(v4, "("+v4t+") "+v4s+"\n")
  187. addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n")
  188. addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n")
  189. addDumpTest(nv4, "(*"+v4t+")(<nil>)\n")
  190. // Max uint.
  191. v5 := uint(4294967295)
  192. nv5 := (*uint)(nil)
  193. pv5 := &v5
  194. v5Addr := fmt.Sprintf("%p", pv5)
  195. pv5Addr := fmt.Sprintf("%p", &pv5)
  196. v5t := "uint"
  197. v5s := "4294967295"
  198. addDumpTest(v5, "("+v5t+") "+v5s+"\n")
  199. addDumpTest(pv5, "(*"+v5t+")("+v5Addr+")("+v5s+")\n")
  200. addDumpTest(&pv5, "(**"+v5t+")("+pv5Addr+"->"+v5Addr+")("+v5s+")\n")
  201. addDumpTest(nv5, "(*"+v5t+")(<nil>)\n")
  202. }
  203. func addBoolDumpTests() {
  204. // Boolean true.
  205. v := bool(true)
  206. nv := (*bool)(nil)
  207. pv := &v
  208. vAddr := fmt.Sprintf("%p", pv)
  209. pvAddr := fmt.Sprintf("%p", &pv)
  210. vt := "bool"
  211. vs := "true"
  212. addDumpTest(v, "("+vt+") "+vs+"\n")
  213. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
  214. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  215. addDumpTest(nv, "(*"+vt+")(<nil>)\n")
  216. // Boolean false.
  217. v2 := bool(false)
  218. pv2 := &v2
  219. v2Addr := fmt.Sprintf("%p", pv2)
  220. pv2Addr := fmt.Sprintf("%p", &pv2)
  221. v2t := "bool"
  222. v2s := "false"
  223. addDumpTest(v2, "("+v2t+") "+v2s+"\n")
  224. addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n")
  225. addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n")
  226. }
  227. func addFloatDumpTests() {
  228. // Standard float32.
  229. v := float32(3.1415)
  230. nv := (*float32)(nil)
  231. pv := &v
  232. vAddr := fmt.Sprintf("%p", pv)
  233. pvAddr := fmt.Sprintf("%p", &pv)
  234. vt := "float32"
  235. vs := "3.1415"
  236. addDumpTest(v, "("+vt+") "+vs+"\n")
  237. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
  238. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  239. addDumpTest(nv, "(*"+vt+")(<nil>)\n")
  240. // Standard float64.
  241. v2 := float64(3.1415926)
  242. nv2 := (*float64)(nil)
  243. pv2 := &v2
  244. v2Addr := fmt.Sprintf("%p", pv2)
  245. pv2Addr := fmt.Sprintf("%p", &pv2)
  246. v2t := "float64"
  247. v2s := "3.1415926"
  248. addDumpTest(v2, "("+v2t+") "+v2s+"\n")
  249. addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n")
  250. addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n")
  251. addDumpTest(nv2, "(*"+v2t+")(<nil>)\n")
  252. }
  253. func addComplexDumpTests() {
  254. // Standard complex64.
  255. v := complex(float32(6), -2)
  256. nv := (*complex64)(nil)
  257. pv := &v
  258. vAddr := fmt.Sprintf("%p", pv)
  259. pvAddr := fmt.Sprintf("%p", &pv)
  260. vt := "complex64"
  261. vs := "(6-2i)"
  262. addDumpTest(v, "("+vt+") "+vs+"\n")
  263. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
  264. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  265. addDumpTest(nv, "(*"+vt+")(<nil>)\n")
  266. // Standard complex128.
  267. v2 := complex(float64(-6), 2)
  268. nv2 := (*complex128)(nil)
  269. pv2 := &v2
  270. v2Addr := fmt.Sprintf("%p", pv2)
  271. pv2Addr := fmt.Sprintf("%p", &pv2)
  272. v2t := "complex128"
  273. v2s := "(-6+2i)"
  274. addDumpTest(v2, "("+v2t+") "+v2s+"\n")
  275. addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n")
  276. addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n")
  277. addDumpTest(nv2, "(*"+v2t+")(<nil>)\n")
  278. }
  279. func addArrayDumpTests() {
  280. // Array containing standard ints.
  281. v := [3]int{1, 2, 3}
  282. nv := (*[3]int)(nil)
  283. pv := &v
  284. vAddr := fmt.Sprintf("%p", pv)
  285. pvAddr := fmt.Sprintf("%p", &pv)
  286. vt := "int"
  287. vs := "{\n (" + vt + ") 1,\n (" + vt + ") 2,\n (" + vt + ") 3\n}"
  288. addDumpTest(v, "([3]"+vt+") "+vs+"\n")
  289. addDumpTest(pv, "(*[3]"+vt+")("+vAddr+")("+vs+")\n")
  290. addDumpTest(&pv, "(**[3]"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  291. addDumpTest(nv, "(*[3]"+vt+")(<nil>)\n")
  292. // Array containing type with custom formatter on pointer receiver only.
  293. v2 := [3]pstringer{"1", "2", "3"}
  294. nv2 := (*[3]pstringer)(nil)
  295. pv2 := &v2
  296. v2Addr := fmt.Sprintf("%p", pv2)
  297. pv2Addr := fmt.Sprintf("%p", &pv2)
  298. v2t := "spew_test.pstringer"
  299. v2s := "{\n (" + v2t + ") stringer 1,\n (" + v2t + ") stringer 2,\n (" +
  300. v2t + ") stringer 3\n}"
  301. addDumpTest(v2, "([3]"+v2t+") "+v2s+"\n")
  302. addDumpTest(pv2, "(*[3]"+v2t+")("+v2Addr+")("+v2s+")\n")
  303. addDumpTest(&pv2, "(**[3]"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n")
  304. addDumpTest(nv2, "(*[3]"+v2t+")(<nil>)\n")
  305. // Array containing interfaces.
  306. v3 := [3]interface{}{"one", int(2), uint(3)}
  307. nv3 := (*[3]interface{})(nil)
  308. pv3 := &v3
  309. v3Addr := fmt.Sprintf("%p", pv3)
  310. pv3Addr := fmt.Sprintf("%p", &pv3)
  311. v3t := "[3]interface {}"
  312. v3t2 := "string"
  313. v3t3 := "int"
  314. v3t4 := "uint"
  315. v3s := "{\n (" + v3t2 + ") \"one\",\n (" + v3t3 + ") 2,\n (" + v3t4 +
  316. ") 3\n}"
  317. addDumpTest(v3, "("+v3t+") "+v3s+"\n")
  318. addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n")
  319. addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n")
  320. addDumpTest(nv3, "(*"+v3t+")(<nil>)\n")
  321. // Array containing bytes.
  322. v4 := [34]byte{
  323. 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
  324. 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
  325. 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
  326. 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
  327. 0x31, 0x32,
  328. }
  329. nv4 := (*[34]byte)(nil)
  330. pv4 := &v4
  331. v4Addr := fmt.Sprintf("%p", pv4)
  332. pv4Addr := fmt.Sprintf("%p", &pv4)
  333. v4t := "[34]uint8"
  334. v4s := "{\n 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20" +
  335. " |............... |\n" +
  336. " 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30" +
  337. " |!\"#$%&'()*+,-./0|\n" +
  338. " 00000020 31 32 " +
  339. " |12|\n}"
  340. addDumpTest(v4, "("+v4t+") "+v4s+"\n")
  341. addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n")
  342. addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n")
  343. addDumpTest(nv4, "(*"+v4t+")(<nil>)\n")
  344. }
  345. func addSliceDumpTests() {
  346. // Slice containing standard float32 values.
  347. v := []float32{3.14, 6.28, 12.56}
  348. nv := (*[]float32)(nil)
  349. pv := &v
  350. vAddr := fmt.Sprintf("%p", pv)
  351. pvAddr := fmt.Sprintf("%p", &pv)
  352. vt := "float32"
  353. vs := "{\n (" + vt + ") 3.14,\n (" + vt + ") 6.28,\n (" + vt + ") 12.56\n}"
  354. addDumpTest(v, "([]"+vt+") "+vs+"\n")
  355. addDumpTest(pv, "(*[]"+vt+")("+vAddr+")("+vs+")\n")
  356. addDumpTest(&pv, "(**[]"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  357. addDumpTest(nv, "(*[]"+vt+")(<nil>)\n")
  358. // Slice containing type with custom formatter on pointer receiver only.
  359. v2 := []pstringer{"1", "2", "3"}
  360. nv2 := (*[]pstringer)(nil)
  361. pv2 := &v2
  362. v2Addr := fmt.Sprintf("%p", pv2)
  363. pv2Addr := fmt.Sprintf("%p", &pv2)
  364. v2t := "spew_test.pstringer"
  365. v2s := "{\n (" + v2t + ") stringer 1,\n (" + v2t + ") stringer 2,\n (" +
  366. v2t + ") stringer 3\n}"
  367. addDumpTest(v2, "([]"+v2t+") "+v2s+"\n")
  368. addDumpTest(pv2, "(*[]"+v2t+")("+v2Addr+")("+v2s+")\n")
  369. addDumpTest(&pv2, "(**[]"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n")
  370. addDumpTest(nv2, "(*[]"+v2t+")(<nil>)\n")
  371. // Slice containing interfaces.
  372. v3 := []interface{}{"one", int(2), uint(3), nil}
  373. nv3 := (*[]interface{})(nil)
  374. pv3 := &v3
  375. v3Addr := fmt.Sprintf("%p", pv3)
  376. pv3Addr := fmt.Sprintf("%p", &pv3)
  377. v3t := "[]interface {}"
  378. v3t2 := "string"
  379. v3t3 := "int"
  380. v3t4 := "uint"
  381. v3t5 := "interface {}"
  382. v3s := "{\n (" + v3t2 + ") \"one\",\n (" + v3t3 + ") 2,\n (" + v3t4 +
  383. ") 3,\n (" + v3t5 + ") <nil>\n}"
  384. addDumpTest(v3, "("+v3t+") "+v3s+"\n")
  385. addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n")
  386. addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n")
  387. addDumpTest(nv3, "(*"+v3t+")(<nil>)\n")
  388. // Slice containing bytes.
  389. v4 := []byte{
  390. 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
  391. 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
  392. 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
  393. 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
  394. 0x31, 0x32,
  395. }
  396. nv4 := (*[]byte)(nil)
  397. pv4 := &v4
  398. v4Addr := fmt.Sprintf("%p", pv4)
  399. pv4Addr := fmt.Sprintf("%p", &pv4)
  400. v4t := "[]uint8"
  401. v4s := "{\n 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20" +
  402. " |............... |\n" +
  403. " 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30" +
  404. " |!\"#$%&'()*+,-./0|\n" +
  405. " 00000020 31 32 " +
  406. " |12|\n}"
  407. addDumpTest(v4, "("+v4t+") "+v4s+"\n")
  408. addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n")
  409. addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n")
  410. addDumpTest(nv4, "(*"+v4t+")(<nil>)\n")
  411. }
  412. func addStringDumpTests() {
  413. // Standard string.
  414. v := "test"
  415. nv := (*string)(nil)
  416. pv := &v
  417. vAddr := fmt.Sprintf("%p", pv)
  418. pvAddr := fmt.Sprintf("%p", &pv)
  419. vt := "string"
  420. vs := "\"test\""
  421. addDumpTest(v, "("+vt+") "+vs+"\n")
  422. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
  423. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  424. addDumpTest(nv, "(*"+vt+")(<nil>)\n")
  425. }
  426. func addInterfaceDumpTests() {
  427. // Nil interface.
  428. var v interface{}
  429. nv := (*interface{})(nil)
  430. pv := &v
  431. vAddr := fmt.Sprintf("%p", pv)
  432. pvAddr := fmt.Sprintf("%p", &pv)
  433. vt := "interface {}"
  434. vs := "<nil>"
  435. addDumpTest(v, "("+vt+") "+vs+"\n")
  436. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
  437. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  438. addDumpTest(nv, "(*"+vt+")(<nil>)\n")
  439. // Sub-interface.
  440. v2 := interface{}(uint16(65535))
  441. pv2 := &v2
  442. v2Addr := fmt.Sprintf("%p", pv2)
  443. pv2Addr := fmt.Sprintf("%p", &pv2)
  444. v2t := "uint16"
  445. v2s := "65535"
  446. addDumpTest(v2, "("+v2t+") "+v2s+"\n")
  447. addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n")
  448. addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n")
  449. }
  450. func addMapDumpTests() {
  451. // Map with string keys and int vals.
  452. v := map[string]int{"one": 1, "two": 2}
  453. nv := (*map[string]int)(nil)
  454. pv := &v
  455. vAddr := fmt.Sprintf("%p", pv)
  456. pvAddr := fmt.Sprintf("%p", &pv)
  457. vt := "map[string]int"
  458. vt1 := "string"
  459. vt2 := "int"
  460. vs := "{\n (" + vt1 + ") \"one\": (" + vt2 + ") 1,\n (" + vt1 +
  461. ") \"two\": (" + vt2 + ") 2\n}"
  462. vs2 := "{\n (" + vt1 + ") \"two\": (" + vt2 + ") 2,\n (" + vt1 +
  463. ") \"one\": (" + vt2 + ") 1\n}"
  464. addDumpTest(v, "("+vt+") "+vs+"\n", "("+vt+") "+vs2+"\n")
  465. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n",
  466. "(*"+vt+")("+vAddr+")("+vs2+")\n")
  467. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n",
  468. "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs2+")\n")
  469. addDumpTest(nv, "(*"+vt+")(<nil>)\n")
  470. // Map with custom formatter type on pointer receiver only keys and vals.
  471. v2 := map[pstringer]pstringer{"one": "1"}
  472. nv2 := (*map[pstringer]pstringer)(nil)
  473. pv2 := &v2
  474. v2Addr := fmt.Sprintf("%p", pv2)
  475. pv2Addr := fmt.Sprintf("%p", &pv2)
  476. v2t := "map[spew_test.pstringer]spew_test.pstringer"
  477. v2t1 := "spew_test.pstringer"
  478. v2t2 := "spew_test.pstringer"
  479. v2s := "{\n (" + v2t1 + ") stringer one: (" + v2t2 + ") stringer 1\n}"
  480. addDumpTest(v2, "("+v2t+") "+v2s+"\n")
  481. addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n")
  482. addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n")
  483. addDumpTest(nv2, "(*"+v2t+")(<nil>)\n")
  484. // Map with interface keys and values.
  485. v3 := map[interface{}]interface{}{"one": 1}
  486. nv3 := (*map[interface{}]interface{})(nil)
  487. pv3 := &v3
  488. v3Addr := fmt.Sprintf("%p", pv3)
  489. pv3Addr := fmt.Sprintf("%p", &pv3)
  490. v3t := "map[interface {}]interface {}"
  491. v3t1 := "string"
  492. v3t2 := "int"
  493. v3s := "{\n (" + v3t1 + ") \"one\": (" + v3t2 + ") 1\n}"
  494. addDumpTest(v3, "("+v3t+") "+v3s+"\n")
  495. addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n")
  496. addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n")
  497. addDumpTest(nv3, "(*"+v3t+")(<nil>)\n")
  498. // Map with nil interface value.
  499. v4 := map[string]interface{}{"nil": nil}
  500. nv4 := (*map[string]interface{})(nil)
  501. pv4 := &v4
  502. v4Addr := fmt.Sprintf("%p", pv4)
  503. pv4Addr := fmt.Sprintf("%p", &pv4)
  504. v4t := "map[string]interface {}"
  505. v4t1 := "string"
  506. v4t2 := "interface {}"
  507. v4s := "{\n (" + v4t1 + ") \"nil\": (" + v4t2 + ") <nil>\n}"
  508. addDumpTest(v4, "("+v4t+") "+v4s+"\n")
  509. addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n")
  510. addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n")
  511. addDumpTest(nv4, "(*"+v4t+")(<nil>)\n")
  512. }
  513. func addStructDumpTests() {
  514. // Struct with primitives.
  515. type s1 struct {
  516. a int8
  517. b uint8
  518. }
  519. v := s1{127, 255}
  520. nv := (*s1)(nil)
  521. pv := &v
  522. vAddr := fmt.Sprintf("%p", pv)
  523. pvAddr := fmt.Sprintf("%p", &pv)
  524. vt := "spew_test.s1"
  525. vt2 := "int8"
  526. vt3 := "uint8"
  527. vs := "{\n a: (" + vt2 + ") 127,\n b: (" + vt3 + ") 255\n}"
  528. addDumpTest(v, "("+vt+") "+vs+"\n")
  529. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
  530. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  531. addDumpTest(nv, "(*"+vt+")(<nil>)\n")
  532. // Struct that contains another struct.
  533. type s2 struct {
  534. s1 s1
  535. b bool
  536. }
  537. v2 := s2{s1{127, 255}, true}
  538. nv2 := (*s2)(nil)
  539. pv2 := &v2
  540. v2Addr := fmt.Sprintf("%p", pv2)
  541. pv2Addr := fmt.Sprintf("%p", &pv2)
  542. v2t := "spew_test.s2"
  543. v2t2 := "spew_test.s1"
  544. v2t3 := "int8"
  545. v2t4 := "uint8"
  546. v2t5 := "bool"
  547. v2s := "{\n s1: (" + v2t2 + ") {\n a: (" + v2t3 + ") 127,\n b: (" +
  548. v2t4 + ") 255\n },\n b: (" + v2t5 + ") true\n}"
  549. addDumpTest(v2, "("+v2t+") "+v2s+"\n")
  550. addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n")
  551. addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n")
  552. addDumpTest(nv2, "(*"+v2t+")(<nil>)\n")
  553. // Struct that contains custom type with Stringer pointer interface via both
  554. // exported and unexported fields.
  555. type s3 struct {
  556. s pstringer
  557. S pstringer
  558. }
  559. v3 := s3{"test", "test2"}
  560. nv3 := (*s3)(nil)
  561. pv3 := &v3
  562. v3Addr := fmt.Sprintf("%p", pv3)
  563. pv3Addr := fmt.Sprintf("%p", &pv3)
  564. v3t := "spew_test.s3"
  565. v3t2 := "spew_test.pstringer"
  566. v3s := "{\n s: (" + v3t2 + ") stringer test,\n S: (" + v3t2 +
  567. ") stringer test2\n}"
  568. addDumpTest(v3, "("+v3t+") "+v3s+"\n")
  569. addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n")
  570. addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n")
  571. addDumpTest(nv3, "(*"+v3t+")(<nil>)\n")
  572. // Struct that contains embedded struct and field to same struct.
  573. e := embed{"embedstr"}
  574. v4 := embedwrap{embed: &e, e: &e}
  575. nv4 := (*embedwrap)(nil)
  576. pv4 := &v4
  577. eAddr := fmt.Sprintf("%p", &e)
  578. v4Addr := fmt.Sprintf("%p", pv4)
  579. pv4Addr := fmt.Sprintf("%p", &pv4)
  580. v4t := "spew_test.embedwrap"
  581. v4t2 := "spew_test.embed"
  582. v4t3 := "string"
  583. v4s := "{\n embed: (*" + v4t2 + ")(" + eAddr + ")({\n a: (" + v4t3 +
  584. ") \"embedstr\"\n }),\n e: (*" + v4t2 + ")(" + eAddr + ")({\n" +
  585. " a: (" + v4t3 + ") \"embedstr\"\n })\n}"
  586. addDumpTest(v4, "("+v4t+") "+v4s+"\n")
  587. addDumpTest(pv4, "(*"+v4t+")("+v4Addr+")("+v4s+")\n")
  588. addDumpTest(&pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")("+v4s+")\n")
  589. addDumpTest(nv4, "(*"+v4t+")(<nil>)\n")
  590. }
  591. func addUintptrDumpTests() {
  592. // Null pointer.
  593. v := uintptr(0)
  594. pv := &v
  595. vAddr := fmt.Sprintf("%p", pv)
  596. pvAddr := fmt.Sprintf("%p", &pv)
  597. vt := "uintptr"
  598. vs := "<nil>"
  599. addDumpTest(v, "("+vt+") "+vs+"\n")
  600. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
  601. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  602. // Address of real variable.
  603. i := 1
  604. v2 := uintptr(unsafe.Pointer(&i))
  605. nv2 := (*uintptr)(nil)
  606. pv2 := &v2
  607. v2Addr := fmt.Sprintf("%p", pv2)
  608. pv2Addr := fmt.Sprintf("%p", &pv2)
  609. v2t := "uintptr"
  610. v2s := fmt.Sprintf("%p", &i)
  611. addDumpTest(v2, "("+v2t+") "+v2s+"\n")
  612. addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n")
  613. addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n")
  614. addDumpTest(nv2, "(*"+v2t+")(<nil>)\n")
  615. }
  616. func addUnsafePointerDumpTests() {
  617. // Null pointer.
  618. v := unsafe.Pointer(uintptr(0))
  619. nv := (*unsafe.Pointer)(nil)
  620. pv := &v
  621. vAddr := fmt.Sprintf("%p", pv)
  622. pvAddr := fmt.Sprintf("%p", &pv)
  623. vt := "unsafe.Pointer"
  624. vs := "<nil>"
  625. addDumpTest(v, "("+vt+") "+vs+"\n")
  626. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
  627. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  628. addDumpTest(nv, "(*"+vt+")(<nil>)\n")
  629. // Address of real variable.
  630. i := 1
  631. v2 := unsafe.Pointer(&i)
  632. pv2 := &v2
  633. v2Addr := fmt.Sprintf("%p", pv2)
  634. pv2Addr := fmt.Sprintf("%p", &pv2)
  635. v2t := "unsafe.Pointer"
  636. v2s := fmt.Sprintf("%p", &i)
  637. addDumpTest(v2, "("+v2t+") "+v2s+"\n")
  638. addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n")
  639. addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n")
  640. addDumpTest(nv, "(*"+vt+")(<nil>)\n")
  641. }
  642. func addChanDumpTests() {
  643. // Nil channel.
  644. var v chan int
  645. pv := &v
  646. nv := (*chan int)(nil)
  647. vAddr := fmt.Sprintf("%p", pv)
  648. pvAddr := fmt.Sprintf("%p", &pv)
  649. vt := "chan int"
  650. vs := "<nil>"
  651. addDumpTest(v, "("+vt+") "+vs+"\n")
  652. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
  653. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  654. addDumpTest(nv, "(*"+vt+")(<nil>)\n")
  655. // Real channel.
  656. v2 := make(chan int)
  657. pv2 := &v2
  658. v2Addr := fmt.Sprintf("%p", pv2)
  659. pv2Addr := fmt.Sprintf("%p", &pv2)
  660. v2t := "chan int"
  661. v2s := fmt.Sprintf("%p", v2)
  662. addDumpTest(v2, "("+v2t+") "+v2s+"\n")
  663. addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n")
  664. addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n")
  665. }
  666. func addFuncDumpTests() {
  667. // Function with no params and no returns.
  668. v := addIntDumpTests
  669. nv := (*func())(nil)
  670. pv := &v
  671. vAddr := fmt.Sprintf("%p", pv)
  672. pvAddr := fmt.Sprintf("%p", &pv)
  673. vt := "func()"
  674. vs := fmt.Sprintf("%p", v)
  675. addDumpTest(v, "("+vt+") "+vs+"\n")
  676. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
  677. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  678. addDumpTest(nv, "(*"+vt+")(<nil>)\n")
  679. // Function with param and no returns.
  680. v2 := TestDump
  681. nv2 := (*func(*testing.T))(nil)
  682. pv2 := &v2
  683. v2Addr := fmt.Sprintf("%p", pv2)
  684. pv2Addr := fmt.Sprintf("%p", &pv2)
  685. v2t := "func(*testing.T)"
  686. v2s := fmt.Sprintf("%p", v2)
  687. addDumpTest(v2, "("+v2t+") "+v2s+"\n")
  688. addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n")
  689. addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n")
  690. addDumpTest(nv2, "(*"+v2t+")(<nil>)\n")
  691. // Function with multiple params and multiple returns.
  692. var v3 = func(i int, s string) (b bool, err error) {
  693. return true, nil
  694. }
  695. nv3 := (*func(int, string) (bool, error))(nil)
  696. pv3 := &v3
  697. v3Addr := fmt.Sprintf("%p", pv3)
  698. pv3Addr := fmt.Sprintf("%p", &pv3)
  699. v3t := "func(int, string) (bool, error)"
  700. v3s := fmt.Sprintf("%p", v3)
  701. addDumpTest(v3, "("+v3t+") "+v3s+"\n")
  702. addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s+")\n")
  703. addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s+")\n")
  704. addDumpTest(nv3, "(*"+v3t+")(<nil>)\n")
  705. }
  706. func addCircularDumpTests() {
  707. // Struct that is circular through self referencing.
  708. type circular struct {
  709. c *circular
  710. }
  711. v := circular{nil}
  712. v.c = &v
  713. pv := &v
  714. vAddr := fmt.Sprintf("%p", pv)
  715. pvAddr := fmt.Sprintf("%p", &pv)
  716. vt := "spew_test.circular"
  717. vs := "{\n c: (*" + vt + ")(" + vAddr + ")({\n c: (*" + vt + ")(" +
  718. vAddr + ")(<already shown>)\n })\n}"
  719. vs2 := "{\n c: (*" + vt + ")(" + vAddr + ")(<already shown>)\n}"
  720. addDumpTest(v, "("+vt+") "+vs+"\n")
  721. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs2+")\n")
  722. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs2+")\n")
  723. // Structs that are circular through cross referencing.
  724. v2 := xref1{nil}
  725. ts2 := xref2{&v2}
  726. v2.ps2 = &ts2
  727. pv2 := &v2
  728. ts2Addr := fmt.Sprintf("%p", &ts2)
  729. v2Addr := fmt.Sprintf("%p", pv2)
  730. pv2Addr := fmt.Sprintf("%p", &pv2)
  731. v2t := "spew_test.xref1"
  732. v2t2 := "spew_test.xref2"
  733. v2s := "{\n ps2: (*" + v2t2 + ")(" + ts2Addr + ")({\n ps1: (*" + v2t +
  734. ")(" + v2Addr + ")({\n ps2: (*" + v2t2 + ")(" + ts2Addr +
  735. ")(<already shown>)\n })\n })\n}"
  736. v2s2 := "{\n ps2: (*" + v2t2 + ")(" + ts2Addr + ")({\n ps1: (*" + v2t +
  737. ")(" + v2Addr + ")(<already shown>)\n })\n}"
  738. addDumpTest(v2, "("+v2t+") "+v2s+"\n")
  739. addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s2+")\n")
  740. addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s2+")\n")
  741. // Structs that are indirectly circular.
  742. v3 := indirCir1{nil}
  743. tic2 := indirCir2{nil}
  744. tic3 := indirCir3{&v3}
  745. tic2.ps3 = &tic3
  746. v3.ps2 = &tic2
  747. pv3 := &v3
  748. tic2Addr := fmt.Sprintf("%p", &tic2)
  749. tic3Addr := fmt.Sprintf("%p", &tic3)
  750. v3Addr := fmt.Sprintf("%p", pv3)
  751. pv3Addr := fmt.Sprintf("%p", &pv3)
  752. v3t := "spew_test.indirCir1"
  753. v3t2 := "spew_test.indirCir2"
  754. v3t3 := "spew_test.indirCir3"
  755. v3s := "{\n ps2: (*" + v3t2 + ")(" + tic2Addr + ")({\n ps3: (*" + v3t3 +
  756. ")(" + tic3Addr + ")({\n ps1: (*" + v3t + ")(" + v3Addr +
  757. ")({\n ps2: (*" + v3t2 + ")(" + tic2Addr +
  758. ")(<already shown>)\n })\n })\n })\n}"
  759. v3s2 := "{\n ps2: (*" + v3t2 + ")(" + tic2Addr + ")({\n ps3: (*" + v3t3 +
  760. ")(" + tic3Addr + ")({\n ps1: (*" + v3t + ")(" + v3Addr +
  761. ")(<already shown>)\n })\n })\n}"
  762. addDumpTest(v3, "("+v3t+") "+v3s+"\n")
  763. addDumpTest(pv3, "(*"+v3t+")("+v3Addr+")("+v3s2+")\n")
  764. addDumpTest(&pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")("+v3s2+")\n")
  765. }
  766. func addPanicDumpTests() {
  767. // Type that panics in its Stringer interface.
  768. v := panicer(127)
  769. nv := (*panicer)(nil)
  770. pv := &v
  771. vAddr := fmt.Sprintf("%p", pv)
  772. pvAddr := fmt.Sprintf("%p", &pv)
  773. vt := "spew_test.panicer"
  774. vs := "(PANIC=test panic)127"
  775. addDumpTest(v, "("+vt+") "+vs+"\n")
  776. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
  777. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  778. addDumpTest(nv, "(*"+vt+")(<nil>)\n")
  779. }
  780. func addErrorDumpTests() {
  781. // Type that has a custom Error interface.
  782. v := customError(127)
  783. nv := (*customError)(nil)
  784. pv := &v
  785. vAddr := fmt.Sprintf("%p", pv)
  786. pvAddr := fmt.Sprintf("%p", &pv)
  787. vt := "spew_test.customError"
  788. vs := "error: 127"
  789. addDumpTest(v, "("+vt+") "+vs+"\n")
  790. addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
  791. addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
  792. addDumpTest(nv, "(*"+vt+")(<nil>)\n")
  793. }
  794. // TestDump executes all of the tests described by dumpTests.
  795. func TestDump(t *testing.T) {
  796. // Setup tests.
  797. addIntDumpTests()
  798. addUintDumpTests()
  799. addBoolDumpTests()
  800. addFloatDumpTests()
  801. addComplexDumpTests()
  802. addArrayDumpTests()
  803. addSliceDumpTests()
  804. addStringDumpTests()
  805. addInterfaceDumpTests()
  806. addMapDumpTests()
  807. addStructDumpTests()
  808. addUintptrDumpTests()
  809. addUnsafePointerDumpTests()
  810. addChanDumpTests()
  811. addFuncDumpTests()
  812. addCircularDumpTests()
  813. addPanicDumpTests()
  814. addErrorDumpTests()
  815. t.Logf("Running %d tests", len(dumpTests))
  816. for i, test := range dumpTests {
  817. buf := new(bytes.Buffer)
  818. spew.Fdump(buf, test.in)
  819. s := buf.String()
  820. if testFailed(s, test.wants) {
  821. t.Errorf("Dump #%d\n got: %s %s", i, s, stringizeWants(test.wants))
  822. continue
  823. }
  824. }
  825. }