<commit_before>#!/usr/bin/env perl

Script->new->run;
exit;

package Script;

use strict;
use warnings;

use FindBin qw($Bin);
use Filesys::Notify::Simple;
use Getopt::Long;
use Test::Harness;
use Data::Debug;

use lib "$Bin/../lib";
use lib "$Bin/../t/lib";

use constant TESTDIR => "$Bin/../t";

sub new {
    my $class = shift;
    my $hash  = {};

    my ($verbose, $test);
    GetOptions(
        'verbose|v+' => \$verbose,
        'test|t=s'   => \$test,
    ) or die "Error in command line arguments\n";

    $Test::Harness::verbose = 1 if $verbose;

    $hash->{'verbose'} = $verbose;

    $hash->{'test'} = $test;

    return bless $hash, $class;
}

sub run {
    my $self = shift;

    $self->test_all_the_things();

    my $watcher = Filesys::Notify::Simple->new([ "$Bin/../lib" ]);

    while(1) {
        $watcher->wait(sub {
            for my $event (@_) {
                next unless $event->{'path'} =~ /\.pm$/; # only test perl module changes

                $self->test_all_the_things();
            }
        });
    }
}

sub test_all_the_things {
    my $self = shift;

    my @test_files = @{ $self->test_files() };

    $self->clear();

    runtests( @test_files );
}

sub test_files {
    my $self = shift;

    return $self->{'test_files'} ||= do {
        my @test_files;

        my $test = $self->{'test'};

        opendir my $dh, TESTDIR or die "Could not open test directory $!";
        while(my $file = readdir($dh)) {
            next unless $file =~ /\.t$/;
            next unless ! $test || $file =~ m/$test/i;

            push @test_files, TESTDIR . "/$file";
        }
        closedir $dh;

        die "No tests found to run" unless scalar @test_files;

        \@test_files;
    };
}

sub clear {
    print "\033[2J";    #clear the screen
    print "\033[0;0H"; #jump to 0,0
}

1;
<commit_msg>Replacing Test::Harness with TAP::Harness<commit_after>#!/usr/bin/env perl

Script->new->run;
exit;

package Script;

use strict;
use warnings;

use FindBin qw($Bin);
use Filesys::Notify::Simple;
use Getopt::Long;
use TAP::Harness;
use Data::Debug;

use lib "$Bin/../lib";
use lib "$Bin/../t/lib";

use constant TESTDIR => "$Bin/../t";

sub new {
    my $class = shift;
    my $hash  = {};

    my ($verbose, $test);
    GetOptions(
        'verbose|v+' => \$verbose,
        'test|t=s'   => \$test,
    ) or die "Error in command line arguments\n";

    $hash->{'verbose'} = $verbose;

    $hash->{'test'} = $test;

    return bless $hash, $class;
}

sub run {
    my $self = shift;

    $self->test_all_the_things();

    my $watcher = Filesys::Notify::Simple->new([ "$Bin/../lib" ]);

    while(1) {
        $watcher->wait(sub {
            for my $event (@_) {
                next unless $event->{'path'} =~ /\.pm$/; # only test perl module changes

                $self->test_all_the_things();
            }
        });
    }
}

sub harness {
    my $self = shift;

    return $self->{'harness'} ||= do {
        my $h = TAP::Harness->new({
            verbosity => $self->{'verbose'} || 0,
            lib       => [ "$Bin/../lib", "$Bin/../t/lib" ],
        });

        $h;
    };
}

sub test_all_the_things {
    my $self = shift;

    my @test_files = @{ $self->test_files() };

    $self->clear();

    $self->harness->runtests( @test_files );
}

sub test_files {
    my $self = shift;

    return $self->{'test_files'} ||= do {
        my @test_files;

        my $test = $self->{'test'};

        opendir my $dh, TESTDIR or die "Could not open test directory $!";
        while(my $file = readdir($dh)) {
            next unless $file =~ /\.t$/;
            next unless ! $test || $file =~ m/$test/i;

            push @test_files, TESTDIR . "/$file";
        }
        closedir $dh;

        die "No tests found to run" unless scalar @test_files;

        \@test_files;
    };
}

sub clear {
    print "\033[2J";    #clear the screen
    print "\033[0;0H"; #jump to 0,0
}

1;

{'fraction_non_alphanumeric': 0.18503435988801223, 'fraction_numerical': 0.007126495291422754, 'mean_word_length': 2.079937304075235, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 42, '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': '7605592', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1368, 'n_words': 349}