Source for file RunTest.php
Documentation is available at RunTest.php 
// +----------------------------------------------------------------------+  
// +----------------------------------------------------------------------+  
// | Copyright (c) 1997-2004 The PHP Group                                |  
// +----------------------------------------------------------------------+  
// | This source file is subject to version 3.0 of the PHP license,       |  
// | that is bundled with this package in the file LICENSE, and is        |  
// | available through the world-wide-web at the following url:           |  
// | http://www.php.net/license/3_0.txt.                                  |  
// | If you did not receive a copy of the PHP license and are unable to   |  
// | obtain it through the world-wide-web, please send a note to          |  
// | license@php.net so we can mail you a copy immediately.               |  
// +----------------------------------------------------------------------+  
// | Authors: Tomas V.V.Cox <cox@idecnet.com>                             |  
// |          Greg Beaver <cellog@php.net>                                |  
// +----------------------------------------------------------------------+  
// $Id: RunTest.php,v 1.3.2.4 2005/02/17 17:47:55 cellog Exp $  
 * Simplified version of PHP's test suite  
 $ php -r 'include "../PEAR/RunTest.php"; $t=new PEAR_RunTest; $o=$t->run("./pear_system.phpt");print_r($o);'  
Actually finish the development and testing  
require_once 'PEAR/Config.php';   
putenv("PHP_PEAR_RUNTESTS=1");   
     * An object that supports the PEAR_Common->log() signature, or null  
     * @param PEAR_Common|null  
    function PEAR_RunTest ($logger = null )  
        $this->_logger =  $logger;   
    //  Run an individual test case.  
    function run ($file, $ini_settings =  '')  
        $conf =  &PEAR_Config ::singleton ();   
        $php =  $conf->get ('php_bin');   
        global $log_format, $info_params, $ini_overwrites;   
        // Load the sections of the test file.  
            'TEST'    =>  '(unnamed test)',  
            return PEAR ::raiseError (" Cannot open test file: $file" );   
            // Match the beginning of a section.  
            if (ereg('^--([A-Z]+)--',$line,$r)) {  
                $section_text[$section] =  '';   
            // Add to the section text.  
            $section_text[$section] .=  $line;   
        $tested =  trim($section_text['TEST'])."  [$shortname]";   
        $tmp_skipif =  $tmp .  uniqid('/phpt.');   
        $tmp_post   =  $tmp .  uniqid('/phpt.');   
        // unlink old test results  
        // Check if test should be skipped.  
            if (trim($section_text['SKIPIF'])) {  
                $this->save_text ($tmp_skipif, $section_text['SKIPIF']);   
                //$extra = substr(PHP_OS, 0, 3) !== "WIN" ?  
                //    "unset REQUEST_METHOD;": "";  
                //$output = `$extra $php $info_params -f $tmp_skipif`;  
                $output = ` $php $info_params -f  $tmp_skipif`;   
                    $skipreason = " SKIP $tested";   
                    $reason =  (eregi("^skip[[:space:]]*(.+)\$", trim($output))) ?  eregi_replace("^skip[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE;   
                        $skipreason .= "  (reason: $reason)";   
                    $this->_logger->log (0 , $skipreason);   
                    $reason =  (ereg("^info[[:space:]]*(.+)\$", trim($output))) ?  ereg_replace("^info[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE;   
                        $info = "  (info: $reason)";   
                    $reason =  (ereg("^warn[[:space:]]*(.+)\$", trim($output))) ?  ereg_replace("^warn[[:space:]]*(.+)\$", "\\1", trim($output)) : FALSE;   
                        $warn = true;  /* only if there is a reason */  
                        $info = "  (warn: $reason)";   
        // We've satisfied the preconditions - run the test!  
        $this->save_text ($tmp_file,$section_text['FILE']);   
        $args =  $section_text['ARGS'] ?  ' -- '. $section_text['ARGS'] :  '';   
        $cmd = " $php$ini_settings -f $tmp_file$args 2>&1";   
        if (isset ($this->_logger)) {  
            $this->_logger->log (2 , 'Running command "' .  $cmd .  '"');   
        $savedir =  getcwd();  // in case the test moves us around  
        if (isset ($section_text['RETURNS'])) {  
            $section_text['RETURNS'] = (int)  trim($section_text['RETURNS']);   
            $returnfail =  ($return_value !=  $section_text['RETURNS']);   
        // Does the output match what is expected?  
        if (isset ($section_text['EXPECTF']) || isset ($section_text['EXPECTREGEX'])) {  
            if (isset ($section_text['EXPECTF'])) {  
                $wanted =  trim($section_text['EXPECTF']);   
                $wanted =  trim($section_text['EXPECTREGEX']);   
            if (isset ($section_text['EXPECTF'])) {  
                $wanted_re =  str_replace("%s", ".+?", $wanted_re);  //not greedy  
                $wanted_re =  str_replace("%i", "[+\-]?[0-9]+", $wanted_re);   
                $wanted_re =  str_replace("%x", "[0-9a-fA-F]+", $wanted_re);   
                $wanted_re =  str_replace("%f", "[+\-]?\.?[0-9]+\.?[0-9]*(E-?[0-9]+)?", $wanted_re);   
                // %f allows two points "-.0.0" but that is the best *simple* expression  
            print(str_repeat('=', 80) . "\n");  
            if (!$returnfail &&  preg_match(" /^$wanted_re\$/s" , $output)) {  
                $this->_logger->log (0 , " PASS $tested$info" );   
            $wanted =  trim($section_text['EXPECT']);   
        // compare and leave on success  
            $ok =  (0 ==  strcmp($output,$wanted));   
            if (!$returnfail &&  $ok) {  
                $this->_logger->log (0 , " PASS $tested$info" );   
        // Test failed so we need to report details.  
            $this->_logger->log (0 , " WARN $tested$info" );   
            $this->_logger->log (0 , " FAIL $tested$info" );   
        if (isset ($section_text['RETURNS'])) {  
            $GLOBALS['__PHP_FAILED_TESTS__'][] = array (  
                            'return' =>  $return_value  
            $GLOBALS['__PHP_FAILED_TESTS__'][] = array (  
        if (strpos($log_format,'E') !== FALSE ) {  
            if (!$log =  fopen($logname,'w')) {  
                return PEAR ::raiseError (" Cannot create test log - $logname" );   
        if (strpos($log_format,'O') !== FALSE ) {  
            if (!$log =  fopen($logname,'w')) {  
                return PEAR ::raiseError (" Cannot create test log - $logname" );   
        if (strpos($log_format,'D') !== FALSE ) {  
            if (!$log =  fopen($logname,'w')) {  
                return PEAR ::raiseError (" Cannot create test log - $logname" );   
            fwrite($log, $this->generate_diff ($wanted, $output,  
                isset ($section_text['RETURNS']) ? array (trim($section_text['RETURNS']), 
        if (strpos($log_format,'L') !== FALSE ) {  
            if (!$log =  fopen($logname,'w')) {  
                return PEAR ::raiseError (" Cannot create test log - $logname" );   
            //error_report($file,$logname,$tested);  
        return $warn ?  'WARNED' :  'FAILED';   
    function generate_diff ($wanted, $output, $return_value)  
        foreach($w1 as  $idx =>  $val) $w2[sprintf("%03d<",$idx)] =  sprintf("%03d- ", $idx+1 ). $val;   
        foreach($o1 as  $idx =>  $val) $o2[sprintf("%03d>",$idx)] =  sprintf("%03d+ ", $idx+1 ). $val;   
            $extra = " ##EXPECTED: $return_value[0]\r\n##RETURNED: $return_value[1]";   
        return implode("\r\n", $diff) .  $extra;   
    //  Write the given text to a temporary file, and return the filename.  
    function save_text ($filename, $text)  
        if (!$fp =  fopen($filename, 'w')) {  
            return PEAR ::raiseError ("Cannot open file '" .  $filename .  "' (save_text)");   
 
 
        
		    
 
		    Documentation generated on Mon, 11 Mar 2019 14:24:00 -0400 by  phpDocumentor 1.4.4. PEAR Logo Copyright ©  PHP Group 2004.
	        
       |