<commit_before>#!perl
use strict;
use warnings;
use File::Temp qw(tempdir);
use File::Copy qw(copy);

use Test::More;

plan skip_all => 'JSX_OPTS specified' if $ENV{JSX_OPTS};

plan tests => 32;

my @opts = (
    "",
    "--release",
    "--minify",
    "--release --minify",
);

{
    my $tmpdir = tempdir(CLEANUP => 1, DIR => ".");
    my %expected_from_3rdgen;

    for my $gen2opts (@opts) {
        is compile(
            "bin/jsx",
            "$tmpdir/gen2",
            $gen2opts,
        ), 0, "create 2nd gen '$gen2opts'";
        for my $gen3opts (@opts) {
            is compile(
                "$tmpdir/gen2",
                "$tmpdir/gen3",
                $gen3opts,
            ), 0, "create 3rd gen '$gen2opts' => '$gen3opts'";
            my $gen3output = slurp("$tmpdir/gen3");
            if (defined $expected_from_3rdgen{$gen3opts}) {
                is(
                    $expected_from_3rdgen{$gen3opts},
                    $gen3output,
                    "output of 3rd gen are equal '$gen2opts' => '$gen3opts'",
                );
            } else {
                $expected_from_3rdgen{$gen3opts} = $gen3output;
            }
        }
    }
}
done_testing;

sub compile {
    my ($bootstrap, $target, @opts) = @_;
    system(
        "make",
        "compiler-core",
        "BOOTSTRAP_COMPILER=$bootstrap",
        "COMPILER_TARGET=$target",
        "COMPILER_COMPILE_OPTS=" . join(" ", @opts, "--executable", "node"),
    );
}

sub slurp {
    my $fn = shift;
    open my $fh, "<", $fn or die "could not open file:$fn:$!";
    do { local $/; <$fh> };
}<commit_msg>compare the 3rd gen outputs with 2nd gen outputs<commit_after>#!perl
use strict;
use warnings;
use File::Temp qw(tempdir);
use File::Copy qw(copy);

use Test::More;

plan skip_all => 'JSX_OPTS specified' if $ENV{JSX_OPTS};

plan tests => 36;

my @opts = (
    "",
    "--release",
    "--minify",
    "--release --minify",
);

{
    my $tmpdir = tempdir(CLEANUP => 1, DIR => ".");
    my @expected_src;

    # compile 2nd gens, and store the expected source (to be compared with the result of 3rd gens)
    for (my $gen2 = 0; $gen2 < @opts; $gen2++) {
        is compile(
            "bin/jsx",
            "$tmpdir/gen2-$gen2",
            $opts[$gen2],
        ), 0, "create 2nd gen '$opts[$gen2]'";
        $expected_src[$gen2] = slurp("$tmpdir/gen2-$gen2");
    }

    # compile 3rd gens, and check their output
    for (my $gen2 = 0; $gen2 < @opts; $gen2++) {
        for (my $gen3 = 0; $gen3 < @opts; $gen3++) {
            is compile(
                "$tmpdir/gen2-$gen2",
                "$tmpdir/gen3.tmp",
                $opts[$gen3],
            ), 0, "create 3rd gen '$opts[$gen3]' from 2nd gen '$opts[$gen2]'";
            ok(
                $expected_src[$gen3] eq slurp("$tmpdir/gen3.tmp"),
                "output of 3rd gen is same for '$opts[$gen3]'"
            );
        }
    }
}
done_testing;

sub compile {
    my ($bootstrap, $target, @opts) = @_;
    system(
        "make",
        "compiler-core",
        "BOOTSTRAP_COMPILER=$bootstrap",
        "COMPILER_TARGET=$target",
        "COMPILER_COMPILE_OPTS=" . join(" ", @opts, "--executable", "node"),
    );
}

sub slurp {
    my $fn = shift;
    open my $fh, "<", $fn or die "could not open file:$fn:$!";
    do { local $/; <$fh> };
}
{'fraction_non_alphanumeric': 0.17058468957203135, 'fraction_numerical': 0.022001205545509342, 'mean_word_length': 1.9293909973521624, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 15, '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': '3908549', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1163, 'n_words': 280}