Fail gracefully and count tests

Change-Id: Icd2ebbc0799b40abef1106bf7f5aae3082c2895d
diff --git a/t/test.t b/t/test.t
index 73c3515..877a7dc 100644
--- a/t/test.t
+++ b/t/test.t
@@ -1,6 +1,6 @@
 use strict;
 use warnings;
-use Test::More;
+use Test::More tests => 10;
 use Test::Script;
 use Test::TempDir::Tiny;
 use File::Copy;
@@ -10,17 +10,26 @@
 
 for my $morpho_fname (glob("t/data/*\.*\.zip")) {
     my $base_fname = $morpho_fname =~ s/(.*)\..*\.zip/$1.zip/r;
-    die "cannot find $base_fname" if (!-e $base_fname);
+    if (!-e $base_fname) {
+        fail("cannot find $base_fname");
+        next;
+    };
 
     my $conllu_fname = $base_fname =~ s/(.*)\.zip/$1.morpho.conllu/r;
-    die "cannot find $conllu_fname" if (!-e $conllu_fname);
+    if (!-e $conllu_fname) {
+        fail("cannot find $conllu_fname");
+        next;
+    };
 
     my $expected;
-    open(my $fh, '<', $conllu_fname) or die "cannot open file $conllu_fname"; {
+    if (open(my $fh, '<', $conllu_fname)) {
         local $/;
         $expected = <$fh>;
+        close($fh);
+    } else {
+        fail("cannot open file $conllu_fname");
+        next;
     }
-    close($fh);
     script_runs([ 'script/korapxml2conllu', $morpho_fname ], "Runs korapxml2conllu with pos and lemma annotated input");
     script_stdout_is $expected, "Converts $morpho_fname correctly";
 }
@@ -30,22 +39,30 @@
     next if (!-e $conllu_fname);
 
     my $expected;
-    open(my $fh, '<', $conllu_fname) or die "cannot open file $conllu_fname"; {
+    if (open(my $fh, '<', $conllu_fname)) {
         local $/;
         $expected = <$fh>;
+        close($fh);
+    } else {
+        fail("cannot open file $conllu_fname");
+        next;
     }
-    close($fh);
     script_runs([ 'script/korapxml2conllu', $base_fname ], "Runs korapxml2conllu with base input");
     script_stdout_is $expected, "Converts $base_fname correctly to CoNLL-U";
 }
 
 my $test_tempdir = tempdir();
 my $expected;
-open(my $fh, '<', "t/data/goe.morpho.conllu"); {
+my $conllu_fname = "t/data/goe.morpho.conllu";
+if(open(my $fh, '<', $conllu_fname )) {
     local $/;
     $expected = <$fh>;
-}
-close($fh);
+    close($fh);
+} else {
+    fail("cannot open file $conllu_fname");
+  }
+
+ok(length($expected) > 100, 'Output is not empty');
 
 my $zipfile = "$test_tempdir/goe.tree_tagger.zip";
 my $zipcontent;
@@ -54,10 +71,8 @@
 open(my $fh, ">", $zipfile) or fail("cannot open file $zipfile for writing");
 print $fh $zipcontent;
 close($fh);
-
 copy("t/data/goe.zip", $test_tempdir);
 script_runs([ 'script/korapxml2conllu', "$test_tempdir/goe.tree_tagger.zip" ],
     "Converts $test_tempdir/goe.tree_tagger.zip to CoNLL-U");
 script_stdout_is $expected, "Full round trip: Converts goe.morpho.conllu to KorAP-XML and back to CoNLL-U correctly";
-
 done_testing;