<commit_before>#! perl
# Copyright (C) 2009, The Perl Foundation.
# $Id$

use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );

use File::Temp qw(tempfile);
use Test::More qw(no_plan);

use Parrot::Test;
use Parrot::Config qw(%PConfig);


use lib qw( lib );
BEGIN {
    eval 'use Parrot::Test::Pod';
    if ($@) {
        plan skip_all => 'Prerequisites for Parrot::Test::Pod not satisfied';
        exit;
    }
}

my $self = Parrot::Test::Pod->new( {
    argv => [ @ARGV ],
} );

my $need_testing_ref = $self->identify_files_for_POD_testing();

foreach my $file ( @{ $need_testing_ref } ) {
    foreach my $contents (get_samples($file)) {
        compile_pir_ok($contents, $file);
    }
}

#################### SUBROUTINES ####################

sub compile_pir_ok {
    my $code = shift;
    my $file = shift;

    my ($fh,$tempfile) = tempfile(SUFFIX => '.pir', UNLINK => 1);
    print {$fh} $code;
    close $fh;

    my $cmd = File::Spec->curdir() . $PConfig{slash} .
              $PConfig{test_prog} . " -o " . File::Spec->devnull() . " " .
              $tempfile;

    my $description = "$file\n$code";

    is(system($cmd), 0 , $description);
}

sub get_samples {
    my $file = shift;<commit_msg>[t] fix argv handling to actually so specifying files on the command line actually works.<commit_after>#! perl
# Copyright (C) 2009, The Perl Foundation.
# $Id$

use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );

use File::Temp qw(tempfile);
use Test::More qw(no_plan);

use Parrot::Test;
use Parrot::Config qw(%PConfig);


use lib qw( lib );
BEGIN {
    eval 'use Parrot::Test::Pod';
    if ($@) {
        plan skip_all => 'Prerequisites for Parrot::Test::Pod not satisfied';
        exit;
    }
}

my @files = @ARGV;

if (!@files) {
  my $podTester = Parrot::Test::Pod->new();
  @files = @{$podTester->identify_files_for_POD_testing()};
}

foreach my $file ( @files ) {
    foreach my $contents (get_samples($file)) {
        compile_pir_ok($contents, $file);
    }
}

#################### SUBROUTINES ####################

sub compile_pir_ok {
    my $code = shift;
    my $file = shift;

    my ($fh,$tempfile) = tempfile(SUFFIX => '.pir', UNLINK => 1);
    print {$fh} $code;
    close $fh;

    my $cmd = File::Spec->curdir() . $PConfig{slash} .
              $PConfig{test_prog} . " -o " . File::Spec->devnull() . " " .
              $tempfile;

    my $description = "$file\n$code";

    is(system($cmd), 0 , $description);
}

sub get_samples {
    my $file = shift;
{'fraction_non_alphanumeric': 0.20239520958083831, 'fraction_numerical': 0.004790419161676647, 'mean_word_length': 3.0224719101123596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '3345025', 'n_tokens_mistral': 931, 'n_tokens_neox': 881, 'n_words': 223}