]> git.sur5r.net Git - i3/i3/blob - testcases/t/201-config-parser.t
74ea95387df1ce170b16f2ade363d731ff9a1528
[i3/i3] / testcases / t / 201-config-parser.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 # Tests the standalone parser binary to see if it calls the right code when
18 # confronted with various commands, if it prints proper error messages for
19 # wrong commands and if it terminates in every case.
20 #
21 use i3test i3_autostart => 0;
22 use IPC::Run qw(run);
23
24 sub parser_calls {
25     my ($command) = @_;
26
27     my $stdout;
28     run [ '../test.config_parser', $command ],
29         '>&-',
30         '2>', \$stdout;
31     # TODO: use a timeout, so that we can error out if it doesn’t terminate
32
33     # Filter out all debugging output.
34     my @lines = split("\n", $stdout);
35     @lines = grep { not /^# / } @lines;
36
37     ## The criteria management calls are irrelevant and not what we want to test
38     ## in the first place.
39     #@lines = grep { !(/cmd_criteria_init()/ || /cmd_criteria_match_windows/) } @lines;
40     return join("\n", @lines) . "\n";
41 }
42
43 my $config = <<'EOT';
44 mode "meh" {
45     bindsym Mod1 + Shift +   x resize grow
46     bindcode Mod1+44 resize shrink
47 }
48 EOT
49
50 my $expected = <<'EOT';
51 cfg_enter_mode(meh)
52 cfg_mode_binding(bindsym, Mod1,Shift, x, resize grow)
53 cfg_mode_binding(bindcode, Mod1, 44, resize shrink)
54 EOT
55
56 is(parser_calls($config),
57    $expected,
58    'single number (move workspace 3) ok');
59
60 $config = <<'EOT';
61 exec geeqie
62 exec --no-startup-id /tmp/foo.sh
63 exec_always firefox
64 exec_always --no-startup-id /tmp/bar.sh
65 EOT
66
67 $expected = <<'EOT';
68 cfg_exec(exec, (null), geeqie)
69 cfg_exec(exec, --no-startup-id, /tmp/foo.sh)
70 cfg_exec(exec_always, (null), firefox)
71 cfg_exec(exec_always, --no-startup-id, /tmp/bar.sh)
72 EOT
73
74 is(parser_calls($config),
75    $expected,
76    'single number (move workspace 3) ok');
77
78
79 done_testing;