<commit_before><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses(
    'lang.Process',
    'util.profiling.unittest.TestCase'
  );

  /**
   * TestCase
   *
   * @see      reference
   * @purpose  purpose
   */
  class BootstrapTest extends TestCase {
  
    /**
     * Run XP script and check exitcode
     *
     * @access  public
     * @param   int code expected exitcode
     * @param   string source sourcecode to execute
     */
    function assertExitCode($code, $source) {
      try(); {
        $p= &new Process($_SERVER['_'].' -dinclude_path='.ini_get("include_path"));
        $s= &$p->getInputStream();
        $s->write('<?php '.$source.'?>');
        
        $p->close();
      } if (catch('Exception', $e)) {
        return throw($e);
      }
      
      $this->assertEquals($code, $p->exitValue());
    }
    
    /**
     * Test
     *
     * @access  public
     */
    #[@test]
    function emptyBootstrap() {
      $this->assertExitcode(0, 'require("lang.base.php");');
    }
    
    /**
     * Test
     *
     * @access  public
     */
    #[@test]
    function useOfExistingFile() {
      $this->assertExitcode(0, 'require("lang.base.php"); uses("'.$this->getClassName().'");');
    }    
    
    /**
     * Test
     *
     * @access  public
     */
    #[@test]
    function useOfNonexistingFile() {
      $this->assertExitcode(255, 'require("lang.base.php"); uses("does.not.exist");');
    }
    
    /**
     * Test
     *
     * @access  public
     */
    #[@test]
    function recursiveInclusion() {
      $this->assertExitcode(123, '
        require("lang.base.php"); 
        uses("net.xp_framework.unittest.bootstrap.A");
        
        exit(123);
      ');
    }
    
    /**
     * Test
     *
     * @access  public
     */
    #[@test]
    function recursiveInclusionWithTicks() {
      $this->assertExitcode(123, '
        declare(ticks=1);
        require("lang.base.php");
        uses("net.xp_framework.unittest.bootstrap.A");
        
        exit(123);
      ');
    }
    
    
  }
?>
<commit_msg>- simplify a bit - check for correct invocation environment - add support for invocations within a cygwin environment<commit_after><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses(
    'lang.Process',
    'util.profiling.unittest.TestCase'
  );

  /**
   * TestCase
   *
   * @see      reference
   * @purpose  purpose
   */
  class BootstrapTest extends TestCase {

    /**
     * Sets up the tests
     *
     * @access  public
     */
    function setUp() {
      if (!isset($_SERVER['_'])) return throw(new PrerequisitesNotMetError(
        'This test can only be run in a non-web environment'
      ));
    }
  
    /**
     * Retrieve PHP binary path. Converts the path to a proper
     * windows path in case the PHP binary has been invoked through
     * a cygwin path.
     *
     * @access  protected
     * @return  string
     */
    function _binary() {
      static $binary= NULL;
      
      if (!$binary) {
        $binary= preg_replace('#^/cygdrive/(\w)/#', '$1:/', $_SERVER['_']);
      }
      return $binary;
    }

    /**
     * Run XP script and check exitcode
     *
     * @access  public
     * @param   int code expected exitcode
     * @param   string source sourcecode to execute
     */
    function assertExitCode($code, $source) {
      try(); {
        $p= &new Process($this->_binary().' -dinclude_path='.ini_get("include_path"));
        $p->in->write('<?php '.$source.'?>');
        $p->close();
      } if (catch('Exception', $e)) {
        return throw($e);
      }
      
      $this->assertEquals($code, $p->exitValue());
    }
    
    /**
     * Test
     *
     * @access  public
     */
    #[@test]
    function emptyBootstrap() {
      $this->assertExitcode(0, 'require("lang.base.php");');
    }
    
    /**
     * Test
     *
     * @access  public
     */
    #[@test]
    function useOfExistingFile() {
      $this->assertExitcode(0, 'require("lang.base.php"); uses("'.$this->getClassName().'");');
    }    
    
    /**
     * Test
     *
     * @access  public
     */
    #[@test]
    function useOfNonexistingFile() {
      $this->assertExitcode(255, 'require("lang.base.php"); uses("does.not.exist");');
    }
    
    /**
     * Test
     *
     * @access  public
     */
    #[@test]
    function recursiveInclusion() {
      $this->assertExitcode(123, '
        require("lang.base.php"); 
        uses("net.xp_framework.unittest.bootstrap.A");
        
        exit(123);
      ');
    }
    
    /**
     * Test
     *
     * @access  public
     */
    #[@test]
    function recursiveInclusionWithTicks() {
      $this->assertExitcode(123, '
        declare(ticks=1);
        require("lang.base.php");
        uses("net.xp_framework.unittest.bootstrap.A");
        
        exit(123);
      ');
    }
    
    
  }
?>

{'fraction_non_alphanumeric': 0.16478555304740405, 'fraction_numerical': 0.007592858608659963, 'mean_word_length': 1.8027602070155262, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1919096', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1557, 'n_words': 294}