41 #include "autodetect.h"
97 std::ofstream File(TempFile.c_str());
98 File << TestsToWrite.GetAsXML();
111 UnitTestGroup Results;
113 pugi::xml_document Doc;
115 std::ifstream InputFile(TempFile.c_str());
116 pugi::xml_parse_result LoadResults = Doc.load(InputFile);
120 Results.AddTestsFromXML(Doc.first_child());
122 std::stringstream FailStream;
123 FailStream <<
"Failure loading tempfile from SubProcess: "
124 << LoadResults.description() << std::endl
125 <<
"At " << LoadResults.offset <<
" bytes into the file.";
126 throw runtime_error(FailStream.str());
139 std::ofstream FileToClear;
140 FileToClear.open(TempFile.c_str(),std::ios_base::out|std::ios_base::trunc);
146 { std::remove(TempFile.c_str()); }
170 UnitTestGroup::ShouldRunAutomaticTests();
178 UnitTestGroup::ShouldRunInteractiveTests();
186 UnitTestGroup::ShouldRunSubProcessTests();
207 TestGroups(GlobalTestGroups)
217 void ExecuteSubTest()
219 for(std::vector<Mezzanine::String>::iterator CurrentTestName=TestGroupsToRun.begin(); CurrentTestName!=TestGroupsToRun.end(); ++CurrentTestName )
221 if(DoInteractiveTest)
222 { TestGroups[*CurrentTestName]->ShouldRunInteractiveTests(); }
224 { TestGroups[*CurrentTestName]->ShouldRunAutomaticTests(); }
225 TestGroups[*CurrentTestName]->RunTests();
226 (*this) += *(TestGroups[*CurrentTestName]);
232 void IterateSubtests()
234 setvbuf(stdout, NULL, _IONBF, 0);
235 for(std::vector<Mezzanine::String>::iterator CurrentTestName=TestGroupsToRun.begin(); CurrentTestName!=TestGroupsToRun.end(); ++CurrentTestName )
239 if(system(SubprocessInvocation.c_str()))
241 printf(
"%s", (SubprocessInvocation+
String(
" - Failure")).c_str() );
244 printf(
"%s", (SubprocessInvocation+
String(
" - Success")).c_str() );
245 this->AddTestResult(
String(
"Process::" + *CurrentTestName),
Success);
251 }
catch (std::exception& e) {
252 TestError << e.what() << endl;
264 if (DoAutomaticTest==DoInteractiveTest && DoInteractiveTest==
false)
265 { DoAutomaticTest=
true; }
269 for(map<String,UnitTestGroup*>::iterator Iter=TestGroups.begin(); Iter!=TestGroups.end(); ++Iter)
270 { TestGroupsToRun.push_back(Iter->first); }
289 std::ostream& Error=std::cerr,
291 bool FullOutput =
true,
292 bool HeaderOutput =
true)
298 UnitTestGroup::DisplayResults(Output, Error, Summary, FullOutput, HeaderOutput);
303 UnitTestGroup::DisplayResults(Output, Error, Summary, FullOutput, HeaderOutput);
332 int main(
int argc,
char** argv)
338 GlobalCoreTestGroup TestGroups;
339 bool WriteFile =
true;
341 if( !system( NULL ) )
343 std::cerr <<
"system() call not supported, missing command processor." << std::endl;
348 bool FullDisplay =
true, SummaryDisplay =
true;
353 {
return Usage(
"UnitTestGroups", TestGroups); }
357 for (
int c=1; c<argc; ++c)
362 else if(ThisArg==MemSpaceArg)
365 Depth = TestSubSubProcess;
367 else if(ThisArg==
"testlist")
369 else if(ThisArg==
"interactive")
371 else if(ThisArg==
"automatic")
373 else if(ThisArg==
"all")
375 else if(ThisArg==
"summary")
376 { FullDisplay =
false, SummaryDisplay =
true; }
377 else if(ThisArg==
"skipfile")
378 { WriteFile =
false; }
381 if(ThisArg.size() > SubTestPrefix.size())
383 if( ThisArg.substr(0,SubTestPrefix.size()) == SubTestPrefix)
385 Depth = TestSubSubProcess;
386 ThisArg = ThisArg.substr(SubTestPrefix.size(), ThisArg.size()-SubTestPrefix.size());
387 GlobalCoreTestGroup::iterator SearchResult = TestGroups.find(ThisArg);
388 if(TestGroups.end()==SearchResult)
390 std::cerr << ThisArg <<
" appears to be a request to debug a sub-process that does not exist." << std::endl;
394 if(!SearchResult->second->HasSubprocessTest())
396 std::cerr << ThisArg <<
" appears to be a request to debug a sub-process that does not have a sub process." << std::endl;
400 SearchResult->second->ShouldRunSubProcessTests();
403 GlobalCoreTestGroup::iterator Found = TestGroups.find(
String(ThisArg.c_str()));
404 if(Found != TestGroups.end())
413 std::cerr << ThisArg <<
" is not a valid testgroup or parameter." << std::endl;
425 String FileName(
"TestResults.txt");
426 std::ofstream OutFile(FileName.c_str());
427 Runner.
DisplayResults(OutFile, OutFile, SummaryDisplay, FullDisplay);
431 { Runner.
DisplayResults(cout, cerr, SummaryDisplay, FullDisplay); }
433 for(AllUnitTestGroups::iterator Iter = Runner.begin(); Iter!=Runner.end(); Iter++)
Mezzanine::String GetExecutableName()
Get the command/executable name used to invoke this at the command prompt.
char ** ArgV
ArgC as it was passed into Main.
void ClearTempFile()
Empty the file specified by TempFile.
int ArgC
ArgC as it was passed into Main.
AllUnitTestGroups(GlobalCoreTestGroup &GlobalTestGroups)
Constructor.
Mezzanine::String CommandName
This will store the name of the command that launched this executable at run time.
At least one test return worse then skipped.
virtual void DisplayResults(std::ostream &Output=std::cout, std::ostream &Error=std::cerr, bool Summary=true, bool FullOutput=true, bool HeaderOutput=true)
Display the results either to the console or to the temp file for the main process to pick up...
UnitTestGroup GetResultsFromTempFile()
This will open then parse the contents of the file specified by TempFile and interpret any test resul...
void WriteTempFile(const UnitTestGroup &TestsToWrite)
Write the passed UnitTestGroup to an XML temp file.
ProcessDepth GetCurrentProcessDepth()
Indicates what this test might attempt to do, based on what it thinks the process depth is...
All the definitions for datatypes as well as some basic conversion functions are defined here...
At least some invalid args were passed on the command line.
Test was simply not ran at the behest of the user.
GlobalCoreTestGroup & TestGroups
A collection of all the test groups.
Indicates an abnormal termination of a Workunit or other failure, Likely the whole application will n...
int Usage(Mezzanine::String ThisName, CoreTestGroup &TestGroups)
Print a message for the user onf the standard output that briefly describes hwo to use this...
virtual void ShouldRunSubProcessTests()
Tells this whether or not it should be used to run any tests that child tests might want to spwan in ...
virtual void ShouldRunInteractiveTests()
This indicates we should run interactive tests rather than than launching a subprocess for that...
virtual void ShouldRunAutomaticTests()
This indicates we should run automatic tests rather than than launching a subprocess for that...
Mezzanine::String GetSubSubProcessArgument()
If a test needs to pass a string to a subsubprocess it will get stored here.
int PrintList(CoreTestGroup &TestGroups)
Print all the groups that exist in a given CoreTestGroup.
ProcessDepth Depth
The current process depth as interpretted by Main.
Mezzanine::String SubSubProcessArgument
A string intended for use by any subsubprocess test.
Normal exit all tests skipped or better.
int main(int argc, char **argv)
This is the entry point for the unit test executable.
virtual void RunTests()
Determine which tests need to be run and run them.
void DeleteTempFile()
Attempts to delete TempFile. Silently fails if not possible.
int GetMainArgumentCount()
Get the argument count as it was passed into Main.
char * AllLower(char *StringToConvert)
Makes a c style stron all lowercase with respect to the current locale.
virtual void ShouldRunAllTests()
Used to signal.
virtual void DontRunAllTests()
Used to signal that none or only a subset of tests should run.
Test was ran and appeared to work.
char ** GetMainArgumentVector()
Get the argument vector as it was passed into Main.
void HandleSingleArgument(Mezzanine::String Arg)
Handles one argument at a time for main.
std::vector< Mezzanine::String > TestGroupsToRun
When determining what tests to run the name are aggregated here.
std::string String
A datatype used to a series of characters.
This aggregates the results of all the other test groups.