Page 1 of 1

[Implemented] #PB_Compiler_MainFile/PB_Compiler_IncludedFile

Posted: Wed Jul 12, 2006 12:56 pm
by GedB
Python has a clever little trick for testing modules.

They use code like this

Code: Select all

   if __name__ == "__main__":
      TestingOne
      TestingTwo
      TestingThree
http://diveintopython.org/getting_to_kn ... dules.html

This means that if they run the module code directly, their code will be executed.

However, if the code has been included by another package, it will not be run.

I'd love to be able to do this in PB, and it wouldn't need much to make it possible, all thats needed is the contstants #PB_Compiler_MainFile and #PB_Compiler_IncludedFile.

#PB_Compiler_MainFile is true if the file being compile is the one in which the user was in when they hit compile, false otherwise.

#PB_Compiler_IncludedFile is true if the file being compiled has been included by another file.

Then I can say

Code: Select all

  CompilerIf #PB_Compiler_MainFile = #True
    ; some testing code
  CompilerEndIf
Think about the usefulness of this.

Imagine I have a library for functions for a HashMap, for example, it can include a set of unit test scripts within a block like the above.

Now I'm working on some other code that uses the HashMap, and I decide that I need to change some stuff in the HashMap to make it easier to work with.

At the moment I have to click on the HashMap, make my changes, and then click back to my main file and test it. If I break something in the HashMap by mistake it can be tricky.

If I had the above, I could switch to my HashMap and make my changes. Then I could run it with F5 and see the results of my tests. Once I was happy that it was all working I could swich back to my main file and carry on from there.

So what do you say? What if I say pretty please with a cherry on top? :D

Posted: Wed Jul 12, 2006 1:03 pm
by Flype
i agree,
as i was a python-user, i was also wondering about something like this.