<commit_before># $Id$

package Parrot::Test::Python;

use strict;
use warnings;

use File::Basename;

=head1 Parrot::Test::Python

Provide language specific testing routines here...

This is currently alarmingly similar to the generated subs in Parrot::Test.
Perhaps someone can do a better job of delegation here.

Note: this current verion is based on Pirate.  Previous versions were
based on ast2past and versions before that on pie-thon.

=cut

sub new {
    return bless {};
}

sub output_is() {
    my ($self, $code, $output, $desc) = @_;

    $count = $self->{builder}->current_test + 1;

    $desc = $language unless $desc;

    my $lang_f = Parrot::Test::per_test('.py',$count);
    my $py_out_f = "$lang_f.out";
    my $pirate_out_f = Parrot::Test::per_test('.pirate.out',$count);
    my $parrotdir = dirname $self->{parrot};

    $TEST_PROG_ARGS = $ENV{TEST_PROG_ARGS} || '-j -Oc';
    my $args = $TEST_PROG_ARGS;

    Parrot::Test::write_code_to_file( $code, $lang_f );

    my ($pycmd, $cmd, $pass, $dir);
    my $exit_code = 0;

    $pycmd = "python  $lang_f";
    $cmd = "pirate $lang_f";

    # For some reason, if you redirect both STDERR and STDOUT here,
    # you get a 38M file of garbage. We'll temporarily assume everything
    # works and ignore stderr.
    $exit_code = Parrot::Test::run_command($pycmd, STDOUT => $py_out_f);
    my $py_file = Parrot::Test::slurp_file($py_out_f);
    my $pirate_file;

    $exit_code |= Parrot::Test::run_command($cmd, STDOUT => $pirate_out_f);
    $pirate_file = Parrot::Test::slurp_file($pirate_out_f);
    $pass = $self->{builder}->is_eq( $pirate_file, $py_file, $desc );
    $self->{builder}->diag("'$cmd' failed with exit code $exit_code")
    if $exit_code and not $pass;

    unless ($ENV{POSTMORTEM}) {
        unlink $lang_f;
        unlink $py_out_f;
        unlink $pirate_out_f;
    }

    return $pass;
}

1;<commit_msg>track exit codes of python and pirate separately<commit_after># $Id$

package Parrot::Test::Python;

use strict;
use warnings;

use File::Basename;

=head1 Parrot::Test::Python

Provide language specific testing routines here...

This is currently alarmingly similar to the generated subs in Parrot::Test.
Perhaps someone can do a better job of delegation here.

Note: this current verion is based on Pirate.  Previous versions were
based on ast2past and versions before that on pie-thon.

=cut

sub new {
    return bless {};
}

sub output_is() {
    my ($self, $code, $output, $desc) = @_;

    $count = $self->{builder}->current_test + 1;

    $desc = $language unless $desc;

    my $lang_f = Parrot::Test::per_test('.py',$count);
    my $py_out_f = "$lang_f.out";
    my $pirate_out_f = Parrot::Test::per_test('.pirate.out',$count);
    my $parrotdir = dirname $self->{parrot};

    $TEST_PROG_ARGS = $ENV{TEST_PROG_ARGS} || '-j -Oc';
    my $args = $TEST_PROG_ARGS;

    Parrot::Test::write_code_to_file( $code, $lang_f );

    my ($pycmd, $cmd, $pass, $dir);

    $pycmd = "python  $lang_f";
    $cmd = "pirate $lang_f";

    # For some reason, if you redirect both STDERR and STDOUT here,
    # you get a 38M file of garbage. We'll temporarily assume everything
    # works and ignore stderr.
    my $python_exit_code = Parrot::Test::run_command($pycmd, STDOUT => $py_out_f);
    my $py_file = Parrot::Test::slurp_file($py_out_f);
    $self->{builder}->diag("'$pycmd' failed with exit code $python_exit_code")
        if $python_exit_code and not $pass;

    my $pirate_exit_code = Parrot::Test::run_command($cmd, STDOUT => $pirate_out_f);
    my $pirate_file = Parrot::Test::slurp_file($pirate_out_f);
    $pass = $self->{builder}->is_eq( $pirate_file, $py_file, $desc );
    $self->{builder}->diag("'$cmd' failed with exit code $pirate_exit_code")
        if $pirate_exit_code and not $pass;

    unless ($ENV{POSTMORTEM}) {
        unlink $lang_f;
        unlink $py_out_f;
        unlink $pirate_out_f;
    }

    return $pass;
}

1;
{'fraction_non_alphanumeric': 0.14278455284552846, 'fraction_numerical': 0.0033028455284552847, 'mean_word_length': 3.7319711538461537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '6855053', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1413, 'n_words': 381}