Automate-Animate-FFmpeg

 view release on metacpan or  search on metacpan

t/900-scripts.t  view on Meta::CPAN

#!/usr/bin/env perl

###################################################################
#### NOTE env-var PERL_TEST_TEMPDIR_TINY_NOCLEANUP=1 will stop erasing tmp files
###################################################################

use strict;
use warnings;

use utf8;

use lib 'blib/lib';

use Test::More;
use Test2::Plugin::UTF8;
use Test::Script;
use Test::TempDir::Tiny;
use File::Spec;
use FindBin;
use Cwd;
use Encode;
use File::Basename;
use Data::Roundtrip qw/perl2dump no-unicode-escape-permanently/;

use Automate::Animate::FFmpeg;

our $VERSION = '0.13';

my $curdir = $FindBin::Bin;

my $aaFF = Automate::Animate::FFmpeg->new();
ok(defined $aaFF, 'Automate::Animate::FFmpeg->new()'." : called and got defined result.") or BAIL_OUT;
my $exe; if( !defined($exe=$aaFF->ffmpeg_executable()) || ($exe=~/^\s*$/) || (! -x $exe) ){
	diag "There is no FFmpeg executable set in this module. No tests will be run.";
	done_testing;
	exit(0);
}

# if for debug you change this make sure that it has path in it e.g. ./xyz
my $tmpdir = tempdir(); # will be erased unless a BAIL_OUT or env var set
ok(-d $tmpdir, "output dir exists");

my $FAILURE_REGEX = qr/(?:\: error,)|(?:Usage)/;

my $FRAME_DURATION = 3;
my $VERBOSITY = 10;
my $outfile = File::Spec->catfile($tmpdir, "γαγαγαγ.mp4");
my @IMGS = (
	File::Spec->catfile($curdir, 't-data', 'images', 'blue.png'),
	File::Spec->catfile($curdir, 't-data', 'images', 'green.png'),
	File::Spec->catfile($curdir, 't-data', 'images', 'red.png'),
	File::Spec->catfile($curdir, 't-data', 'images', 'κίτρινο.png'),
	File::Spec->catfile($curdir, 't-data', 'images', 'Περισσότερα', 'πράσινο.png'),
	File::Spec->catfile($curdir, 't-data', 'images', 'Περισσότερα', 'Κόκκινο.png'),
);
my $input_images_file = File::Spec->catfile($tmpdir, "filelist.txt");
my $FH;
ok(open($FH, '>:encoding(UTF-8)', $input_images_file), "opened file '$input_images_file' for writing the file list.") or BAIL_OUT;
print $FH join("\n", @IMGS)."\n"; close $FH;

# script must be relative!
my $execu = File::Spec->catfile('script', 'automate-animate-ffmpeg.pl');

my @TESTS = (
	# test the scripts (the keys) with the scripts contained in the values
	# script-filename	  CLI-params-for-success    CLI-params-for-failure
	# input pattern to select exactly 4 images with shell glob
	[
		# will succeed
		[$execu, '--output-filename', $outfile, '--verbosity', $VERBOSITY, '--frame-duration', $FRAME_DURATION, '--input-pattern', '*.png', '.'],
		# will fail
		[$execu, '--output-filename', $outfile, '--verbosity', $VERBOSITY, '--frame-duration', $FRAME_DURATION, '--input-pattern', 'aa*.png', '.'],
	],
	# input pattern to select exactly 4 images with regex
	[
		# will succeed
		[$execu, '--output-filename', $outfile, '--verbosity', $VERBOSITY, '--frame-duration', $FRAME_DURATION, '--input-pattern', qw!regex(/.+?\.png/i)!, '.'],
		# will fail
		[$execu, '--output-filename', $outfile, '--verbosity', $VERBOSITY, '--frame-duration', $FRAME_DURATION, '--input-pattern', qw!regex(/.+?\.tiff/i)!, '.'],
	],
	# 4 input images using --input-image for each
	[
		# will succeed



( run in 0.764 second using v1.01-cache-2.11-cpan-39bf76dae61 )