[Implemented] #PB_Compiler_MainFile/PB_Compiler_IncludedFile

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

[Implemented] #PB_Compiler_MainFile/PB_Compiler_IncludedFile

Post 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
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

i agree,
as i was a python-user, i was also wondering about something like this.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Post Reply