FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
textReport.php
1 #!/usr/bin/php
2 <?php
3 /***********************************************************
4  Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  ***********************************************************/
19 
34 require_once('reportClass.php');
35 require_once('testSuites.php');
36 
37 
38 //$res = '/home/markd/Src/fossology/tests/FossTestResults-2009-08-25-10:31:39-pm';
39 
40 $options = getopt("hf:");
41 
42 $Usage = "$argv[0] [-h] -f <test-results-file>\n";
43 
44 if(empty($options)) {
45  print $Usage;
46  exit(1);
47 }
48 
49 if(array_key_exists('h',$options)) {
50  print $Usage;
51  exit(0);
52 }
53 if(array_key_exists('f',$options)) {
54  $filePath = $options['f'];
55  if(!strlen($filePath)) {
56  print $Usage;
57  exit(1);
58  }
59  if(!file_exists($filePath)) {
60  print "Error! $filePath does not exist or is not readable\n";
61  exit(1);
62  }
63 }
64 
65 $tr = new TestReport($filePath);
66 
67 $results = $tr->parseResultsFile($filePath);
68 //print "got back the following from parseResultsFile:\n";
69 //print_r($results) . "\n";
70 
71 $totalPasses = 0;
72 $totalFailures = 0;
73 $totalExceptions = 0;
74 
86 function groupByType($suiteName, $list) {
87 
88  if(!is_array($list)) {
89  return(FALSE);
90  }
91  if(!strlen($suiteName)) {
92  return(FALSE);
93  }
94 
95  foreach($list as $nextList){
96  foreach($nextList as $index => $resultList){
97  $failTypeList[] = $resultList;
98  }
99  }
100  return($failType[$suiteName] = $failTypeList);
101 } // groupByType
102 
103 function printByType($typeName, $typeList) {
104 
105  if(!is_array($typeList)) {
106  return(FALSE);
107  }
108  if(!strlen($typeName)) {
109  return(FALSE);
110  }
111 
112  print "The following Test Suites had $typeName:\n";
113  foreach($typeList as $suite => $flist){
114  //print "DB: fsuite and flist are:$fsuite,$flist\n";
115  print "$suite:\n";
116  $len = strlen($suite);
117  $len++; // for the ':'
118  printf("%'-{$len}s\n", '');
119  foreach ($flist as $fline) {
120  print " $fline\n";
121  }
122  print "\n";
123  }
124 } // printByType
125 
126 // summarize the results for this run. Note failures and exceptions by suite
127 
128 $suiteFailures = array();
129 $suiteExceptions = array();
130 $suitesRun = array();
131 
132 foreach($results as $suite => $result) {
133  foreach($result as $partResult) {
134 
135  // gather the unique suites that were run
136  if (array_key_exists($suite, $testSuites))
137  {
138  if(!in_array($suite, $suitesRun))
139  {
140  $suitesRun[] = $suite;
141  }
142  }
143  if (is_array($partResult)) {
144  if(array_key_exists('failures',$partResult)) {
145  $suiteFailures[$suite] = groupByType($suite,$partResult);
146  }
147 
148  if(array_key_exists('exceptions',$partResult)) {
149  $suiteExceptions[$suite] = groupByType($suite,$partResult);
150  }
151  }
152  // it's the suite result summary, compute totals
153  else {
154  list($passes, $fail, $except) = preg_split('/:/',$partResult);
155  //print "DB: passes, fail, except are:$passes,$fail,$except\n";
156  $totalPasses += $passes;
157  $totalFailures += $fail;
158  $totalExceptions+= $except;
159  }
160  }
161 }
162 // print the summary and any failures and exceptions
163 
164 print "Test Results for FOSSology UI Test suite\n";
165 print "Tests run on $tr->Date at $tr->Time using SVN Version $tr->Svn\n";
166 print "The tests Suites that were run are:\n";
167 printf("%'-35s\n", '');
168 
169 foreach ($suitesRun as $suite)
170 {
171  if (array_key_exists($suite, $testSuites))
172  {
173  print "$suite: $testSuites[$suite]\n\n";
174  }
175 }
176 
177 print "Test Results Summary\n";
178 printf("%'-37s\n", '');
179 print "Total Passes: $totalPasses\n";
180 print "Total Failures: $totalFailures\n";
181 print "Total Exceptions: $totalExceptions\n";
182 printf("%'-37s\n", '');
183 //print "The following Test Suites had Failures:\n";
184 printByType('failures', $suiteFailures);
185 printf("%'-37s\n", '');
186 //print "The following Test Suites had Exceptions:\n";
187 printByType('Exceptions', $suiteExceptions);
188 
189 exit(0);
190 ?>
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:321