Sometimes I run unit tests on ClarionMagLibrary (CML) code, and sometimes on non-CML code. When I run the latter I may or may not want to include the CML library, but when I run the former I usually want to compile the code directly so I don't have to remember whether I'm testing a library change or a unit test change. It's also usually an advantage to test against a local compile until I'm sure everything is working - that way I'm not breaking any code that does use the library.
...
Code Block | ||
---|---|---|
| ||
#EXTENSION(TestSupportIncludes,'Add global includes for test support'),APPLICATION,DESCRIPTION('[ClarionTest] Global Includes for Test Support')
#DISPLAY
#Prompt('Compile ClarionMag Library source',Check),%CompileClarionMagLibrarySource,At(10,,180)
#Enable(%CompileClarionMagLibrarySource=%false)
#Prompt('Include the ClarionMag library',check),%IncludeClarionMagLib,default(%true),At(10,,180)
#EndEnable
#PROMPT('Generate help comments',CHECK),%ShowHelpComments,Default(%False),At(10,,180)
#DISPLAY('You can add the name of your Class .INC files below. The INCLUDE directive will be added for you.'),AT(10,,180,24)
#BOXED('Class .INC Files')
#PROMPT('Class .INC File:',@S200),%TestClasses,MULTI('Class .INC File')
#ENDBOXED
#!**********
#ATSTART
#IF(VAREXISTS(%TestGroups) AND ITEMS(%TestGroups) = 0)
#ADD(%TestGroups,'Default')
#ENDIF
#If(%CompileClarionMagLibrarySource)
#Set(%IncludeClarionMagLib,%False)
#PDefine('_Compile_CML_Class_Source_',1)
#Else
#PDefine('_Compile_CML_Class_Source_',0)
#EndIf
#ENDAT
#AT(%CustomGlobalDeclarations),where(%IncludeClarionMagLib)
#PROJECT('CMagLib.lib')
#ENDAT
|
In the #ATSTART section I added some code to set the project defines, using the #PDEFINE statement. The help says this about #PDEFINE:
Panel | ||||||
---|---|---|---|---|---|---|
#PDEFINE ( symbol, value )
The #PDEFINE statement adds a #pragma (compiler option) statement to the project system. A pragma is added to the project file in the form of symbol => value. Example: #IF (%DemoVersion) #PDEFINE('_DEMO_',1) #ELSE #PDEFINE('_DEMO_',0) #ENDIF |
And here are the new template prompts:
There's one possible problem here, which is that although the Include the ClarionMag library prompt is disabled, if checked it remains checked, and that looks confusing. The fix is to write some template code that clears the checkbox via the WhenAccepted attribute:
Code Block |
---|
#Prompt('Compile ClarionMag Library source',Check),%CompileClarionMagLibrarySource,At(10,,180),WhenAccepted(%ClearCompileClarionMagLibrarySourceIfNecessary(%CompileClarionMagLibrarySource,%IncludeClarionMagLib))
...
#Group(%ClearCompileClarionMagLibrarySourceIfNecessary,*%pCompileClarionMagLibrarySource,*%pIncludeClarionMagLib)
#If(%pCompileClarionMagLibrarySource=%true)
#Set(%pIncludeClarionMagLib,%False)
#EndIf |
Notice that the #Group receives parameters by address - if you pass the parameters by value they will not be updated in the prompt section, and because the variables aren't globally declared they must be passed.
This introduces another problem, however, which is that if I originally needed the CML but for testing compile it, when I uncheck the first option I've lost the second one. So the better option I think is to remove the WhenAccepted attribute and hide the second option when the first one is selected.
Hiding #PROMPTs is a bit non-obvious. You need to wrap the prompt in a #BOXED/#ENDBOXED section with a WHERE clause:
Code Block |
---|
#Boxed,Where(%CompileClarionMagLibrarySource=%false) #Prompt('Include the ClarionMag library',check),%IncludeClarionMagLib,default(%true),At(10,,180) #EndBoxed |
The second prompt now disappears when the first is selected:
And of course the all-important project define is set to either 0 or 1 according to the first option: