FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
fo-runTests.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 
44 $path = '/usr/local/simpletest' . PATH_SEPARATOR;
45 set_include_path(get_include_path() . PATH_SEPARATOR . $path);
46 if (!defined('SIMPLE_TEST'))
47 define('SIMPLE_TEST', '/usr/local/simpletest/');
48 
49 /* simpletest includes */
50 require_once SIMPLE_TEST . 'unit_tester.php';
51 require_once SIMPLE_TEST . 'reporter.php';
52 require_once SIMPLE_TEST . 'web_tester.php';
53 
54 require_once ('TestEnvironment.php');
55 if(defined('TESTROOT'))
56 {
57  echo TESTROOT . "\n";
58  require_once(TESTROOT . '/testClasses/timer.php');
59 }
60 else
61 {
62  echo "ERROR! cannot load /testClasses/timer.php, is TESTROOT defined?\n";
63  exit(1);
64 }
65 
66 $Usage = "Usage: $argv[0] options...
67  Options:
68  [ {<test-file.php> || a single test or
69  [-l 'list of tests'}] a list of tests, space seperated
70  [ -n <suite-name>] optional test suite name
71  [ -t 'A Title'] optional title\n
72  To run everything in a directory $argv[0] -l \"`ls`\"\n" ;
73 
74 /*
75  * NOTE on parameters, can't guess a suite name from a list, so
76  * only get a suite name if -n is used or no -a and a single test to run.
77  */
78 
79 /*
80  "$argv[0] -l 'list of tests space seperated'\n or\n" .
81  "$argv[0] -l \"`ls`\" to run everything in the directory\n".
82  "\n$argv[0] -t 'Title' to supply an optional title\n";
83  */
84 
85 $options = getopt("l:n:t:");
86 
87 /*
88  Must have at least 1 argument (the test file to run)
89  */
90 $RunList = array();
91 $aTest = NULL;
92 $suite = NULL;
93 
94 //print "argc,argv is:$argc\n";print_r($argv) . "\n";
95 //print "argc is:$argc\n";
96 if (empty($options)) {
97  if ($argc < 2){
98  print $Usage;
99  exit(1);
100  }
101 }
102 if($argc >= 2){
103  /*
104  If first argument does not start with a '-' then it must be a test to run
105  */
106  $len = strspn($argv[1],'-');
107  if(strspn($argv[1],'-') == 0) {
108  $aTest = $argv[1];
109  }
110 }
111 if (array_key_exists("l",$options)) {
112  /* split on spaces AND newlines so you can do a -l "`ls`" */
113  $RunList = preg_split('/\s|\n/',$options['l']);
114  //print "runx: runlist is:\n"; print_r($RunList) . "\n";
115 }
116 if (array_key_exists("n",$options)) {
117  $suite = $options['n'];
118  //print "DB: suite is:$suite\n";
119 }
120 // no suite specified
121 if (!is_null($aTest)) {
122  if(file_exists($aTest)) {
123  $suite = $aTest;
124  $RunList = array($aTest);
125  //print "DB: runlist after assignment of aTest is:\n";print_r($RunList) . "\n";
126  }
127  else {
128  print "Error! File $aTest does not exist!\n";
129  exit(1);
130  }
131 }
132 // default name
133 if(is_null($suite)) {
134  $suite = 'Generic FOSSology Test Suite';
135 }
136 $Title = NULL;
137 if (array_key_exists("t",$options)) {
138  $Title = $options['t'];
139  //print "DB: Title is:$Title\n";
140 }
141 
142 //$Svn = `svnversion`;
143 $start = new timer();
144 $date = date('Y-m-d');
145 $time = date('h:i:s-a');
146 print "Starting $suite on: " . $date . " at " . $time . "\n";
147 //print "Using Svn Version:$Svn\n";
148 $Runtest = new TestSuite("Fossology tests $Title");
149 /*
150  * tests will run serially...
151  *
152  * allow filenames without .php or with it
153  */
154 //print "DB: runlist is:\n";print_r($RunList) . "\n";
155 foreach($RunList as $ptest) {
156  if(preg_match('/^.*?\.php/',$ptest)) {
157  $test = $ptest;
158  }
159  else {
160  $test = $ptest . ".php";
161  }
162  $Runtest->addTestFile("$test");
163 }
164 
165 /*
166  * leave the code below alone, it allows the tests to be run either by
167  * the cli or in a web browser
168  */
169 
170 if (TextReporter::inCli()) {
171  $results = $Runtest->run(new TextReporter()) ? 0 : 1;
172  print "Ending $suite at: " . date('r') . "\n";
173  $elapseTime = $start->TimeAgo($start->getStartTime());
174  print "The suite $suite took {$elapseTime}to run\n\n";
175  exit($results);
176 }
177 
178 $Runtest->run(new HtmlReporter());
179 print "<pre>Ending $suite at: " . date('r') . "</pre>\n";
180 $elapseTime = $start->TimeAgo($start->getStartTime());
181 print "<pre>The suite $suite took {$elapseTime}to run</pre>\n";
182 ?>
Definition: timer.php:42