I am having problems printing structure when test cases fail. This is a pointer to a fragment of pointers to structures or *[]*X The problem is that I need to know the contents of the X structures inside the slice, but I cannot get it to print the whole chain. It prints only its addresses, since it is a pointer. I need him to follow the signs.
This, however, is useless, because the function I want to test modifies their contents and modifies the test code so as not to use pointers, just means that I am not testing the code with pointers (so that this does not work).
In addition, simply moving along the slice will not work, since the real function uses reflection and can process more than one layer of pointers.
A simplified example:
package main import "fmt" func main() { type X struct { desc string } type test struct { in *[]*X want *[]*X } test1 := test{ in: &[]*X{ &X{desc: "first"}, &X{desc: "second"}, &X{desc: "third"}, }, } fmt.Printf("%#v", test1) }
Output Example:
main.test{in:(*[]*main.X)(0x10436180), want:(*[]*main.X)(nil)}
(code is at http://play.golang.org/p/q8Its5l_lL )
source share