<commit_before>#!/usr/bin/perl

use Logic::Tools;
use Getopt::Long;
use Cwd;

use strict;

my $my_dir = getcwd;


#test_dir - simple test for all scripts
#specific_test_dir - optional path to script specific test
my ($path,$script_name,$src_script_dir,$dst_script_dir,$script_cfg_name,$src_script_cfg_dir,$dst_script_cfg_dir,$test_dir,$specific_test_dir,$emails,$test_only);

GetOptions( "path=s"                => \$path, 
            "script_name=s"         => \$script_name,
            "src_script_dir=s"      => \$src_script_dir,
            "dst_script_dir=s"      => \$dst_script_dir,
            "script_cfg_name=s"     => \$script_cfg_name,
            "src_script_cfg_dir=s"  => \$src_script_cfg_dir,
            "dst_script_cfg_dir=s"  => \$dst_script_cfg_dir,
            "test_dir=s"            => \$test_dir,
            "specific_test_dir=s"   => \$specific_test_dir,
            "emails=s"              => \$emails,
            "test_only=s"           => \$test_only);


my $tools=Logic::Tools->new(logfile => $my_dir.'/'.$path.'/deploy.log');

$tools->logprint("info","unit test [$script_name]: $script_name");

$tools->logprint("info","unit test [$script_name]: read test dir $test_dir");

opendir(my $test_dir_hdl,$test_dir) || $tools -> logprint("error","unit test [$script_name]:не удалось открыть каталог $test_dir");

my @tests=readdir($test_dir_hdl);

my %tests;
foreach(@tests)
{
    if($_=~/^(\d\d).+t$/)
    {
        $tests{$1}=$_;
    }
}
closedir $test_dir_hdl;

my @test_num;
foreach my $key (keys %tests)
{
    push(@test_num,$key);
}

@test_num = sort { $a <=> $b } @test_num;

#make dir for tests log
mkdir($my_dir.'/'.$src_script_dir.'/testlog');
#execute test in sequence
foreach(@test_num)
{
    my $command='sudo perl '.$my_dir.'/'.$test_dir.'/'.$tests{$_}.' '.$my_dir.'/'.$src_script_dir.'/script'.' 1>>'.$my_dir.'/'.$src_script_dir.'/testlog/'.$tests{$_}.'.log'.' 2>>'.$my_dir.'/'.$src_script_dir.'/testlog/'.$tests{$_}.'.log';
    $tools->logprint("info","unit test [$script_name]: $tests{$_} run $command");
    `$command`;
    my $test_name=$tests{$_};
    open(my $test_log,"<",$my_dir.'/'.$src_script_dir.'/testlog/'.$tests{$_}.'.log');
    my $error_count=0;
    my @message;
    while (<$test_log>) 
    {
        chomp;
        $tools->logprint("info","unit test [$script_name]: $test_name - $_");
        #unless($_=~/^ok.+/||$_=~/^\d+.+\d+$/)
        if($_=~/^not\sok.+/||$_=~/^.+not\sok.+/)
        {
            print $_."\n";
            $tools->logprint("error","unit test [$script_name]: $test_name - $_");
            push(@message,$_);
            $error_count++;
        }
    }
    close($test_log);
    if($error_count>0)
    {
        $tools->logprint("error","unit test [$script_name]: project has many error: $error_count");
        my $command=$path.'/install/mail_send.pl'.
                                ' -emails '.$emails.
                                ' -theme '.'"project has many error: '.$error_count.'"'.
                                ' -message "'.join("\n",@message).'"'.
                                ' -path '.$path;
        $tools->logprint("info","unit test [$script_name]: send mail $command");
        `$command`;
        print -1;
        exit;
    }
}

#------------------------------------------------------------------------------------------------------------------------------------------------------------------<commit_msg>try fix error<commit_after>#!/usr/bin/perl

use Logic::Tools;
use Getopt::Long;
use Cwd;

use strict;

my $my_dir = getcwd;


#test_dir - simple test for all scripts
#specific_test_dir - optional path to script specific test
my ($path,$script_name,$src_script_dir,$dst_script_dir,$script_cfg_name,$src_script_cfg_dir,$dst_script_cfg_dir,$test_dir,$specific_test_dir,$emails,$test_only);

GetOptions( "path=s"                => \$path, 
            "script_name=s"         => \$script_name,
            "src_script_dir=s"      => \$src_script_dir,
            "dst_script_dir=s"      => \$dst_script_dir,
            "script_cfg_name=s"     => \$script_cfg_name,
            "src_script_cfg_dir=s"  => \$src_script_cfg_dir,
            "dst_script_cfg_dir=s"  => \$dst_script_cfg_dir,
            "test_dir=s"            => \$test_dir,
            "specific_test_dir=s"   => \$specific_test_dir,
            "emails=s"              => \$emails,
            "test_only=s"           => \$test_only);


my $tools=Logic::Tools->new(logfile => $my_dir.'/'.$path.'/deploy.log');

$tools->logprint("info","unit test [$script_name]: $script_name");

$tools->logprint("info","unit test [$script_name]: read test dir $test_dir");

opendir(my $test_dir_hdl,$test_dir) || $tools -> logprint("error","unit test [$script_name]:не удалось открыть каталог $test_dir");

my @tests=readdir($test_dir_hdl);

my %tests;
foreach(@tests)
{
    if($_=~/^(\d\d).+t$/)
    {
        $tests{$1}=$_;
    }
}
closedir $test_dir_hdl;

my @test_num;
foreach my $key (keys %tests)
{
    push(@test_num,$key);
}

@test_num = sort { $a <=> $b } @test_num;

#make dir for tests log
mkdir($my_dir.'/'.$src_script_dir.'/testlog');
#execute test in sequence
foreach(@test_num)
{
    my $command='sudo perl '.$my_dir.'/'.$test_dir.'/'.$tests{$_}.' '.$my_dir.'/'.$src_script_dir.'/script'.' 1>>'.$my_dir.'/'.$src_script_dir.'/testlog/'.$tests{$_}.'.log'.' 2>>'.$my_dir.'/'.$src_script_dir.'/testlog/'.$tests{$_}.'.log';
    $tools->logprint("info","unit test [$script_name]: $tests{$_} run $command");
    `$command`;
    my $test_name=$tests{$_};
    open(my $test_log,"<",$my_dir.'/'.$src_script_dir.'/testlog/'.$tests{$_}.'.log');
    my $error_count=0;
    my @message;
    while (<$test_log>) 
    {
        chomp;
        $tools->logprint("info","unit test [$script_name]: $test_name - !$_!");
        #unless($_=~/^ok.+/||$_=~/^\d+.+\d+$/)
        if($_=~/^not.ok.+/||$_=~/^.+not.ok.+/)
        {
            print $_."\n";
            $tools->logprint("error","unit test [$script_name]: $test_name - $_");
            push(@message,$_);
            $error_count++;
        }
    }
    close($test_log);
    if($error_count>0)
    {
        $tools->logprint("error","unit test [$script_name]: project has many error: $error_count");
        my $command=$path.'/install/mail_send.pl'.
                                ' -emails '.$emails.
                                ' -theme '.'"project has many error: '.$error_count.'"'.
                                ' -message "'.join("\n",@message).'"'.
                                ' -path '.$path;
        $tools->logprint("info","unit test [$script_name]: send mail $command");
        `$command`;
        print -1;
        exit;
    }
}

#------------------------------------------------------------------------------------------------------------------------------------------------------------------
{'fraction_non_alphanumeric': 0.2448800468110006, 'fraction_numerical': 0.0017554125219426564, 'mean_word_length': 2.163813049514114, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1878248', 'n_tokens_mistral': 2410, 'n_tokens_neox': 2345, 'n_words': 362}