Hacker News new | past | comments | ask | show | jobs | submit login

That `run` function looks to me like setting up test doubles. What makes `stderr` in this code different from a spy?



Not being a spy. :-) It's an array that's populated by an event listener.

CommandLine is the actual production code that writes to stdout and stderr (and reads command-line arguments). CommandLine.createNull() creates an instance of CommandLine that's "turned off" and doesn't actually write to stdout or stderr. CommandLine.trackStderr() returns a reference to an array that is updated whenever something is written to stderr (or not, in the case of a nulled CommandLine).

I'm off to bed, but I'm happy to answer further questions in the morning. For free, even.


Looks like we've reached max depth, but one last response for @ithkuil:

> Another case where having real production code have parts of it that can be turned off is trunk based development leveraging feature flags.

I've used Nullables to implement "dry run" capability in a command-line tool that did git stuff. Super clean—when I got the --dry-run flag, I just called Repo.createNull() rather than Repo.create().


Another case where having real production code have parts of it that can be turned off is trunk based development leveraging feature flags.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: