S
Stephen Sprunk
That depends upon how you define unit tests. For purposes of unit
testing, I treat functions with internal linkage as part of the
function(s) with external linkage in the same translation unit that
(directly or indirectly) call them. If they have any feature which
cannot be properly tested through calls to those externally linked
functions, then that generally means that the feature is either
unnecessary or at least badly designed.
To me, the purpose of unit testing is to prove the code is correct (as
defined by the design docs), and one cannot prove a function is correct
until you've proven that all the functions it _calls_ are correct. I've
chased down too many bugs where function X calls function Y with an
invalid argument and got a result that seemed reasonable--until one day
(or once in a blue moon) it didn't. If you test function Y, that's one
less thing to worry about when testing (or troubleshooting) function X.
No, but it can dramatically increase that limit. Well-designed programs
stress your short-term memory capacity much less than poorly designed
programs, because they're easier to understand.
Fair enough, though I think of "large" in terms of complexity rather
than absolute size. A short, complex function can test my mental limits
more than a long, simple one; the former is also more likely to contain
hidden bugs, and that seems like inherently bad design.
For an example, just look at the IOCCC; most submissions are mercifully
short yet more mentally taxing than a typical real-world program that's
ten or even a hundred times their size. And I still don't understand
that "RSA in 5 lines" Perl T-shirt, which puts even most IOCCC code to
shame.
S