I'm testing my module's procedures in an external test module. This works great 
for public procedures but not at all for private ones since they are not 
exported. I have been exporting these just so I can write test code. This has 
the drawback that the public interface of the module is bigger than it needs to 
be.

An alternate scheme is to use the isMainModule variable and test the code 
inside this block inside the main module. This works well for the private 
procedures, but not as well for the public ones, since this environment is a 
lot different than how the user accesses the procedures.

Another alternate scheme is to use both approaches, extern modules for the 
public procedures and inside the main module for the private procedures. This 
has the disadvantage that the module's tests are in two places and both need to 
be run.

If there was a good way to conditional make a procedure public, for example 
public in normal builds and private when release is defined, that would allow 
you to put all the test code for a module in its test module. The test code 
would have to be inside a "when not defined(release):" block. This sounds like 
a good approach to me.

Is there already a good solution to this issue? If not, is it possible to come 
up with a good way to do this using templates or macros?, that is more elegant 
than:
    
    
    when defined(release):
      proc myPrivate(value: uint8): string =
        ...
    else:
      proc myPrivate *(value: uint8): string =
        ...
    

Something like:
    
    
    dpub = ???
    proc myPrivate dpub(value: uint8): string =
        ...
    

Reply via email to