35 function checkCUnit($fileName)
40 return(array(
"Error! illegal input $fileName"));
43 $verFail = check4CUnitFail($fileName);
44 if(!is_null($verFail))
55 return(array(
"Error! $e\n"));
66 function genCunitRep($fileName)
74 $xslFile =
"CUnit-Run.xsl";
75 if(preg_grep(
"/Results/", array($fileName)))
77 $xslFile =
"CUnit-Run.xsl";
79 else if(preg_grep(
"/Listing/", array($fileName)))
81 $xslFile =
"CUnit-List.xsl";
84 $outFile = basename($fileName,
'.xml');
85 $outPath = TESTROOT .
"/reports/unit/$outFile.html";
86 $xslPath =
"/usr/share/CUnit/$xslFile";
88 $rmLast = exec(
"rm -rf $outPath", $rmOut, $rmRtn);
90 $report = genHtml($fileName, $outPath, $xslPath);
93 echo
"Error: Could not generate a HTML Test report from $fileName.\n";
107 function processCUnit($unitTest)
112 $unitTest = preg_replace(
'#/#',
'-', $unitTest);
115 if ($libphp === $unitTest)
return NULL;
119 return(
"Error! no valid input at line " . __FILE__ .
" at line " .
123 foreach(glob(
"$unitTest*.xml") as $fName)
125 $fileName = lcfirst($fName);
127 if(preg_grep(
"/Listing/", array($fileName)))
129 $rmlast = exec(
"rm $fileName", $rmOut, $rmRtn);
132 if(!tweakCUnit($fileName))
134 return(
"Error! could not save processed xml file, they may not display properly\n");
139 $errors = checkCUnit($fileName);
141 if(is_object($errors[0]))
144 echo
"There were Unit Test Failures in $unitTest\n";
147 else if(!is_NULL($errors))
151 return(
"Failure: Could not check file $fileName for failures is the file corrupt?\n");
154 if(!genCunitRep($fileName))
156 return(
"Error!, could not generate html report for $unitTest\n");
171 function tweakCUnit($fileName)
179 $rFile = file_get_contents($fileName);
182 $replace =
'href="http://fossology.usa.hp.com/~fossology/dtds/';
183 $rFile = preg_replace($pat, $replace, $rFile);
185 $runPat =
'/CUnit-Run\.dtd/';
186 $rReplace =
'http://fossology.usa.hp.com/~fossology/dtds/CUnit-Run.dtd';
187 $listPat =
'/CUnit-List\.dtd/';
188 $lReplace =
'http://fossology.usa.hp.com/~fossology/dtds/CUnit-List.dtd';
189 $rFile = preg_replace($runPat, $rReplace, $rFile);
190 $rFile = preg_replace($listPat, $lReplace, $rFile);
192 if(!file_put_contents($fileName, $rFile))
205 if(!defined(
'TESTROOT'))
208 $plenth = strlen($path);
210 $TESTROOT = substr($path, 0, $plenth-5);
211 $_ENV[
'TESTROOT'] = $TESTROOT;
212 putenv(
"TESTROOT=$TESTROOT");
213 define(
'TESTROOT',$TESTROOT);
218 if(array_key_exists(
'WORKSPACE', $_ENV))
220 $WORKSPACE = $_ENV[
'WORKSPACE'];
221 define(
'WORKSPACE', $WORKSPACE);
224 $unit = TESTROOT .
"/unit";
226 if(@chdir($unit) === FALSE)
228 echo
"FATAL!, could not cd to:\n$unit\n";
231 require_once(
'../lib/bootstrap.php');
232 require_once(
'../lib/common-Report.php');
233 require_once(
'../lib/common-Test.php');
234 require_once(
'../lib/createRC.php');
237 $sc = getenv(
'SYSCONFDIR');
238 echo
"DB: runUnit: sysconf from getenv is:$sc\n";
244 echo
"DB: runUnit: globals:sysconfdir:{$GLOBALS['SYSCONFDIR']}\n";
245 putenv(
"SYSCONFDIR=$sc");
246 $_ENV[
'SYSCONFDIR'] = $sc;
248 echo
"DB: runUnit: after putenv SYSCONFDIR from env is:" . getenv(
'SYSCONFDIR') .
"\n";
249 echo
"DB: runUnit: after _ENV set, SYSCONFDIR from _ENV is:{$_ENV['SYSCONFDIR']}\n";
255 $modules = parse_ini_file(
'../dataFiles/unitTests.ini',1);
256 foreach($modules as $key => $value)
267 backToParent(
'../..');
270 foreach($unitList as $unitTest)
274 $other = substr($unitTest, 0, 3);
275 if($other ==
'lib' || $other ==
'cli')
277 if(@chdir($unitTest .
'/tests') === FALSE)
279 echo
"Error! cannot cd to " . $unitTest .
"/tests, skipping test\n";
286 if(@chdir($unitTest .
'/agent_tests/Unit') === FALSE)
288 echo
"Error! cannot cd to " . $unitTest .
"/agent_tests/Unit, skipping test\n";
293 $Make =
new RunTest($unitTest);
294 $runResults = $Make->MakeTest();
296 $Make->printResults($runResults);
297 if(processCUnit($unitTest) != NULL)
299 echo
"Error: could not process cunit results file for $unitTest\n";
301 if(MakeCover($unitTest) != NULL)
306 backToParent(
'../../..');
class for making an agent unit or functional test
bootstrap($sysconfdir="")
Bootstrap the fossology php library.