Mr. Cluey
: Classes : CPerlCPerl. CPerl test. Test, Perl, test.
Let's face it; QAP manipulates windows well, but its handling of text files leaves something to be desired. Using QAP to pour through log files, or to examine HTML that has been generated, or other, possibly proprietary, file formats, is at best tedious.
Perl, with its pattern matching facilities, is far better for this type of work. Creating test scripts with Perl is easy enough, and there are a lot of books available on the language (I recommend O'Reily - the camel, not the llama). There are tests which integrate both of these tools, using the strengths of each.
CPerl gives me a common interface to all of the Perl scripts I have integrated with my QAP scripts.
The CPerl class looks approximately like this
winclass CPerl
{
string m_Source ;
string GetSource() ;
list of string Run( string sArgs optional ) ;
}
GetSource identifies the script file to be run. The default behavior is to simply pass back m_Source. However, if that variable has not been set, it will attempt to use the WindowTag to identify the script name.
This sounds odd, but is well founded. I had two distinct uses for this class in mind. The first declares the Perl application in advance, and specifies the source directly. The second creates a temporary instance of the class, on the fly as it were.
window CPerl plMyApp { string m_Source = "MyApp.pl" ; }
main ()
{
//These two calls are equivalent
plMyApp.Run () ;
CPerl("MyApp.pl") ;
}
Run calls GetSource() to identify which script to run. Having done so, it creates the command line (using sArgs if it has been supplied) and calls SYS_Execute to get the results.
The only tricky part is specifying the path to the PERL executable. You could insist that perl.exe reside in the same location on everybody's machine. Instead, I use the compiler variable PERL_EXE to specify the path to the exe.
Here are some tasks where testing with Perl can be helpful.
If you find the interface easier to work with, you might implement Run with a vararg list, which moves the burden of arranging the order of the parameters from the scripts to the class. This is certainly a good idea.
But why stop with CPerl? A generic CSysApp works just as well - each type of application derrived from CSysApp specifies which application it uses, and the base class can handle all of the gory details.
| Mr. Cluey : Classes : CPerl |