]> git.sur5r.net Git - i3/i3/blob - testcases/t/235-check-config-no-x.t
Allow checking for duplicate bindings with -C
[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 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://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 my ($cfg, $ret, $out);
24
25 sub check_config {
26     my ($config) = @_;
27     my ($fh, $tmpfile) = tempfile(UNLINK => 1);
28     print $fh $config;
29     my $output = qx(DISPLAY= i3 -C -c $tmpfile 2>&1);
30     my $retval = $?;
31     $fh->flush;
32     close($fh);
33     return ($retval >> 8, $output);
34 }
35
36 ################################################################################
37 # 1: test with a bogus configuration file
38 ################################################################################
39
40 $cfg = <<EOT;
41 # i3 config file (v4)
42 i_am_an_unknown_config option
43 EOT
44
45 ($ret, $out) = check_config($cfg);
46 is($ret, 1, "exit code == 1");
47 like($out, qr/ERROR: *CONFIG: *[Ee]xpected.*tokens/, 'bogus config file');
48
49 ################################################################################
50 # 2: test with a valid configuration file
51 ################################################################################
52
53 $cfg = <<EOT;
54 # i3 config file (v4)
55 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
56 EOT
57
58 ($ret, $out) = check_config($cfg);
59 is($ret, 0, "exit code == 0");
60 is($out, "", 'valid config file');
61
62 ################################################################################
63 # 3: test duplicate keybindings
64 ################################################################################
65
66 $cfg = <<EOT;
67 # i3 config file (v4)
68 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
69 bindsym Shift+a nop 1
70 bindsym Shift+a nop 2
71 EOT
72
73 ($ret, $out) = check_config($cfg);
74 is($ret, 1, "exit code == 1");
75 like($out, qr/ERROR: *Duplicate keybinding in config file/, 'duplicate keybindings');
76
77 ################################################################################
78 # 4: test no duplicate keybindings
79 ################################################################################
80
81 $cfg = <<EOT;
82 # i3 config file (v4)
83 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
84 bindsym Shift+a nop 1
85 EOT
86
87 ($ret, $out) = check_config($cfg);
88 is($ret, 0, "exit code == 0");
89 is($out, "", 'valid config file');
90
91 done_testing;