Testing fun!

Ovid on 2006-07-25T14:40:55

Since I'm trying to encourage testing at my new job, I check in code with plenty of tests. Some of today's code goes through directories and applies actions to the various files it finds in there, including moving them. A very common failure case when doing this is when the source and target have the same name. Today, I was asked what would happen if that occurs. I pointed out that this meant the file would be processed "in place" and that we needed this feature.

Him: OK, but this could break. Would you write some tests for it?
Me: Hmm, I guess I didn't do that.

... time passess ...

Me: I'll bet you enjoyed that.
Him: What?
Me: Having me write the tests because you saw the bug.
Him: What bug?

Silly me. I was writing out to the source file and then unlinking the target file. Oops. Neither of us noticed that.