<commit_before><commit_msg>add tests for findfragments command<commit_after>#!/usr/bin/env perl

use 5.010;
use strict;
use warnings FATAL => 'all';
use autodie             qw(open);
use IPC::System::Simple qw(system);
use Capture::Tiny       qw(capture);
use File::Path          qw(remove_tree);
use File::Find;
use File::Spec;
#use Data::Dump::Color;

use Test::More tests => 5;

$| = 1;

my $devtests = 0;
if (defined $ENV{TEPHRA_ENV} && $ENV{TEPHRA_ENV} eq 'development') {
    $devtests = 1;
}

my $cmd      = File::Spec->catfile('blib', 'bin', 'tephra');
my $testdir  = File::Spec->catdir('t', 'test_data');
my $genome   = File::Spec->catfile($testdir, 'ref.fas');
my $repeatdb = File::Spec->catfile($testdir, 'repdb.fas');
my $masked   = File::Spec->catfile($testdir, 'ref_masked.fas');
my $outfile  = File::Spec->catfile($testdir, 'ref_masked_tephra_repdb_fragments.gff3');
my $log      = File::Spec->catfile($testdir, 'ref_findfragments.log');
my $thrlog   = File::Spec->catfile($testdir, 'tephra_fragment_searches.log');

SKIP: {
    skip 'skip development tests', 3 unless $devtests;
    my @results = capture { system([0..5], "$cmd findfragments -h") };

    ok(@results, 'Can execute findfragments subcommand');
    
    my $frag_cmd = "$cmd findfragments -g $masked -d $repeatdb -o $outfile > $log";
    ##say STDERR $frag_cmd;
    
    my @ret = capture { system([0..5], $frag_cmd) };

    ok( -e $outfile, 'Can run findfragments and generate GFF3 output' );
    ok( -e $log,     'Expected log for findfragments command produced' );
    ok( -e $thrlog,  'Expected log for findfragments command produced' );
    
    open my $in, '<', $outfile;
    my $fragct = 0;
    while (<$in>) {
	chomp;
	next if /^#/;
	$fragct++;
    }

    ok( $fragct == 3, 'Expected number of fragments discovered' );

    ## clean up
    unlink $log, $thrlog, $masked, $outfile;
};

done_testing();
{'fraction_non_alphanumeric': 0.17575436739015352, 'fraction_numerical': 0.008999470619375331, 'mean_word_length': 3.8091603053435112, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4400003', 'n_tokens_mistral': 713, 'n_tokens_neox': 696, 'n_words': 177}