commit cc4177a9707d4b5c488012eb7c947dfc322adc3a
parent 512846331e774634fc3de8dc2babfc541f0c3574
Author: Kyle Milz <kyle@0x30.net>
Date: Mon, 9 Oct 2017 22:16:38 -0600
t: add 2 new gl tests
1) checks error given when $CITRUN_PROCDIR exists but is not a directory
2) the welcome message when no runtime files have been found yet
Diffstat:
4 files changed, 98 insertions(+), 0 deletions(-)
diff --git a/t/gl/welcome.tga b/t/gl/welcome.tga
Binary files differ.
diff --git a/t/gl_nodir.t b/t/gl_nodir.t
@@ -0,0 +1,22 @@
+#
+# Check that citrun_gl outputs a good error message when $CITRUN_PROCDIR is bad.
+#
+use Modern::Perl;
+
+use t::utils;
+plan tests => 3;
+
+
+my $gl = Test::Cmd->new( prog => 'bin/citrun_gl', workdir => '' );
+
+my $procdir = $gl->workdir . "/procdir/";
+$ENV{CITRUN_PROCDIR} = $procdir;
+
+# Create a file in the exact place the directory is supposed to be.
+$gl->write( 'procdir', '' );
+$gl->run();
+
+my $err_good = "citrun_gl: opendir '$procdir': Not a directory";
+is( $gl->stdout, '', 'is stdout silent' );
+like( $gl->stderr, qr/$err_good/, 'is stderr silent' );
+is( $? >> 8, 1, 'is exit code nonzero' );
diff --git a/t/gl_utils.pm b/t/gl_utils.pm
@@ -0,0 +1,53 @@
+#
+# Shared utilities for citrun_gl testing.
+# - ok_image, an image diff and show function
+#
+use Modern::Perl;
+use File::Compare; # compare
+use Imager; # new
+use Test::More; # pass, fail, diag
+
+
+#
+# Compares the image given as the first argument with the image given as the
+# second argument and saves the result into the directory given as the third
+# argument.
+#
+# If differences are found, show an ascii art picture of the differences and try
+# and launch a graphical viewer too.
+#
+sub ok_image {
+ my $output_file = shift;
+ my $output_good = shift;
+ my $tmp_dir = shift;
+
+ if (compare( $output_file, $output_good )) {
+ my $a = Imager->new( file => $output_good ) or die Imager->errstr;
+ my $b = Imager->new( file => $output_file ) or die Imager->errstr;
+ my $diff = $a->difference( other => $b );
+
+ my $diff_file = "$tmp_dir/diff.tga";
+ $diff->write( file => $diff_file ) or die $diff->errstr;
+
+ # Try and show an ascii art picture of the differences.
+ if (open( my $cmd_out, '-|', "img2txt", "-f", "utf8", $diff_file )) {
+ diag("diff $diff_file");
+ diag("--- t/gl/basic.tga");
+ diag("+++ $output_file");
+ diag($_) while (<$cmd_out>);
+ close( $cmd_out );
+ } else {
+ die "\\-> Maybe try installing `libcaca`.";
+ }
+
+ system("imlib2_view $diff_file");
+ #system("xdg-open $diff_file");
+
+ fail( 'is render file identical' );
+ }
+ else {
+ pass( 'is render file identical' );
+ }
+}
+
+1;
diff --git a/t/gl_welcome.t b/t/gl_welcome.t
@@ -0,0 +1,23 @@
+#
+# Checks that opening the viewer without any runtime files shows the welcome
+# message.
+#
+use Modern::Perl;
+
+use t::gl_utils;
+use t::utils;
+plan tests => 4;
+
+
+my $gltest = Test::Cmd->new( prog => 'bin/citrun_gltest', workdir => '' );
+$ENV{CITRUN_PROCDIR} = $gltest->workdir . "/procdir/";
+
+my $output_file = File::Spec->catdir( $gltest->workdir, 'test.tga' );
+my $output_good = File::Spec->catfile( 't', 'gl', 'welcome.tga' );
+
+$gltest->run( args => "$output_file 800 600" );
+isnt( $gltest->stdout, '', 'is citrun_gltest stdout not silent' );
+is( $gltest->stderr, '', 'is citrun_gltest stderr silent' );
+is( $? >> 8, 0, 'is citrun_gltest exit code zero' );
+
+ok_image( $output_file, $output_good, $gltest->workdir );