lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Jul 30, 2014 at 10:23 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2014-07-31 6:37 GMT+02:00 Coda Highland <chighland@gmail.com>:
>> On Wed, Jul 30, 2014 at 7:03 PM, albert_200200 <albert_200200@126.com> wrote:
>>> Really thanks for your quick reply. Your following meaning I didn't
>>> understand well. Do you mean every method I want to make sure it's correct
>>> and to test,  I should make this method public, Is that your meaning?
>>
>> No, that's the opposite of what I was trying to say. I'm trying to say
>> that tests shouldn't be poking at the internals. Tests should be just
>> like user code -- they should test the functions that the user can
>> call, and the private functions should be implementation details that
>> the tests shouldn't have to know about.
>>
>> The other part I was saying is that there are ways to work around it
>> if, in the end, you decide that you have some internal function that
>> REALLY, REALLY needs tested on its own but shouldn't be exposed to the
>
> One of my first lessons as a young programmer was taught to
> me by my boss, who himself was a mathematician who did
> not write programs. It was:
>
>    A program without documentation is totally useless;
>    documentation without a program is very useful.
>
> I dismissed it as typical of the person who was saying it, and
> told him so (it was that kind of organization). He "explained"
> by handing me the specifications of a program, part of
> a closed-source package, that could evaluate an integral
> numerically to high precision. Then he told me to go and write
> a program that could do what was described, with exactly the
> same Fortran interface.
>
> Any software you make public should have documentation
> as accurate as the Lua manual, and your testing should be
> designed to check that it does what your manual says.
>
> What I have done in some of my modules is to make them
> return two values. Then `require "mymod"` only accesses the
> public part, but `mymod, private = dofile"mymod.lua"` also
> returns a table containing some local functions, cached
> while they were visible. Then `lunit` or a similar tool can test
> `mymod`, and some special-purpose tool that I have control
> over can test `private`.
>

Ah, that's the way to make that work! I knew there was some trickery
that could be pulled to pull in a file in "test mode" but I hadn't yet
puzzled out how to do it.

/s/ Adam