<commit_before><?php

namespace Transphpile\Tests;

use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Process\PhpProcess;
use Symfony\Component\Yaml\Yaml;
use Transphpile\IO\IOInterface;
use Transphpile\IO\SymfonyIO;
use Transphpile\Transpile\Transpile;



class FunctionalTestCase extends TestCase
{

    function assertTranspile($yamlPath)
    {
        $input = new ArrayInput(array());
        $stream = fopen('php://memory', 'rw', false);
        $output = new StreamOutput($stream);
        $symfonyio = new SymfonyIO($input, $output);


        // Load and parse yaml
        $config = Yaml::parse(file_get_contents($yamlPath));
        if (! isset($config['stdout']) && ! isset($config['stderr'])) {
            $this->fail('Stdout and/or stderr must be set in $yamlPath');
        }
        if (! isset($config['code'])) {
            $this->fail('Node code found in $yamlPath');
        }

        // Create temp file for code to transpile
        $tmpPath = tempnam(sys_get_temp_dir(), 'transphpile');
        file_put_contents($tmpPath, "<?php\n" . $config['code']);

        // Transpile code and send to stdout
        $transpiler = new Transpile($symfonyio);
        $transpiler->transpile($tmpPath, '-');

        // unlink tmp file
        unlink($tmpPath);

        // Fetch php5 code written by transpiler
        rewind($stream);
        $php5 = stream_get_contents($stream);


        // Run php5 code
        $process = new PhpProcess($php5);
        $process->run();
        $stdout = $process->getOutput();
        $stderr = $process->getErrorOutput();

        // Check output and error output
        if (isset($config['stdout'])) {
            $config['stdout'] = trim($config['stdout']);
            if (empty($stdout)) {
                $this->fail('stdout seems empty and should be "'.$config['stdout'].'"');
            }

            $this->assertRegExp('{'.$config['stdout'].'}', $stdout, isset($config['name']) ? $config['name'] : "");
        }
<commit_msg>stdout must always be set and halt when stderr is used, but not set in config<commit_after><?php

namespace Transphpile\Tests;

use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Process\PhpProcess;
use Symfony\Component\Yaml\Yaml;
use Transphpile\IO\IOInterface;
use Transphpile\IO\SymfonyIO;
use Transphpile\Transpile\Transpile;



class FunctionalTestCase extends TestCase
{

    function assertTranspile($yamlPath)
    {
        $input = new ArrayInput(array());
        $stream = fopen('php://memory', 'rw', false);
        $output = new StreamOutput($stream);
        $symfonyio = new SymfonyIO($input, $output);


        // Load and parse yaml
        $config = Yaml::parse(file_get_contents($yamlPath));
        if (! isset($config['stdout'])) {
            $this->fail('Stdout section not found in $yamlPath');
        }
        if (! isset($config['code'])) {
            $this->fail('Code section not found in $yamlPath');
        }

        // Create temp file for code to transpile
        $tmpPath = tempnam(sys_get_temp_dir(), 'transphpile');
        file_put_contents($tmpPath, "<?php\n" . $config['code']);

        // Transpile code and send to stdout
        $transpiler = new Transpile($symfonyio);
        $transpiler->transpile($tmpPath, '-');

        // unlink tmp file
        unlink($tmpPath);

        // Fetch php5 code written by transpiler
        rewind($stream);
        $php5 = stream_get_contents($stream);

        // Run php5 code
        $process = new PhpProcess($php5);
        $process->run();
        $stdout = $process->getOutput();
        $stderr = $process->getErrorOutput();

        if (! empty($stderr) && ! isset($config['stderr'])) {
            $this->fail('Error reported, but no stderr section found in $yamlPath');
        }

        // Check output and error output
        $config['stdout'] = trim($config['stdout']);
        $this->assertRegExp('{'.$config['stdout'].'}', $stdout, isset($config['name']) ? $config['name'] : "");

{'fraction_non_alphanumeric': 0.15315533980582524, 'fraction_numerical': 0.001941747572815534, 'mean_word_length': 2.732789855072464, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '5757781', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1186, 'n_words': 274}