In the previous chapter, I changed some code so that it wouldn’t produce output and instead did the output in the MAIN sub, which conveniently went untested.
Changing code to make it easier to test is a legitimate practice. But if you do have to test code that produces output by calling say, there’s a small trick you can use: say works on a file handle, and you can swap out the default file handle, which is connected to standard output. Instead of the default, you can put a dummy file handle in its place that captures the lower-level commands issued to it and record this for testing.