<commit_before><?php

/**
 * This file is part of the symfony package.
 * (c) 2004-2006 <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * Unit test library.
 *
 * @package    lime
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id: lime.php 29529 2010-05-19 13:41:48Z fabien $
 */
class lime_test
{
  const EPSILON = 0.0000000001;

  protected $test_nb = 0;
  protected $output  = null;
  protected $results = array();
  protected $options = array();

  static protected $all_results = array();

  public function __construct($plan = null, $options = array())
  {
    // for BC
    if (!is_array($options))
    {
      $options = array('output' => $options);
    }

    $this->options = array_merge(array(
      'force_colors'    => false,
      'output'          => null,
      'verbose'         => false,
      'error_reporting' => false,
    ), $options);

    $this->output = $this->options['output'] ? $this->options['output'] : new lime_output($this->options['force_colors']);

    $caller = $this->find_caller(debug_backtrace());
    self::$all_results[] = array(
      'file'  => $caller[0],
      'tests' => array(),
      'stats' => array('plan' => $plan, 'total' => 0, 'failed' => array(), 'passed' => array(), 'skipped' => array(), 'errors' => array()),
    );

    $this->results = &self::$all_results[count(self::$all_results) - 1];

    null !== $plan and $this->output->echoln(sprintf("1..%d", $plan));

    set_error_handler(array($this, 'handle_error'));
    set_exception_handler(array($this, 'handle_exception'));
  }

  static public function reset()
  {
    self::$all_results = array();
  }

  static public function to_array()
  {
    return self::$all_results;
  }

  static public function to_xml($results = null)
  {
    if (is_null($results))
    {
      $results = self::$all_results;
    }

    $dom = new DOMDocument('1.0', 'UTF-8');
    $dom->formatOutput = true;
    $dom->appendChild($testsuites = $dom->createElement('testsuites'));

    $errors = 0;
    $failures = 0;
    $errors = 0;
    $skipped = 0;
    $assertions = 0;

    foreach ($results as $result)
    {
      $testsuites->appendChild($testsuite = $dom->createElement('testsuite'));
      $testsuite->setAttribute('name', basename($result['file'], '.php'));
      $testsuite->setAttribute('file', $result['file']);
      $testsuite->setAttribute('failures', count($result['stats']['failed']));
      $testsuite->setAttribute('errors', count($result['stats']['errors']));
      $testsuite->setAttribute('skipped', count($result['stats']['skipped']));
      $testsuite->setAttribute('tests', $result['stats']['plan']);
      $testsuite->setAttribute('assertions', $result['stats']['plan']);

      $failures += count($result['stats']['failed']);
      $errors += count($result['stats']['errors']);
      $skipped += count($result['stats']['skipped']);
      $assertions += $result['stats']['plan'];

      foreach ($result['tests'] as $test)
      {
        $testsuite->appendChild($testcase = $dom->createElement('testcase'));
        $testcase->setAttribute('name', $test['message']);
        $testcase->setAttribute('file', $test['file']);
        $testcase->setAttribute('line', $test['line']);
        $testcase->setAttribute('assertions', 1);
        if (!$test['status'])
        {
          $testcase->appendChild($failure = $dom->createElement('failure'));
          $failure->setAttribute('type', 'lime');<commit_msg>Avoid a PHP Warning on setAttribute<commit_after><?php

/**
 * This file is part of the symfony package.
 * (c) 2004-2006 <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * Unit test library.
 *
 * @package    lime
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id: lime.php 29529 2010-05-19 13:41:48Z fabien $
 */
class lime_test
{
  const EPSILON = 0.0000000001;

  protected $test_nb = 0;
  protected $output  = null;
  protected $results = array();
  protected $options = array();

  static protected $all_results = array();

  public function __construct($plan = null, $options = array())
  {
    // for BC
    if (!is_array($options))
    {
      $options = array('output' => $options);
    }

    $this->options = array_merge(array(
      'force_colors'    => false,
      'output'          => null,
      'verbose'         => false,
      'error_reporting' => false,
    ), $options);

    $this->output = $this->options['output'] ? $this->options['output'] : new lime_output($this->options['force_colors']);

    $caller = $this->find_caller(debug_backtrace());
    self::$all_results[] = array(
      'file'  => $caller[0],
      'tests' => array(),
      'stats' => array('plan' => $plan, 'total' => 0, 'failed' => array(), 'passed' => array(), 'skipped' => array(), 'errors' => array()),
    );

    $this->results = &self::$all_results[count(self::$all_results) - 1];

    null !== $plan and $this->output->echoln(sprintf("1..%d", $plan));

    set_error_handler(array($this, 'handle_error'));
    set_exception_handler(array($this, 'handle_exception'));
  }

  static public function reset()
  {
    self::$all_results = array();
  }

  static public function to_array()
  {
    return self::$all_results;
  }

  static public function to_xml($results = null)
  {
    if (is_null($results))
    {
      $results = self::$all_results;
    }

    $dom = new DOMDocument('1.0', 'UTF-8');
    $dom->formatOutput = true;
    $dom->appendChild($testsuites = $dom->createElement('testsuites'));

    $errors = 0;
    $failures = 0;
    $errors = 0;
    $skipped = 0;
    $assertions = 0;

    foreach ($results as $result)
    {
      $testsuites->appendChild($testsuite = $dom->createElement('testsuite'));
      $testsuite->setAttribute('name', basename($result['file'], '.php'));
      $testsuite->setAttribute('file', $result['file']);
      $testsuite->setAttribute('failures', count($result['stats']['failed']));
      $testsuite->setAttribute('errors', count($result['stats']['errors']));
      $testsuite->setAttribute('skipped', count($result['stats']['skipped']));
      $testsuite->setAttribute('tests', $result['stats']['plan']);
      $testsuite->setAttribute('assertions', $result['stats']['plan']);

      $failures += count($result['stats']['failed']);
      $errors += count($result['stats']['errors']);
      $skipped += count($result['stats']['skipped']);
      $assertions += $result['stats']['plan'];

      foreach ($result['tests'] as $test)
      {
        $testsuite->appendChild($testcase = $dom->createElement('testcase'));
        $testcase->setAttribute('name', utf8_encode($test['message']));
        $testcase->setAttribute('file', $test['file']);
        $testcase->setAttribute('line', $test['line']);
        $testcase->setAttribute('assertions', 1);
        if (!$test['status'])
        {
          $testcase->appendChild($failure = $dom->createElement('failure'));
          $failure->setAttribute('type', 'lime');
{'fraction_non_alphanumeric': 0.2000281333520889, 'fraction_numerical': 0.01477000984667323, 'mean_word_length': 3.5518565941101152, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 2, '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': '4299065', 'n_tokens_mistral': 2248, 'n_tokens_neox': 2166, 'n_words': 442}