]> git.sur5r.net Git - i3/i3/blob - testcases/t/201-config-parser.t
Introduce --exclude-titlebar flag for mouse bindings. (#2703)
[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         '>/dev/null',
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 { !(/cfg_criteria_init/ || /cfg_criteria_pop_state/) } @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     bindsym --release Mod1+x exec foo
48     bindsym --whole-window button3 nop
49     bindsym --release --whole-window button3 nop
50     bindsym --border button3 nop
51     bindsym --release --border button3 nop
52     bindsym --exclude-titlebar button3 nop
53     bindsym --whole-window --border --exclude-titlebar button3 nop
54 }
55 EOT
56
57 my $expected = <<'EOT';
58 cfg_enter_mode((null), meh)
59 cfg_mode_binding(bindsym, Mod1,Shift, x, (null), (null), (null), (null), resize grow)
60 cfg_mode_binding(bindcode, Mod1, 44, (null), (null), (null), (null), resize shrink)
61 cfg_mode_binding(bindsym, Mod1, x, --release, (null), (null), (null), exec foo)
62 cfg_mode_binding(bindsym, (null), button3, (null), (null), --whole-window, (null), nop)
63 cfg_mode_binding(bindsym, (null), button3, --release, (null), --whole-window, (null), nop)
64 cfg_mode_binding(bindsym, (null), button3, (null), --border, (null), (null), nop)
65 cfg_mode_binding(bindsym, (null), button3, --release, --border, (null), (null), nop)
66 cfg_mode_binding(bindsym, (null), button3, (null), (null), (null), --exclude-titlebar, nop)
67 cfg_mode_binding(bindsym, (null), button3, (null), --border, --whole-window, --exclude-titlebar, nop)
68 EOT
69
70 is(parser_calls($config),
71    $expected,
72    'mode bindings ok');
73
74 ################################################################################
75 # exec and exec_always
76 ################################################################################
77
78 $config = <<'EOT';
79 exec geeqie
80 exec --no-startup-id /tmp/foo.sh
81 exec_always firefox
82 exec_always --no-startup-id /tmp/bar.sh
83 EOT
84
85 $expected = <<'EOT';
86 cfg_exec(exec, (null), geeqie)
87 cfg_exec(exec, --no-startup-id, /tmp/foo.sh)
88 cfg_exec(exec_always, (null), firefox)
89 cfg_exec(exec_always, --no-startup-id, /tmp/bar.sh)
90 EOT
91
92 is(parser_calls($config),
93    $expected,
94    'exec okay');
95
96 ################################################################################
97 # for_window
98 ################################################################################
99
100 $config = <<'EOT';
101 for_window [class="^Chrome"] floating enable
102 EOT
103
104 $expected = <<'EOT';
105 cfg_criteria_add(class, ^Chrome)
106 cfg_for_window(floating enable)
107 EOT
108
109 is(parser_calls($config),
110    $expected,
111    'for_window okay');
112
113 ################################################################################
114 # assign
115 ################################################################################
116
117 $config = <<'EOT';
118 assign [class="^Chrome"] 4
119 assign [class="^Chrome"] named workspace
120 assign [class="^Chrome"] "quoted named workspace"
121 assign [class="^Chrome"] → "quoted named workspace"
122 EOT
123
124 $expected = <<'EOT';
125 cfg_criteria_add(class, ^Chrome)
126 cfg_assign(4)
127 cfg_criteria_add(class, ^Chrome)
128 cfg_assign(named workspace)
129 cfg_criteria_add(class, ^Chrome)
130 cfg_assign(quoted named workspace)
131 cfg_criteria_add(class, ^Chrome)
132 cfg_assign(quoted named workspace)
133 EOT
134
135 is(parser_calls($config),
136    $expected,
137    'for_window okay');
138
139 ################################################################################
140 # floating_minimum_size / floating_maximum_size
141 ################################################################################
142
143 $config = <<'EOT';
144 floating_minimum_size 80x55
145 floating_minimum_size 80    x  55  
146 floating_maximum_size 73 x 10
147 EOT
148
149 $expected = <<'EOT';
150 cfg_floating_minimum_size(80, 55)
151 cfg_floating_minimum_size(80, 55)
152 cfg_floating_maximum_size(73, 10)
153 EOT
154
155 is(parser_calls($config),
156    $expected,
157    'floating_minimum_size ok');
158
159 ################################################################################
160 # popup_during_fullscreen
161 ################################################################################
162
163 $config = <<'EOT';
164 popup_during_fullscreen ignore
165 popup_during_fullscreen leave_fullscreen
166 popup_during_fullscreen SMArt
167 EOT
168
169 $expected = <<'EOT';
170 cfg_popup_during_fullscreen(ignore)
171 cfg_popup_during_fullscreen(leave_fullscreen)
172 cfg_popup_during_fullscreen(smart)
173 EOT
174
175 is(parser_calls($config),
176    $expected,
177    'popup_during_fullscreen ok');
178
179
180 ################################################################################
181 # floating_modifier
182 ################################################################################
183
184 $config = <<'EOT';
185 floating_modifier Mod1
186 floating_modifier mOd1
187 EOT
188
189 $expected = <<'EOT';
190 cfg_floating_modifier(Mod1)
191 cfg_floating_modifier(Mod1)
192 EOT
193
194 is(parser_calls($config),
195    $expected,
196    'floating_modifier ok');
197
198 ################################################################################
199 # default_orientation
200 ################################################################################
201
202 $config = <<'EOT';
203 default_orientation horizontal
204 default_orientation vertical
205 default_orientation auto
206 EOT
207
208 $expected = <<'EOT';
209 cfg_default_orientation(horizontal)
210 cfg_default_orientation(vertical)
211 cfg_default_orientation(auto)
212 EOT
213
214 is(parser_calls($config),
215    $expected,
216    'default_orientation ok');
217
218 ################################################################################
219 # workspace_layout
220 ################################################################################
221
222 $config = <<'EOT';
223 workspace_layout default
224 workspace_layout stacked
225 workspace_layout stacking
226 workspace_layout tabbed
227 EOT
228
229 $expected = <<'EOT';
230 cfg_workspace_layout(default)
231 cfg_workspace_layout(stacked)
232 cfg_workspace_layout(stacking)
233 cfg_workspace_layout(tabbed)
234 EOT
235
236 is(parser_calls($config),
237    $expected,
238    'workspace_layout ok');
239
240 ################################################################################
241 # workspace assignments, with trailing whitespace (ticket #921)
242 ################################################################################
243
244 $config = <<'EOT';
245 workspace "3" output DP-1 
246 workspace "3" output            VGA-1   
247 EOT
248
249 $expected = <<'EOT';
250 cfg_workspace(3, DP-1)
251 cfg_workspace(3, VGA-1)
252 EOT
253
254 is(parser_calls($config),
255    $expected,
256    'workspace assignment ok');
257
258 ################################################################################
259 # new_window
260 ################################################################################
261
262 $config = <<'EOT';
263 new_window 1pixel
264 new_window normal
265 new_window none
266 new_float 1pixel
267 new_float normal
268 new_float none
269 EOT
270
271 $expected = <<'EOT';
272 cfg_new_window(new_window, 1pixel, -1)
273 cfg_new_window(new_window, normal, 2)
274 cfg_new_window(new_window, none, -1)
275 cfg_new_window(new_float, 1pixel, -1)
276 cfg_new_window(new_float, normal, 2)
277 cfg_new_window(new_float, none, -1)
278 EOT
279
280 is(parser_calls($config),
281    $expected,
282    'new_window ok');
283
284 ################################################################################
285 # hide_edge_borders
286 ################################################################################
287
288 $config = <<'EOT';
289 hide_edge_borders none
290 hide_edge_borders vertical
291 hide_edge_borders horizontal
292 hide_edge_borders both
293 hide_edge_borders smart
294 EOT
295
296 $expected = <<'EOT';
297 cfg_hide_edge_borders(none)
298 cfg_hide_edge_borders(vertical)
299 cfg_hide_edge_borders(horizontal)
300 cfg_hide_edge_borders(both)
301 cfg_hide_edge_borders(smart)
302 EOT
303
304 is(parser_calls($config),
305    $expected,
306    'hide_edge_borders ok');
307
308 ################################################################################
309 # focus_follows_mouse
310 ################################################################################
311
312 $config = <<'EOT';
313 focus_follows_mouse yes
314 focus_follows_mouse no
315 EOT
316
317 $expected = <<'EOT';
318 cfg_focus_follows_mouse(yes)
319 cfg_focus_follows_mouse(no)
320 EOT
321
322 is(parser_calls($config),
323    $expected,
324    'focus_follows_mouse ok');
325
326 ################################################################################
327 # mouse_warping
328 ################################################################################
329
330 $config = <<'EOT';
331 mouse_warping output
332 mouse_warping none
333 EOT
334
335 $expected = <<'EOT';
336 cfg_mouse_warping(output)
337 cfg_mouse_warping(none)
338 EOT
339
340 is(parser_calls($config),
341    $expected,
342    'mouse_warping ok');
343
344 ################################################################################
345 # force_display_urgency_hint
346 ################################################################################
347
348 is(parser_calls('force_display_urgency_hint 300'),
349    "cfg_force_display_urgency_hint(300)\n",
350    'force_display_urgency_hint ok');
351
352 is(parser_calls('force_display_urgency_hint 500 ms'),
353    "cfg_force_display_urgency_hint(500)\n",
354    'force_display_urgency_hint ok');
355
356 is(parser_calls('force_display_urgency_hint 700ms'),
357    "cfg_force_display_urgency_hint(700)\n",
358    'force_display_urgency_hint ok');
359
360 $config = <<'EOT';
361 force_display_urgency_hint 300
362 force_display_urgency_hint 500 ms
363 force_display_urgency_hint 700ms
364 force_display_urgency_hint 700
365 EOT
366
367 $expected = <<'EOT';
368 cfg_force_display_urgency_hint(300)
369 cfg_force_display_urgency_hint(500)
370 cfg_force_display_urgency_hint(700)
371 cfg_force_display_urgency_hint(700)
372 EOT
373
374 is(parser_calls($config),
375    $expected,
376    'force_display_urgency_hint ok');
377
378 ################################################################################
379 # workspace
380 ################################################################################
381
382 $config = <<'EOT';
383 workspace 3 output VGA-1
384 workspace "4: output" output VGA-2
385 workspace bleh output LVDS1/I_1
386 EOT
387
388 $expected = <<'EOT';
389 cfg_workspace(3, VGA-1)
390 cfg_workspace(4: output, VGA-2)
391 cfg_workspace(bleh, LVDS1/I_1)
392 EOT
393
394 is(parser_calls($config),
395    $expected,
396    'workspace ok');
397
398 ################################################################################
399 # ipc-socket
400 ################################################################################
401
402 $config = <<'EOT';
403 ipc-socket /tmp/i3.sock
404 ipc_socket ~/.i3/i3.sock
405 EOT
406
407 $expected = <<'EOT';
408 cfg_ipc_socket(/tmp/i3.sock)
409 cfg_ipc_socket(~/.i3/i3.sock)
410 EOT
411
412 is(parser_calls($config),
413    $expected,
414    'ipc-socket ok');
415
416 ################################################################################
417 # colors
418 ################################################################################
419
420 $config = <<'EOT';
421 client.focused          #4c7899 #285577 #ffffff #2e9ef4 #b34d4c
422 client.focused_inactive #333333 #5f676a #ffffff #484e50
423 client.unfocused        #333333 #222222 #888888 #292d2e
424 client.urgent           #2f343a #900000 #ffffff #900000 #c00000
425 client.placeholder      #000000 #0c0c0c #ffffff #000000
426 EOT
427
428 $expected = <<'EOT';
429 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4, #b34d4c)
430 cfg_color(client.focused_inactive, #333333, #5f676a, #ffffff, #484e50, NULL)
431 cfg_color(client.unfocused, #333333, #222222, #888888, #292d2e, NULL)
432 cfg_color(client.urgent, #2f343a, #900000, #ffffff, #900000, #c00000)
433 cfg_color(client.placeholder, #000000, #0c0c0c, #ffffff, #000000, NULL)
434 EOT
435
436 is(parser_calls($config),
437    $expected,
438    'colors ok');
439
440 ################################################################################
441 # Verify that errors don’t harm subsequent valid statements
442 ################################################################################
443
444 $config = <<'EOT';
445 hide_edge_border both
446 client.focused          #4c7899 #285577 #ffffff #2e9ef4
447 EOT
448
449 my $expected_all_tokens = "ERROR: CONFIG: Expected one of these tokens: <end>, '#', '" . join("', '", qw(
450         set
451         set_from_resource
452         bindsym
453         bindcode
454         bind
455         bar
456         font
457         mode
458         floating_minimum_size
459         floating_maximum_size
460         floating_modifier
461         default_orientation
462         workspace_layout
463         new_window
464         new_float
465         hide_edge_borders
466         for_window
467         assign
468         no_focus
469         focus_follows_mouse
470         mouse_warping
471         force_focus_wrapping
472         force_xinerama
473         force-xinerama
474         disable_randr15
475         disable-randr15
476         workspace_auto_back_and_forth
477         fake_outputs
478         fake-outputs
479         force_display_urgency_hint
480         focus_on_window_activation
481         show_marks
482         workspace
483         ipc_socket
484         ipc-socket
485         restart_state
486         popup_during_fullscreen
487         exec_always
488         exec
489         client.background
490         client.focused_inactive
491         client.focused
492         client.unfocused
493         client.urgent
494         client.placeholder
495     )) . "'\n";
496
497 my $expected_end = <<'EOT';
498 ERROR: CONFIG: (in file <stdin>)
499 ERROR: CONFIG: Line   1: hide_edge_border both
500 ERROR: CONFIG:           ^^^^^^^^^^^^^^^^^^^^^
501 ERROR: CONFIG: Line   2: client.focused          #4c7899 #285577 #ffffff #2e9ef4
502 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4, NULL)
503 EOT
504
505 $expected = $expected_all_tokens . $expected_end;
506
507 is(parser_calls($config),
508    $expected,
509    'errors dont harm subsequent statements');
510
511 $config = <<'EOT';
512 hide_edge_borders FOOBAR
513 client.focused          #4c7899 #285577 #ffffff #2e9ef4
514 EOT
515
516 $expected = <<'EOT';
517 ERROR: CONFIG: Expected one of these tokens: 'none', 'vertical', 'horizontal', 'both', 'smart', '1', 'yes', 'true', 'on', 'enable', 'active'
518 ERROR: CONFIG: (in file <stdin>)
519 ERROR: CONFIG: Line   1: hide_edge_borders FOOBAR
520 ERROR: CONFIG:                             ^^^^^^
521 ERROR: CONFIG: Line   2: client.focused          #4c7899 #285577 #ffffff #2e9ef4
522 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4, NULL)
523 EOT
524
525 is(parser_calls($config),
526    $expected,
527    'errors dont harm subsequent statements');
528
529 ################################################################################
530 # Regression: semicolons end comments, but shouldn’t
531 ################################################################################
532
533 $config = <<'EOT';
534 # "foo" client.focused          #4c7899 #285577 #ffffff #2e9ef4
535 EOT
536
537 $expected = <<'EOT';
538
539 EOT
540
541 is(parser_calls($config),
542    $expected,
543    'semicolon does not end a comment line');
544
545 ################################################################################
546 # Error message with 2+2 lines of context
547 ################################################################################
548
549 $config = <<'EOT';
550 # i3 config file (v4)
551
552 font foobar
553
554 unknown qux
555
556 # yay
557 # this should not show up
558 EOT
559
560 my $expected_head = <<'EOT';
561 cfg_font(foobar)
562 EOT
563
564 my $expected_tail = <<'EOT';
565 ERROR: CONFIG: (in file <stdin>)
566 ERROR: CONFIG: Line   3: font foobar
567 ERROR: CONFIG: Line   4: 
568 ERROR: CONFIG: Line   5: unknown qux
569 ERROR: CONFIG:           ^^^^^^^^^^^
570 ERROR: CONFIG: Line   6: 
571 ERROR: CONFIG: Line   7: # yay
572 EOT
573
574 $expected = $expected_head . $expected_all_tokens . $expected_tail;
575
576 is(parser_calls($config),
577    $expected,
578    'error message (2+2 context) ok');
579
580 ################################################################################
581 # Error message with 0+0 lines of context
582 ################################################################################
583
584 $config = <<'EOT';
585 unknown qux
586 EOT
587
588 $expected_tail = <<'EOT';
589 ERROR: CONFIG: (in file <stdin>)
590 ERROR: CONFIG: Line   1: unknown qux
591 ERROR: CONFIG:           ^^^^^^^^^^^
592 EOT
593
594 $expected = $expected_all_tokens . $expected_tail;
595
596 is(parser_calls($config),
597    $expected,
598    'error message (0+0 context) ok');
599
600 ################################################################################
601 # Error message with 1+0 lines of context
602 ################################################################################
603
604 $config = <<'EOT';
605 # context before
606 unknown qux
607 EOT
608
609 $expected_tail = <<'EOT';
610 ERROR: CONFIG: (in file <stdin>)
611 ERROR: CONFIG: Line   1: # context before
612 ERROR: CONFIG: Line   2: unknown qux
613 ERROR: CONFIG:           ^^^^^^^^^^^
614 EOT
615
616 $expected = $expected_all_tokens . $expected_tail;
617
618 is(parser_calls($config),
619    $expected,
620    'error message (1+0 context) ok');
621
622 ################################################################################
623 # Error message with 0+1 lines of context
624 ################################################################################
625
626 $config = <<'EOT';
627 unknown qux
628 # context after
629 EOT
630
631 $expected_tail = <<'EOT';
632 ERROR: CONFIG: (in file <stdin>)
633 ERROR: CONFIG: Line   1: unknown qux
634 ERROR: CONFIG:           ^^^^^^^^^^^
635 ERROR: CONFIG: Line   2: # context after
636 EOT
637
638 $expected = $expected_all_tokens . $expected_tail;
639
640 is(parser_calls($config),
641    $expected,
642    'error message (0+1 context) ok');
643
644 ################################################################################
645 # Error message with 0+2 lines of context
646 ################################################################################
647
648 $config = <<'EOT';
649 unknown qux
650 # context after
651 # context 2 after
652 EOT
653
654 $expected_tail = <<'EOT';
655 ERROR: CONFIG: (in file <stdin>)
656 ERROR: CONFIG: Line   1: unknown qux
657 ERROR: CONFIG:           ^^^^^^^^^^^
658 ERROR: CONFIG: Line   2: # context after
659 ERROR: CONFIG: Line   3: # context 2 after
660 EOT
661
662 $expected = $expected_all_tokens . $expected_tail;
663
664 is(parser_calls($config),
665    $expected,
666    'error message (0+2 context) ok');
667
668 ################################################################################
669 # Error message within mode blocks
670 ################################################################################
671
672 $config = <<'EOT';
673 mode "yo" {
674     bindsym x resize shrink left
675     unknown qux
676 }
677 EOT
678
679 $expected = <<'EOT';
680 cfg_enter_mode((null), yo)
681 cfg_mode_binding(bindsym, (null), x, (null), (null), (null), (null), resize shrink left)
682 ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', '}'
683 ERROR: CONFIG: (in file <stdin>)
684 ERROR: CONFIG: Line   1: mode "yo" {
685 ERROR: CONFIG: Line   2:     bindsym x resize shrink left
686 ERROR: CONFIG: Line   3:     unknown qux
687 ERROR: CONFIG:               ^^^^^^^^^^^
688 ERROR: CONFIG: Line   4: }
689 EOT
690
691 is(parser_calls($config),
692    $expected,
693    'error message (mode block) ok');
694
695 ################################################################################
696 # Error message within bar blocks
697 ################################################################################
698
699 $config = <<'EOT';
700 bar {
701     output LVDS-1
702     unknown qux
703 }
704 EOT
705
706 $expected = <<'EOT';
707 cfg_bar_start()
708 cfg_bar_output(LVDS-1)
709 ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'i3bar_command', 'status_command', 'socket_path', 'mode', 'hidden_state', 'id', 'modifier', 'wheel_up_cmd', 'wheel_down_cmd', 'bindsym', 'position', 'output', 'tray_output', 'tray_padding', 'font', 'separator_symbol', 'binding_mode_indicator', 'workspace_buttons', 'strip_workspace_numbers', 'verbose', 'colors', '}'
710 ERROR: CONFIG: (in file <stdin>)
711 ERROR: CONFIG: Line   1: bar {
712 ERROR: CONFIG: Line   2:     output LVDS-1
713 ERROR: CONFIG: Line   3:     unknown qux
714 ERROR: CONFIG:               ^^^^^^^^^^^
715 ERROR: CONFIG: Line   4: }
716 cfg_bar_finish()
717 EOT
718
719 is(parser_calls($config),
720    $expected,
721    'error message (bar block) ok');
722
723 done_testing;