Improve tests
[app-lastmsg.git] / t / App-Lastmsg.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use Test::More tests => 3;
6 BEGIN { use_ok('App::Lastmsg') };
7
8 {
9 no warnings 'redefine';
10 *App::Lastmsg::format_time = sub { shift };
11 }
12
13 chdir 't';
14 my $out = '';
15 open my $fh, '>', \$out or die "$!";
16 $App::Lastmsg::OUTPUT_FILEHANDLE = $fh;
17 $0 = 'lastmsg';
18 App::Lastmsg::run;
19
20 is $out, <<'EOF', 'output is correct';
21 user2 user2@example.org 1483182600
22 user1 user1@example.com 1483105440
23 user3 NOT FOUND
24 EOF
25
26 $ENV{LASTMSG_DEBUG} = 1;
27 my $err = '';
28 close STDERR;
29 open STDERR, '>', \$err or die "$!";
30 App::Lastmsg::run;
31
32 is $err, <<'EOF', 'debug output is correct';
33 Scanning inbox (inbox)
34 Processing <mail1@example.com> from User 1 <user1@example.com> (Comment)
35 Processing <mail2@example.com> from user1@example.com
36 Processing <mail3@example.com> from user2@example.com
37 Scanning sent (sent)
38 Processing <33r32r32igf432g@localhost.localdomain> sent to Random User <rando@example.com> (Very random), User 2 <user2@example.org>
39 EOF
This page took 0.022616 seconds and 4 git commands to generate.