Changeset 1044

Show
Ignore:
Timestamp:
02/23/10 15:31:34 (5 months ago)
Author:
weyrick
Message:

hack in framework for testing transform passes with rphp-analyzer

Location:
trunk/rphp-testsuite
Files:
2 added
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/rphp-testsuite/Makefile

    r921 r1044  
    3737        php -f ./dotest.php -- -d ./re-tests/ ./re-output 
    3838 
    39 # raven parse 
    40 parse:  
    41         php -f ./dotest.php -- --parseonly -d ./re-tests/ ./re-output 
     39# raven transforms 
     40transforms:  
     41        php -f ./dotest.php -- -d ./re-tests/transforms/ ./re-output 
    4242 
    4343# zend 
  • trunk/rphp-testsuite/dotest.php

    r940 r1044  
    33/* ***** BEGIN LICENSE BLOCK ***** 
    44 * Roadsend PHP Compiler 
    5  * Copyright (C) 2009 Shannon Weyrick 
     5 * Copyright (C) 2009-2010 Shannon Weyrick 
    66 * 
    77 * This program is free software; you can redistribute it and/or 
     
    3636    static public $rphpBinary; 
    3737    static public $rphpABinary; 
    38     static public $rphpVersion; 
    39     static public $doCompiled = true; 
     38    static public $rphpVersion;     
    4039    static public $testRoot; 
    4140    static public $outDir; 
    4241    static public $singleMode = false; 
    43     static public $parseOnly = false; 
    4442     
    4543    public static function log($level, $msg) { 
     
    6664            } 
    6765            if (empty(self::$rphpBinary) || empty(self::$rphpABinary)) { 
    68                 self::bomb('Unable to find rphp binaries (rphp,rphp-analyze). Try setting RPHP_BINARY and RPHP_ANALYZER_BINARY or putting rphp in the PATH'); 
     66                self::bomb('Unable to find rphp binaries (rphp,rphp-analyzer). Try setting RPHP_BINARY and RPHP_ANALYZER_BINARY or putting rphp in the PATH'); 
    6967            } 
    7068        } 
     
    9896    public function usage() { 
    9997        echo "Roadsend PHP Test Suite\n"; 
    100         echo "dotest [--parseonly] [-dfl] <directory or file> [output directory]\n"; 
    101         echo "  --parseonly\t\tRun parser (AST dump) tests only, no runtime\n"; 
     98        echo "dotest [-df] <directory or file> [output directory]\n"; 
    10299        echo "  -d <path>\t\tRun all tests in the specified root directory\n"; 
    103100        echo "  -f <file>\t\tRun the single test specified\n"; 
    104         echo "  -l <file>\t\tRun all tests listed in the specified file\n"; 
    105101        die("\n"); 
    106102    } 
     
    128124 
    129125    public function run() { 
    130  
    131         if ($GLOBALS['argv'][1] == '--parseonly') { 
    132             Control::$parseOnly = true; 
    133             Control::$doCompiled = false; 
    134             array_splice($GLOBALS['argv'],1,1); 
    135         } 
    136126 
    137127        if (($GLOBALS['argc'] < 3) || 
     
    175165 
    176166    public function showResults() { 
     167         
     168        $allPassed = true; 
    177169        foreach ($this->testList as $testH) { 
    178170            if ($testH->interpretResult == PHP_Test::RESULT_FAIL) 
     
    184176            if ($testH->compileResult == PHP_Test::RESULT_FAIL) 
    185177                $cFail[] = $testH; 
    186         } 
    187         if (sizeof($iFail)) { 
    188             echo "------------- INTERPRETER FAILURES -------------\n"; 
    189             foreach ($iFail as $testH) { 
     178            if ($testH->parseResult == PHP_Test::RESULT_FAIL) 
     179                $pFail[] = $testH; 
     180        } 
     181        if (sizeof($iFail)||sizeof($bFail)||sizeof($bFailFail)||sizeof($cFail)||sizeof($pFail)) 
     182            $allPassed = false; 
     183 
     184        $this->showResultList('INTERPRETER', $iFail, $testH->iDiffOutput, $testH->ierrFileName); 
     185        $this->showResultList('BUILD', $bFail, $testH->builtOutput, $testH->buildErrFileName); 
     186        $this->showResultList('EXPECTED BUILD FAIL', $bFailFail, $testH->builtOutput, $testH->buildErrFileName); 
     187        $this->showResultList('COMPILED RUN', $cFail, $testH->cDiffOutput); 
     188        $this->showResultList('PARSE', $pFail, $testH->pDiffOutput); 
     189         
     190        if ($allPassed) 
     191            echo "---- ALL TESTS PASSED ----\n"; 
     192    } 
     193 
     194    public function showResultList($msg, $fails, $singleExtra=NULL, $extraFile=NULL) { 
     195        if (sizeof($fails)) { 
     196            echo "------------- $msg FAILURES -------------\n"; 
     197            foreach ($fails as $testH) { 
    190198                echo "{$testH->tptFileName}\n"; 
    191199                if (isset($testH->sectionData['KNOWNFAILURE'])) 
    192200                    echo "--- KNOWN FAILURE:\n".$testH->sectionData['KNOWNFAILURE']."---\n"; 
    193201                if (Control::$singleMode) { 
    194                     echo $testH->iDiffOutput; 
    195                     if (filesize($testH->ierrFileName)) { 
     202                    if ($singleExtra) { 
     203                        echo $singleExtra; 
     204                    } 
     205                    if ($extraFile && file_exists($extraFile)) { 
    196206                        echo "--- ERROR OUTPUT ---\n"; 
    197                         echo file_get_contents($testH->ierrFileName); 
     207                        echo file_get_contents($extraFile); 
    198208                    } 
    199209                } 
    200210            } 
    201211        } 
    202         if (sizeof($bFail)) { 
    203             echo "------------- BUILD FAILURES -------------\n"; 
    204             foreach ($bFail as $testH) { 
    205                 echo "{$testH->tptFileName}\n"; 
    206                 if (Control::$singleMode) { 
    207                     echo $testH->buildOutput; 
    208                     echo file_get_contents($testH->buildErrFileName); 
    209                 } 
    210             } 
    211         } 
    212         if (sizeof($bFailFail)) { 
    213             echo "------------- EXPECTED BUILD FAIL FAILURES -------------\n"; 
    214             foreach ($bFailFail as $testH) { 
    215                 echo "{$testH->tptFileName}\n"; 
    216                 if (Control::$singleMode) { 
    217                     echo $testH->buildOutput; 
    218                     echo file_get_contents($testH->buildErrFileName); 
    219                 } 
    220             } 
    221         } 
    222         if (sizeof($cFail)) { 
    223             echo "------------- COMPILE RUN FAILURES -------------\n"; 
    224             foreach ($cFail as $testH) { 
    225                 echo "{$testH->tptFileName}\n"; 
    226                 if (Control::$singleMode) 
    227                     echo $testH->cDiffOutput; 
    228             } 
    229         } 
    230         if (empty($iFail)&&empty($bFail)&&empty($bFailFail)&&empty($cFail)) 
    231             echo "---- ALL TESTS PASSED ----\n"; 
    232212    } 
    233213 
     
    244224    const RESULT_BUILDFAIL_FAIL = 6; // we expected the compiler build to fail, but it passed 
    245225 
    246     const INTERPRETER = 0; 
    247     const COMPILER = 1; 
     226    const INTERPRETER = 1; 
     227    const COMPILER = 2; 
     228    const ANALYZER = 4; 
     229     
     230    public $testTypes = 0; 
    248231     
    249232    public $tptFileName; 
     
    251234    public $ioutFileName; // interpreted output 
    252235    public $coutFileName; // compiled output 
     236    public $poutFileName; // parse output 
    253237    public $expectFileName; 
    254238    public $buildFileName; 
    255239    public $idiffFileName; 
    256240    public $cdiffFileName; 
     241    public $pdiffFileName; 
    257242    public $idiffOutput; 
    258243    public $cdiffOutput; 
    259244    public $buildOutput; 
     245    public $pdiffOutput; 
    260246     
    261247    public $iOutput; 
    262248    public $cOutput; 
     249    public $pOutput; 
    263250 
    264251    protected $expectType = 'EXPECT'; 
     
    269256    public $compileResult = self::RESULT_UNKNOWN; 
    270257    public $interpretResult = self::RESULT_UNKNOWN; 
     258    public $parseResult = self::RESULT_UNKNOWN; 
    271259     
    272260    public function __construct($fName) { 
     
    308296            $this->sectionData['EXPECTREGEX'] = $this->sectionData['EXPECTREGEX:'.$wSize]; 
    309297 
    310  
    311298        // verify we have code to write 
    312299        if (empty($this->sectionData['FILE'])) 
     
    314301 
    315302        if (isset($this->sectionData['EXPECTF'])) { 
     303            $this->testTypes |= self::COMPILER & self::INTERPRETER; 
    316304            $this->expectType = 'EXPECTF'; 
    317305        } 
    318306        elseif (isset($this->sectionData['EXPECTREGEX'])) { 
     307            $this->testTypes |= self::COMPILER & self::INTERPRETER; 
    319308            $this->expectType = 'EXPECTREGEX'; 
    320309        } 
    321         elseif (!isset($this->sectionData['EXPECT'])) { 
     310        elseif (isset($this->sectionData['EXPECTPARSE'])) { 
     311            $this->testTypes |= self::ANALYZER; 
     312            $this->expectType = 'EXPECTPARSE'; 
     313        } 
     314        elseif (isset($this->sectionData['EXPECT'])) { 
     315            $this->testTypes |= self::COMPILER & self::INTERPRETER; 
     316            $this->expectType = 'EXPECT'; 
     317        } 
     318        else {             
    322319            print_r($this->sectionData); 
    323320            Control::bomb('no expect data'); 
    324321        } 
    325322 
     323        // XXX do skips and remove interpreter/compiler as necessary 
     324 
    326325        // work files 
    327326        $bName = Control::$outDir.basename($this->tptFileName, '.phpt'); 
    328         $this->testFileName = $bName.'.php'; 
     327        $this->testFileName = $bName.'.php';         
    329328        $this->expectFileName = $bName.'.expect'; 
     329        // build (compiles only) 
    330330        $this->buildFileName = $bName.'.build.out'; 
    331331        $this->buildErrFileName = $bName.'.build.err'; 
     332        // stdout 
    332333        $this->ioutFileName = $bName.'.i.out'; 
    333334        $this->coutFileName = $bName.'.c.out'; 
     335        $this->poutFileName = $bName.'.p.out'; 
     336        // stderr 
    334337        $this->ierrFileName = $bName.'.i.err'; 
    335338        $this->cerrFileName = $bName.'.c.err'; 
     339        $this->perrFileName = $bName.'.p.err'; 
     340        // diff 
    336341        $this->idiffFileName = $bName.'.i.diff'; 
    337342        $this->cdiffFileName = $bName.'.c.diff'; 
     343        $this->pdiffFileName = $bName.'.p.diff'; 
    338344         
    339345    } 
     
    357363    protected function executeTest($type) { 
    358364 
    359         if (Control::$parseOnly && !isset($this->sectionData['EXPECTPARSE'])) { 
    360             $this->interpretResult = PHP_Test::RESULT_SKIP; 
    361             $this->compileResult = PHP_Test::RESULT_SKIP; 
    362             return; 
    363         } 
    364  
    365365        if ($type == self::INTERPRETER) { 
    366366             
    367             /* 
    368             if (defined('ROADSEND_PHP')) { 
    369                 $cmd = Control::$rphpBinary.' -I '.dirname($this->tptFileName).' -f '.$this->testFileName; 
    370             } 
    371             else { 
    372             // XXX do zend command here 
    373             } 
    374             */ 
    375             if (Control::$parseOnly) { 
    376                 $cmd = Control::$rphpABinary.' --dump-ast '.$this->testFileName; 
    377             } 
    378             else { 
    379                 $cmd = Control::$rphpBinary.' -f '.$this->testFileName; 
    380             } 
     367            $cmd = Control::$rphpBinary.' -f '.$this->testFileName; 
    381368 
    382369            // setup output vars 
     
    385372            $result =& $this->interpretResult; 
    386373            $errFileName =& $this->ierrFileName; 
     374             
     375        } 
     376        elseif ($type == self::ANALYZER) { 
     377             
     378            $passes = trim($this->sectionData['PASSES']); 
     379            if (empty($passes)) { 
     380                $passes = 'dump-ast'; 
     381            }             
     382            $cmd = Control::$rphpABinary.' --passes='.$passes.' '.$this->testFileName; 
     383             
     384            // setup output vars 
     385            $output =& $this->pOutput; 
     386            $outFileName =& $this->poutFileName; 
     387            $result =& $this->parseResult; 
     388            $errFileName =& $this->perrFileName; 
     389             
    387390        } 
    388391        else { 
     
    428431        if ($type == self::INTERPRETER) 
    429432            $this->interpretResult = $result; 
     433        elseif ($type == self::ANALYZER) 
     434            $this->parseResult = $result; 
    430435        else 
    431436            $this->compileResult = $result; 
     
    439444     
    440445        // compare output 
    441         if ($expectType != 'EXPECT') 
     446        if ($expectType != 'EXPECT') { 
    442447            $re_expect = trim($expectData); 
     448        } 
     449         
    443450        switch ($this->expectType) { 
     451            case 'EXPECTPARSE': 
    444452            case 'EXPECT': 
    445453                if ($output != trim($expectData)) { 
     
    476484 
    477485    protected function getExpectData() { 
    478          
    479         if (($type == self::COMPILER) && (isset($this->sectionData['COMPILER:'.$this->expectType]))) { 
    480             $expectData = $this->sectionData['COMPILER:'.$this->expectType]; 
    481         } 
    482         elseif (Control::$parseOnly) { 
    483             $expectData = $this->sectionData['EXPECTPARSE']; 
    484         } 
    485         else { 
    486             $expectData = $this->sectionData[$this->expectType]; 
    487         } 
    488          
    489         return $expectData; 
     486        return $this->sectionData[$this->expectType]; 
    490487    } 
    491488     
     
    497494            $this->iDiffOutput = `$cmd`; 
    498495            file_put_contents($this->idiffFileName, $this->iDiffOutput); 
     496        } 
     497        elseif ($type == self::ANALYZER) { 
     498            $cmd = 'diff '.$this->expectFileName.' '.$this->poutFileName; 
     499            Control::log(2, $cmd); 
     500            $this->pDiffOutput = `$cmd`; 
     501            file_put_contents($this->pdiffFileName, $this->pDiffOutput); 
    499502        } 
    500503        else { 
     
    579582        $this->writeTest(); 
    580583         
    581         echo "INTERPRETER: "; 
    582         Control::flush(); 
    583          
    584         // do interpreter test 
    585         $this->executeTest(self::INTERPRETER); 
    586  
    587         if ($this->interpretResult == self::RESULT_FAIL) { 
    588             $this->writeDiff(self::INTERPRETER); 
    589         } 
    590  
    591         switch ($this->interpretResult) { 
    592             case self::RESULT_PASS: 
    593                 Control::colorMsg(Control::GREEN,"PASS "); 
    594                 break; 
    595             case self::RESULT_FAIL: 
    596                 Control::colorMsg(Control::RED,"FAIL "); 
    597                 break; 
    598             case self::RESULT_SKIP: 
    599                 Control::colorMsg(Control::BLUE,"SKIP "); 
    600                 break; 
    601         } 
     584        if ($this->testTypes & self::INTERPRETER) { 
     585            echo "INTERPRETER: "; 
     586            Control::flush(); 
     587             
     588            // do interpreter test 
     589            $this->executeTest(self::INTERPRETER); 
     590     
     591            if ($this->interpretResult == self::RESULT_FAIL) { 
     592                $this->writeDiff(self::INTERPRETER); 
     593            } 
     594     
     595            switch ($this->interpretResult) { 
     596                case self::RESULT_PASS: 
     597                    Control::colorMsg(Control::GREEN,"PASS "); 
     598                    break; 
     599                case self::RESULT_FAIL: 
     600                    Control::colorMsg(Control::RED,"FAIL "); 
     601                    break; 
     602                case self::RESULT_SKIP: 
     603                    Control::colorMsg(Control::BLUE,"SKIP "); 
     604                    break; 
     605            } 
     606        } 
     607         
     608        if ($this->testTypes & self::ANALYZER) { 
     609            echo "PARSE: "; 
     610            Control::flush(); 
     611             
     612            // do interpreter test 
     613            $this->executeTest(self::ANALYZER); 
     614     
     615            if ($this->parseResult == self::RESULT_FAIL) { 
     616                $this->writeDiff(self::ANALYZER); 
     617            } 
     618     
     619            switch ($this->parseResult) { 
     620                case self::RESULT_PASS: 
     621                    Control::colorMsg(Control::GREEN,"PASS "); 
     622                    break; 
     623                case self::RESULT_FAIL: 
     624                    Control::colorMsg(Control::RED,"FAIL "); 
     625                    break; 
     626                case self::RESULT_SKIP: 
     627                    Control::colorMsg(Control::BLUE,"SKIP "); 
     628                    break; 
     629            } 
     630        }         
    602631         
    603632        // do compiled test 
    604         if (Control::$doCompiled) { 
     633        if ($this->testTypes & self::COMPILER) { 
    605634            echo "   BUILD: "; 
    606635            Control::flush(); 
  • trunk/rphp-testsuite/re-tests/main/basic-literals.phpt

    r921 r1044  
    2929 
    3030?> 
    31 --EXPECTPARSE-- 
    32 foo 
    3331--EXPECT-- 
    3432NULL