Re: [go-nuts] Re: testing examples printing to stdout not working for global var

2022-05-02 Thread 'simon place' via golang-nuts
actually just changing Example's to Test's with a string comparison seems to have the least friction. On Monday, 2 May 2022 at 21:57:29 UTC+1 simon place wrote: > i see, thanks > > the implementation of 'go test' (which the playground runs > auto-magically.) replaces os.Stdout with a new refere

Re: [go-nuts] Re: testing examples printing to stdout not working for global var

2022-05-02 Thread burak serdar
On Mon, May 2, 2022 at 2:57 PM 'simon place' via golang-nuts < golang-nuts@googlegroups.com> wrote: > i see, thanks > > the implementation of 'go test' (which the playground runs > auto-magically.) replaces os.Stdout with a new reference behind the scenes > before running the func, but after makin

Re: [go-nuts] Re: testing examples printing to stdout not working for global var

2022-05-02 Thread 'simon place' via golang-nuts
i see, thanks the implementation of 'go test' (which the playground runs auto-magically.) replaces os.Stdout with a new reference behind the scenes before running the func, but after making global vars, so the code as written isn't strictly 'go' anymore. https://go.dev/play/p/3FBjOmzYIiz?v=gop

Re: [go-nuts] Re: testing examples printing to stdout not working for global var

2022-05-02 Thread burak serdar
On Mon, May 2, 2022 at 9:00 AM psi@gmail.com wrote: > #1 the two functions need to behave identically according to the syntax of > the language. > > #2 this is how working code operates, so testing needs to be able to > handle it. > > at a guess; 'testing' would appear to have some non-compli

Re: [go-nuts] Re: testing examples printing to stdout not working for global var

2022-05-02 Thread 'Sean Liao' via golang-nuts
Code needs to be written to be testable. Peter is correct, you've taken a reference to an uninstrumented os.Stdout. What you've written isn't identical wrt to the evaluation of stdout, so can't be expected to perform identically. -- You received this message because you are subscribed to the Goog

[go-nuts] Re: testing examples printing to stdout not working for global var

2022-05-02 Thread peterGo
Please follow the Go Community Code of Conduct while posting here. https://go.dev/conduct On Monday, May 2, 2022 at 11:00:14 AM UTC-4 psi@gmail.com wrote: > #1 the two functions need to behave identically according to the syntax of > the language. > > #2 this is how working code operates,

[go-nuts] Re: testing examples printing to stdout not working for global var

2022-05-02 Thread psi....@gmail.com
#1 the two functions need to behave identically according to the syntax of the language. #2 this is how working code operates, so testing needs to be able to handle it. at a guess; 'testing' would appear to have some non-compliant reflection going on, in this edge-case. but anyway; your reply

[go-nuts] Re: testing examples printing to stdout not working for global var

2022-05-01 Thread peterGo
It looks like you have a bug in your code. "In tests, standard output is accumulated during execution and dumped to standard output when done." "Example functions may include a concluding line comment that begins with "Output:" and is compared with the standard output of the function when the