Recent twts in reply to #kxlpuda

That’s quite a complicated hello world, @prologic :-D

My main()s often also just do os.Exit(run()). Passing the command line arguments run run(…) seems like another obvious thing to do. Even though, I should have done this more consistently, I reckon. I feel very stupid now, because for whatever reason, it never occurred to me to simply pass an io.Writer for stdout. I really like that. Although, I’m wondering why there’s nothing for stderr. Errors should definitely not mix with other output in my opinion. Anyways. When testing, I always captured stdout with a much more complicated code segment so far. Store the original output and error streams, set the new ones, execute the test, convert things to strings and finally reset to the original streams. I will definitely adopt these io.Writer arguments. Thanks, mate! :-)

This cmdtest test execution also captures the coverage? It looks kinda more complicated than it should be, otherwise. Just a program with the test definition file would be enough in my opinion.

I don’t know if I like the concept of providing a single test definition file or not. It’s a bit intriguing, but I fear that’s not flexible enough. Just a gut feeling, might be wrong.

⤋ Read More

@prologic Logging is different, I meant regular errors messages. E.g. you invoke the program with an invalid argument or something else goes wrong. That should then be reported on stderr and not stdout. When striving for a good coverage rate, error cases should not be forgotten in my opinion. Ideally, error messages are tested, too. I’ve seen a bunch of cases in the past, where something was broken, because there weren’t any tests. But to be fair, I neglect them most of time, too. :-( Just checked, go-cmdtest merges both stdout and -err, that’s a no-go in my books.

⤋ Read More

@prologic Whoops, I must have missed the error return value! That sounds good to me. When there are just fatal errors that abort the program execution, a main function returning an error is definitely enough.

Hmm, if you don’t want to report errors to stderr, where do you write them to? Hopefully not stdout. A log file? It obviously depends on the program and such, but generally I do not want to dig up errors from a log file. Usually, I find it much more convenient to see them directly. Properly dealing with stdout and stderr basically provides the capabilities for free to be pipeline-ready. And of course, -q or something along those lines is also a good choice. When talking about more serious programs, that is. Not just some quickly cobbled together helper.

⤋ Read More


Login or Register to join in on this yarn.