FOSSology  4.4.0
Open Source License Compliance by Open Source Software
textReport.php
1 #!/usr/bin/php
2 <?php
3 /*
4 SPDX-FileCopyrightText: © 2008 Hewlett-Packard Development Company, L.P.
5 
6 SPDX-License-Identifier: GPL-2.0-only
7 */
8 
23 require_once('reportClass.php');
24 require_once('testSuites.php');
25 
26 
27 //$res = '/home/markd/Src/fossology/tests/FossTestResults-2009-08-25-10:31:39-pm';
28 
29 $options = getopt("hf:");
30 
31 $Usage = "$argv[0] [-h] -f <test-results-file>\n";
32 
33 if(empty($options)) {
34  print $Usage;
35  exit(1);
36 }
37 
38 if(array_key_exists('h',$options)) {
39  print $Usage;
40  exit(0);
41 }
42 if(array_key_exists('f',$options)) {
43  $filePath = $options['f'];
44  if(!strlen($filePath)) {
45  print $Usage;
46  exit(1);
47  }
48  if(!file_exists($filePath)) {
49  print "Error! $filePath does not exist or is not readable\n";
50  exit(1);
51  }
52 }
53 
54 $tr = new TestReport($filePath);
55 
56 $results = $tr->parseResultsFile($filePath);
57 //print "got back the following from parseResultsFile:\n";
58 //print_r($results) . "\n";
59 
60 $totalPasses = 0;
61 $totalFailures = 0;
62 $totalExceptions = 0;
63 
75 function groupByType($suiteName, $list) {
76 
77  if(!is_array($list)) {
78  return(FALSE);
79  }
80  if(!strlen($suiteName)) {
81  return(FALSE);
82  }
83 
84  foreach($list as $nextList){
85  foreach($nextList as $index => $resultList){
86  $failTypeList[] = $resultList;
87  }
88  }
89  return($failType[$suiteName] = $failTypeList);
90 } // groupByType
91 
92 function printByType($typeName, $typeList) {
93 
94  if(!is_array($typeList)) {
95  return(FALSE);
96  }
97  if(!strlen($typeName)) {
98  return(FALSE);
99  }
100 
101  print "The following Test Suites had $typeName:\n";
102  foreach($typeList as $suite => $flist){
103  //print "DB: fsuite and flist are:$fsuite,$flist\n";
104  print "$suite:\n";
105  $len = strlen($suite);
106  $len++; // for the ':'
107  printf("%'-{$len}s\n", '');
108  foreach ($flist as $fline) {
109  print " $fline\n";
110  }
111  print "\n";
112  }
113 } // printByType
114 
115 // summarize the results for this run. Note failures and exceptions by suite
116 
117 $suiteFailures = array();
118 $suiteExceptions = array();
119 $suitesRun = array();
120 
121 foreach($results as $suite => $result) {
122  foreach($result as $partResult) {
123 
124  // gather the unique suites that were run
125  if (array_key_exists($suite, $testSuites))
126  {
127  if(!in_array($suite, $suitesRun))
128  {
129  $suitesRun[] = $suite;
130  }
131  }
132  if (is_array($partResult)) {
133  if(array_key_exists('failures',$partResult)) {
134  $suiteFailures[$suite] = groupByType($suite,$partResult);
135  }
136 
137  if(array_key_exists('exceptions',$partResult)) {
138  $suiteExceptions[$suite] = groupByType($suite,$partResult);
139  }
140  }
141  // it's the suite result summary, compute totals
142  else {
143  list($passes, $fail, $except) = preg_split('/:/',$partResult);
144  //print "DB: passes, fail, except are:$passes,$fail,$except\n";
145  $totalPasses += $passes;
146  $totalFailures += $fail;
147  $totalExceptions+= $except;
148  }
149  }
150 }
151 // print the summary and any failures and exceptions
152 
153 print "Test Results for FOSSology UI Test suite\n";
154 print "Tests run on $tr->Date at $tr->Time using SVN Version $tr->Svn\n";
155 print "The tests Suites that were run are:\n";
156 printf("%'-35s\n", '');
157 
158 foreach ($suitesRun as $suite)
159 {
160  if (array_key_exists($suite, $testSuites))
161  {
162  print "$suite: $testSuites[$suite]\n\n";
163  }
164 }
165 
166 print "Test Results Summary\n";
167 printf("%'-37s\n", '');
168 print "Total Passes: $totalPasses\n";
169 print "Total Failures: $totalFailures\n";
170 print "Total Exceptions: $totalExceptions\n";
171 printf("%'-37s\n", '');
172 //print "The following Test Suites had Failures:\n";
173 printByType('failures', $suiteFailures);
174 printf("%'-37s\n", '');
175 //print "The following Test Suites had Exceptions:\n";
176 printByType('Exceptions', $suiteExceptions);
177 
178 exit(0);
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:308