<commit_before><?php namespace net\xp_framework\unittest\core;

use lang\Runnable;
use lang\Object;
use lang\Runtime;
use lang\Process;
use lang\reflect\Package;
use lang\ClassLoader;
use unittest\actions\VerifyThat;
use unittest\actions\RuntimeVersion;

/**
 * TestCase for newinstance() functionality. Some tests are skipped if
 * process execution has been disabled.
 */
class NewInstanceTest extends \unittest\TestCase {

  /** @return bool */
  protected function processExecutionEnabled() {
    return !Process::$DISABLED;
  }

  /**
   * Runs sourcecode inside a new runtime
   *
   * @param   string $src
   * @return  var[] an array with three elements: exitcode, stdout and stderr contents
   */
  protected function runInNewRuntime($src) {
    with ($out= $err= '', $p= Runtime::getInstance()->newInstance(null, 'class', 'xp.runtime.Evaluate', [])); {
      $p->in->write($src);
      $p->in->close();

      // Read output
      while ($b= $p->out->read()) { $out.= $b; }
      while ($b= $p->err->read()) { $err.= $b; }

      // Close child process
      $exitv= $p->close();
    }
    return [$exitv, $out, $err];
  }
  
  #[@test]
  public function new_class_with_empty_body() {
    $o= newinstance(Object::class, []);
    $this->assertInstanceOf(Object::class, $o);
  }
<commit_msg>Rewrite with to new form with block and return<commit_after><?php namespace net\xp_framework\unittest\core;

use lang\Runnable;
use lang\Object;
use lang\Runtime;
use lang\Process;
use lang\reflect\Package;
use lang\ClassLoader;
use unittest\actions\VerifyThat;
use unittest\actions\RuntimeVersion;

/**
 * TestCase for newinstance() functionality. Some tests are skipped if
 * process execution has been disabled.
 */
class NewInstanceTest extends \unittest\TestCase {

  /** @return bool */
  protected function processExecutionEnabled() {
    return !Process::$DISABLED;
  }

  /**
   * Runs sourcecode inside a new runtime
   *
   * @param   string $src
   * @return  var[] an array with three elements: exitcode, stdout and stderr contents
   */
  protected function runInNewRuntime($src) {
    return with (Runtime::getInstance()->newInstance(null, 'class', 'xp.runtime.Evaluate', []), function($p) use($src) {
      $p->in->write($src);
      $p->in->close();

      // Read output
      $out= $err= '';
      while ($b= $p->out->read()) { $out.= $b; }
      while ($b= $p->err->read()) { $err.= $b; }

      // Close child process
      $exitv= $p->close();
      return [$exitv, $out, $err];
    });
  }
  
  #[@test]
  public function new_class_with_empty_body() {
    $o= newinstance(Object::class, []);
    $this->assertInstanceOf(Object::class, $o);
  }

{'fraction_non_alphanumeric': 0.1609152288072018, 'fraction_numerical': 0.0, 'mean_word_length': 3.4082644628099175, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '5712783', 'n_tokens_mistral': 858, 'n_tokens_neox': 843, 'n_words': 222}