summaryrefslogtreecommitdiff
path: root/test/feh.t
blob: 5713de424713f16acf772323b111e955b8cb9165 (plain)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use Test::Command tests => 60;

$ENV{HOME} = 'test';

my $feh = "src/feh";
my $images = 'test/ok/gif test/ok/jpg test/ok/png test/ok/pnm '
           . 'test/fail/gif test/fail/jpg test/fail/png test/fail/pnm';

my ($feh_name, $feh_version) = @ENV{'PACKAGE', 'VERSION'};

# These tests are meant to run non-interactively and without X.
# make sure they are capable of doing so.
delete $ENV{'DISPLAY'};

my $err_no_env = <<'EOF';

Unable to determine feh PACKAGE or VERSION.
This is most likely because you ran 'prove test' or 'perl test/feh.t'.
Sinc this test uses make variables and is therefore designed to be run from
the Makefile only, use 'make test' instead.

If you absolutely need to run it the other way, use
    PACKAGE=feh VERSION=1.5 ${your_command}
(with the appropiate values, of course).

EOF

if (length($feh_name) == 0 or length($feh_version) == 0) {
	die($err_no_env);
}

my $re_warning =
	qr{${feh_name} WARNING: test/fail/... \- No Imlib2 loader for that file format\n};
my $re_loadable = qr{test/ok/...};
my $re_unloadable = qr{test/fail/...};
my $re_list_action = qr{test/ok/... 16x16 \(${feh_name}\)};

my $cmd = Test::Command->new(cmd => "$feh --version");

$cmd->exit_is_num(0);
$cmd->stdout_is_eq("${feh_name} version ${feh_version}\n"
                 . "Compile-time switches: curl xinerama \n");
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(cmd => "$feh --loadable $images");

$cmd->exit_is_num(0);
$cmd->stdout_like($re_loadable);
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(
	cmd => "$feh --loadable --action 'echo touch %f' $images"
);

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/nx_action/loadable_action');
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(
	cmd => "$feh --loadable --action ';echo touch %f' $images"
);

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/nx_action/loadable_naction');
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(
	cmd => "$feh --unloadable --action 'echo rm %f' $images"
);

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/nx_action/unloadable_action');
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(
	cmd => "$feh --unloadable --action ';echo rm %f' $images"
);

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/nx_action/unloadable_naction');
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(cmd => "$feh --unloadable $images");

$cmd->exit_is_num(0);
$cmd->stdout_like($re_unloadable);
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(cmd => "$feh --list $images");

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/list/default');
$cmd->stderr_like($re_warning);

for my $sort (qw/name filename width height pixels size format/) {
	$cmd = Test::Command->new(cmd => "$feh --list $images --sort $sort");

	$cmd->exit_is_num(0);
	$cmd->stdout_is_file("test/list/$sort");
	$cmd->stderr_like($re_warning);
}

$cmd = Test::Command->new(cmd => "$feh --list $images --sort format --reverse");

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/list/format_reverse');
$cmd->stderr_like($re_warning);

$cmd = Test::Command->new(
	cmd => "$feh --list --recursive --sort filename test/ok"
);

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/list/filename_recursive');
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(cmd => "$feh --customlist '%f; %h; %l; %m; %n; %p; "
                               . "%s; %t; %u; %w' $images");

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/list/custom');
$cmd->stderr_like($re_warning);

$cmd = Test::Command->new(cmd => "$feh --list --quiet $images");
$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/list/default');
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(cmd =>
	"$feh --quiet --list --action 'echo \"%f %wx%h (%P)\" >&2' $images");

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/list/default');
$cmd->stderr_like($re_list_action);