]> git.sur5r.net Git - i3/i3/blob - testcases/t/235-check-config-no-x.t
Merge branch 'release-4.10.3'
[i3/i3] / testcases / t / 235-check-config-no-x.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Check whether the -C option works without a display and doesn't
18 # accidentally start the nagbar.
19 #
20 use i3test i3_autostart => 0;
21 use File::Temp qw(tempfile);
22
23 sub check_config {
24     my ($config) = @_;
25     my ($fh, $tmpfile) = tempfile(UNLINK => 1);
26     print $fh $config;
27     my $output = qx(DISPLAY= ../i3 -C -c $tmpfile 2>&1);
28     my $retval = $?;
29     $fh->flush;
30     close($fh);
31     return ($retval >> 8, $output);
32 }
33
34 ################################################################################
35 # 1: test with a bogus configuration file
36 ################################################################################
37
38 my $cfg = <<EOT;
39 # i3 config file (v4)
40 i_am_an_unknown_config option
41 EOT
42
43 my ($ret, $out) = check_config($cfg);
44 is($ret, 1, "exit code == 1");
45 like($out, qr/ERROR: *CONFIG: *[Ee]xpected.*tokens/, 'bogus config file');
46
47 ################################################################################
48 # 2: test with a valid configuration file
49 ################################################################################
50
51 my $cfg = <<EOT;
52 # i3 config file (v4)
53 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
54 EOT
55
56 my ($ret, $out) = check_config($cfg);
57 is($ret, 0, "exit code == 0");
58 is($out, "", 'valid config file');
59
60 done_testing;