46 function checkCUnit($fileName)
51 return(array(
"Error! illegal input $fileName"));
54 $verFail = check4CUnitFail($fileName);
55 if(!is_null($verFail))
66 return(array(
"Error! $e\n"));
77 function genCunitRep($fileName)
85 $xslFile =
"CUnit-Run.xsl";
86 if(preg_grep(
"/Results/", array($fileName)))
88 $xslFile =
"CUnit-Run.xsl";
90 else if(preg_grep(
"/Listing/", array($fileName)))
92 $xslFile =
"CUnit-List.xsl";
95 $outFile = basename($fileName,
'.xml');
96 $outPath = TESTROOT .
"/reports/unit/$outFile.html";
97 $xslPath =
"/usr/share/CUnit/$xslFile";
99 $rmLast = exec(
"rm -rf $outPath", $rmOut, $rmRtn);
101 $report = genHtml($fileName, $outPath, $xslPath);
104 echo
"Error: Could not generate a HTML Test report from $fileName.\n";
118 function processCUnit($unitTest)
123 $unitTest = preg_replace(
'#/#',
'-', $unitTest);
126 if ($libphp === $unitTest)
return NULL;
130 return(
"Error! no valid input at line " . __FILE__ .
" at line " .
134 foreach(glob(
"$unitTest*.xml") as $fName)
136 $fileName = lcfirst($fName);
138 if(preg_grep(
"/Listing/", array($fileName)))
140 $rmlast = exec(
"rm $fileName", $rmOut, $rmRtn);
143 if(!tweakCUnit($fileName))
145 return(
"Error! could not save processed xml file, they may not display properly\n");
150 $errors = checkCUnit($fileName);
152 if(is_object($errors[0]))
155 echo
"There were Unit Test Failures in $unitTest\n";
158 else if(!is_NULL($errors))
162 return(
"Failure: Could not check file $fileName for failures is the file corrupt?\n");
165 if(!genCunitRep($fileName))
167 return(
"Error!, could not generate html report for $unitTest\n");
182 function tweakCUnit($fileName)
190 $rFile = file_get_contents($fileName);
193 $replace =
'href="http://fossology.usa.hp.com/~fossology/dtds/';
194 $rFile = preg_replace($pat, $replace, $rFile);
196 $runPat =
'/CUnit-Run\.dtd/';
197 $rReplace =
'http://fossology.usa.hp.com/~fossology/dtds/CUnit-Run.dtd';
198 $listPat =
'/CUnit-List\.dtd/';
199 $lReplace =
'http://fossology.usa.hp.com/~fossology/dtds/CUnit-List.dtd';
200 $rFile = preg_replace($runPat, $rReplace, $rFile);
201 $rFile = preg_replace($listPat, $lReplace, $rFile);
203 if(!file_put_contents($fileName, $rFile))
216 if(!defined(
'TESTROOT'))
219 $plenth = strlen($path);
221 $TESTROOT = substr($path, 0, $plenth-5);
222 $_ENV[
'TESTROOT'] = $TESTROOT;
223 putenv(
"TESTROOT=$TESTROOT");
224 define(
'TESTROOT',$TESTROOT);
229 if(array_key_exists(
'WORKSPACE', $_ENV))
231 $WORKSPACE = $_ENV[
'WORKSPACE'];
232 define(
'WORKSPACE', $WORKSPACE);
235 $unit = TESTROOT .
"/unit";
237 if(@chdir($unit) === FALSE)
239 echo
"FATAL!, could not cd to:\n$unit\n";
242 require_once(
'../lib/bootstrap.php');
243 require_once(
'../lib/common-Report.php');
244 require_once(
'../lib/common-Test.php');
245 require_once(
'../lib/createRC.php');
248 $sc = getenv(
'SYSCONFDIR');
249 echo
"DB: runUnit: sysconf from getenv is:$sc\n";
255 echo
"DB: runUnit: globals:sysconfdir:{$GLOBALS['SYSCONFDIR']}\n";
256 putenv(
"SYSCONFDIR=$sc");
257 $_ENV[
'SYSCONFDIR'] = $sc;
259 echo
"DB: runUnit: after putenv SYSCONFDIR from env is:" . getenv(
'SYSCONFDIR') .
"\n";
260 echo
"DB: runUnit: after _ENV set, SYSCONFDIR from _ENV is:{$_ENV['SYSCONFDIR']}\n";
266 $modules = parse_ini_file(
'../dataFiles/unitTests.ini',1);
267 foreach($modules as $key => $value)
278 backToParent(
'../..');
281 foreach($unitList as $unitTest)
285 $other = substr($unitTest, 0, 3);
286 if($other ==
'lib' || $other ==
'cli')
288 if(@chdir($unitTest .
'/tests') === FALSE)
290 echo
"Error! cannot cd to " . $unitTest .
"/tests, skipping test\n";
297 if(@chdir($unitTest .
'/agent_tests/Unit') === FALSE)
299 echo
"Error! cannot cd to " . $unitTest .
"/agent_tests/Unit, skipping test\n";
304 $Make =
new RunTest($unitTest);
305 $runResults = $Make->MakeTest();
307 $Make->printResults($runResults);
308 if(processCUnit($unitTest) != NULL)
310 echo
"Error: could not process cunit results file for $unitTest\n";
312 if(MakeCover($unitTest) != NULL)
317 backToParent(
'../../..');
class for making an agent unit or functional test
bootstrap($sysconfdir="")
Bootstrap the fossology php library.