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