Re: Unit-testing in same file

new topic     » goto parent     » topic index » view thread      » older message » newer message
SnakeCharmer said...

Is it possible to test function in same myfunc.e, not in separate t_myfunc.e? For example, I need Luhn algorithm for verifying credit cards.

http://rosettacode.org/wiki/Luhn_test#Euphoria

When this file will be started, it will check an algorithm correctness. It that is necessary for me. But if I import this file to the program, the constant cc_numbers is imported and the for-cycle will be executed, which are absolutely not necessary to me. Besides it would be desirable not to lose possibility of the automated testing.

The easiest way to do this is to put your code inside of an ifdef block:

-- mylib.e 
ifdef UNITTEST then 
  -- eutest mylib.e 
 
  -- tests go here 
end ifdef 

Then, under normal operation, the tests are skipped (the code isn't even parsed). But it's all there when you want to test it. When you call eutest, it automatically adds a "-d UNITTEST" to the command line when it invokes your program.

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu