lua-users home
lua-l archive

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


On Sat, Sep 22, 2012 at 11:55:10AM +0200, Thijs Schreijer wrote:
> The best thing I could come up with is something like this at the end of a
> module;
[snip]
> It's a small burden on production code and relies on a global '_TEST', works
> perfectly well, just wondering if there is a better approach, and if not, is
> there an accepted form of the '_TEST'  global by another name?

My approach tends to be similar.  I tend to use environment variables instead,
so that I can turn the functionality on and off during my tests and verify that
overall functionality remains the same.

Then I use special markers in the code, of the form:

-- @@BEGIN_TEST_ONLY@@

-- @@END_TEST_ONLY@@

surrounding code I want removed during installation.  My installation targets
in my makefiles then remove code from between those markers during install.

It's messy and relies on several moving parts, but it means I can unit-test the
"local" code, I can test that nothing outside the module relies on the local
code and I can remove the test code during installation so it's not doing
environment variable lookups (and potentially polluting my published API/ABI)
at runtime.

D.

-- 
Daniel Silverstone                         http://www.digital-scurf.org/
PGP mail accepted and encouraged.            Key Id: 3CCE BABE 206C 3B69