<commit_before>#!/usr/bin/env php
<?php
set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path());

//function error_handler($errno, $errstr, $errfile, $errline, $errcontext)
//{
//  if($errno != E_STRICT)
//    throw new Exception("Error happened: $errstr($errno) in $errfile@$errline($errcontext)");
//}
//set_error_handler('error_handler');

require_once(dirname(__FILE__) . '/tests_runner/common.inc.php');
require_once(dirname(__FILE__) . '/tests_runner/src/lmbTestRunner.class.php');
require_once(dirname(__FILE__) . '/tests_runner/src/lmbTestTreeFilePathNode.class.php');
require_once(dirname(__FILE__) . '/tests_runner/src/lmbTestTreeGlobNode.class.php');

$fork = true;
$quiet = false;
$tests = array();
$skipped = array();

function out($msg)
{
  global $quiet;

  if(!$quiet)
    echo $msg;
}

function process_argv(&$argv, &$defines = array())
{
  global $quiet;
  global $fork;
  global $skipped;

  $new_argv = array();
  $selected_option = '';
  $next_is_def = false;
  foreach($argv as $arg)
  {
    // control arguments
    switch($arg)
    {
      case '-D':
        $next_is_def = true;
        break;
      case '-q':
        $quiet = true;
        break;
      case '--no-fork':
        $fork = false;
        break;
      case '--include-path':
      case '--skip':
        $selected_option = $arg;
        break;
      case '--':
        $selected_option = '';
        break;
      default:
        if($next_is_def)
        {
          list($dn,$dv) = explode('=', $arg);
          $defines[] = "-D $dn=$dv";
          echo "Defining $dn=$dv\n";
          define("$dn", $dv);
          $next_is_def = false;
          break;
        }
        // value arguments
        switch($selected_option)
        {
          case '--skip':
            $skipped[] = $arg;
            break;
          case '--include-path':
            set_include_path(dirname(__FILE__) . '/' . $arg . PATH_SEPARATOR . get_include_path());
            $selected_option = '';
            break;
          default:
            $new_argv[] = $arg;
            break;
        }
    }
  }
  $argv = $new_argv;
}

function get_php_bin()
{
  ob_start();
  phpinfo(INFO_GENERAL);
  $info = ob_get_contents();
  ob_end_clean();

  if(isset($_ENV["_"]) && basename($_ENV["_"]) != basename(__FILE__))
    $php_bin = $_ENV["_"];
  else
    $php_bin = "php";//any better way to guess it otherwise?

  $php_ini = "";

  $lines = explode("\n", $info);
  foreach($lines as $line)
  {
    if(preg_match('~^Loaded Configuration File\s*=>\s*(.*)$~', $line, $m))
    {
      if(file_exists($m[1]))
        $php_ini = "-c " . $m[1];
    }
  }
  return $php_bin . " " . $php_ini;
}

process_argv($argv, $defines);

if(sizeof($argv) > 1)
  $tests = array_splice($argv, 1);

if(!$tests)
  $tests = glob("*", GLOB_ONLYDIR);

$tests = array_diff($tests, $skipped);

if($fork)
{
  $php_bin = get_php_bin();
  out("=========== Forking processes for each test(PHP cmdline '$php_bin') ===========\n");
}

$res = true;
foreach($tests as $test)
{
  if(file_exists($test) || is_dir($test))
  {
    if($fork)
    {
      system($php_bin . " " . __FILE__ . " -q --no-fork " . implode(" ", $defines) . " $test", $ret);
      if($ret != 0)
        $res = false;
    }
    else<commit_msg>[svn r7954] -- minor fixes<commit_after>#!/usr/bin/env php
<?php
set_include_path(dirname(__FILE__) . '/../' . PATH_SEPARATOR . get_include_path());

//function error_handler($errno, $errstr, $errfile, $errline, $errcontext)
//{
//  if($errno != E_STRICT)
//    throw new Exception("Error happened: $errstr($errno) in $errfile@$errline($errcontext)");
//}
//set_error_handler('error_handler');

require_once(dirname(__FILE__) . '/tests_runner/common.inc.php');
require_once(dirname(__FILE__) . '/tests_runner/src/lmbTestRunner.class.php');
require_once(dirname(__FILE__) . '/tests_runner/src/lmbTestTreeFilePathNode.class.php');
require_once(dirname(__FILE__) . '/tests_runner/src/lmbTestTreeGlobNode.class.php');

$fork = true;
$quiet = false;
$tests = array();
$skipped = array();

function out($msg)
{
  global $quiet;

  if(!$quiet)
    echo $msg;
}

function process_argv(&$argv, &$defines = array())
{
  global $quiet;
  global $fork;
  global $skipped;

  $new_argv = array();
  $selected_option = '';
  $next_is_def = false;
  foreach($argv as $arg)
  {
    // control arguments
    switch($arg)
    {
      case '-D':
        $next_is_def = true;
        break;
      case '-q':
        $quiet = true;
        break;
      case '--no-fork':
        $fork = false;
        break;
      case '--include-path':
      case '--skip':
        $selected_option = $arg;
        break;
      case '--':
        $selected_option = '';
        break;
      default:
        if($next_is_def)
        {
          list($dn,$dv) = explode('=', $arg);
          $defines[] = "-D $dn=$dv";
          echo "Defining $dn=$dv\n";
          define("$dn", $dv);
          $next_is_def = false;
          break;
        }
        // value arguments
        switch($selected_option)
        {
          case '--skip':
            $skipped[] = $arg;
            break;
          case '--include-path':
            set_include_path(dirname(__FILE__) . '/' . $arg . PATH_SEPARATOR . get_include_path());
            $selected_option = '';
            break;
          default:
            $new_argv[] = $arg;
            break;
        }
    }
  }
  $argv = $new_argv;
}

function get_php_bin()
{
  ob_start();
  phpinfo(INFO_GENERAL);
  $info = ob_get_contents();
  ob_end_clean();

  if(isset($_ENV["_"]) && basename($_ENV["_"]) != basename(__FILE__))
    $php_bin = $_ENV["_"];
  else
    $php_bin = "php";//any better way to guess it otherwise?

  $php_ini = "";

  $lines = explode("\n", $info);
  foreach($lines as $line)
  {
    if(preg_match('~^Loaded Configuration File\s*=>\s*(.*)$~', $line, $m))
    {
      if(file_exists($m[1]))
        $php_ini = "-c " . $m[1];
    }
  }
  return $php_bin . " " . $php_ini;
}

process_argv($argv, $defines);

if(sizeof($argv) > 1)
  $tests = array_splice($argv, 1);

if(!$tests)
  $tests = glob("*", GLOB_ONLYDIR);

$tests = array_diff($tests, $skipped);

if($fork)
{
  $php_bin = get_php_bin();
  out("=========== Forking processes for each test path(PHP cmdline '$php_bin') ===========\n");
}

$res = true;
foreach($tests as $test)
{
  if(file_exists($test) || is_dir($test))
  {
    if($fork)
    {
      system($php_bin . " " . __FILE__ . " -q --no-fork " . implode(" ", $defines) . " $test", $ret);
      if($ret != 0)
        $res = false;
    }
    else
{'fraction_non_alphanumeric': 0.19323377019201463, 'fraction_numerical': 0.0021334958854007926, 'mean_word_length': 2.498400852878465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3346312', 'n_tokens_mistral': 2388, 'n_tokens_neox': 2327, 'n_words': 435}