They use code like this
Code: Select all
if __name__ == "__main__":
TestingOne
TestingTwo
TestingThree
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
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?
