1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
use Test::More tests => 12;
use Term::TtyRec::Plus;
my $frames_read;
# test missing file ############################################################
$frames_read = 0;
eval {
my $t = Term::TtyRec::Plus->new(
infile => "t/missing.ttyrec",
);
my $time = 0;
while (my $frame_ref = $t->next_frame()) {
++$frames_read;
$time += $frame_ref->{diff};
}
};
is($frames_read, 0, "exactly zero (well-formed) frames read");
like($@, qr/Unable to open 't\/missing\.ttyrec' for reading/, "\$@ contains the correct error");
# test negative time_threshold #################################################
$frames_read = 0;
eval {
my $t = Term::TtyRec::Plus->new(
infile => "t/simple.ttyrec",
time_threshold => -1,
);
my $time = 0;
while (my $frame_ref = $t->next_frame()) {
++$frames_read;
$time += $frame_ref->{diff};
}
};
is($frames_read, 0, "no frames read");
like($@, qr/Cannot have a negative time threshold/, "\$@ contains the correct error");
# test malformed ttyrec (header) ###############################################
$frames_read = 0;
eval {
my $t = Term::TtyRec::Plus->new(
infile => "t/malformed-header.ttyrec",
);
my $time = 0;
while (my $frame_ref = $t->next_frame()) {
++$frames_read;
$time += $frame_ref->{diff};
}
};
is($frames_read, 3, "exactly three (well-formed) frames read");
like($@, qr/Expected 12-byte header, got \d+ /, "\$@ contains the correct error");
# test malformed ttyrec (data) #################################################
$frames_read = 0;
eval {
my $t = Term::TtyRec::Plus->new(
infile => "t/malformed-data.ttyrec",
);
my $time = 0;
while (my $frame_ref = $t->next_frame()) {
++$frames_read;
$time += $frame_ref->{diff};
}
};
is($frames_read, 1, "exactly one (well-formed) frame read");
like($@, qr/Expected 19-byte frame, got \d+ /, "\$@ contains the correct error");
# test filtering timestamp to -1 ###############################################
$frames_read = 0;
eval {
sub bad_callback {
my ($data, $time, $prev) = @_;
$$time = -1;
}
my $t = Term::TtyRec::Plus->new(
infile => "t/simple.ttyrec",
frame_filter => \&bad_callback,
);
my $time = 0;
while (my $frame_ref = $t->next_frame()) {
++$frames_read;
$time += $frame_ref->{diff};
}
};
is($frames_read, 0, "no frames read");
like($@, qr/Unable to create a new header, \w+ portion of timestamp/, "\$@ contains the correct error");
# test bad grep() arg ##########################################################
$frames_read = 0;
eval {
my $t = Term::TtyRec::Plus->new(
infile => "t/simple.ttyrec",
);
my $time = 0;
while (my $frame_ref = $t->grep("I tell ya,", [qw/grep() was jsn's idea!!/])) {
++$frames_read;
$time += $frame_ref->{diff};
}
};
is($frames_read, 0, "no frames read");
like($@, qr/Each of grep\(\)'s arguments must be a subroutine, regular expression, or string;/, "\$@ contains the correct error");
|