]> git.sur5r.net Git - i3/i3/blob - testcases/t/201-config-parser.t
Allow assign to workspace by number
[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"] 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 new_float 1pixel
270 new_float normal
271 new_float none
272 EOT
273
274 $expected = <<'EOT';
275 cfg_new_window(new_window, 1pixel, -1)
276 cfg_new_window(new_window, normal, 2)
277 cfg_new_window(new_window, none, -1)
278 cfg_new_window(new_float, 1pixel, -1)
279 cfg_new_window(new_float, normal, 2)
280 cfg_new_window(new_float, none, -1)
281 EOT
282
283 is(parser_calls($config),
284    $expected,
285    'new_window ok');
286
287 ################################################################################
288 # hide_edge_borders
289 ################################################################################
290
291 $config = <<'EOT';
292 hide_edge_borders none
293 hide_edge_borders vertical
294 hide_edge_borders horizontal
295 hide_edge_borders both
296 hide_edge_borders smart
297 EOT
298
299 $expected = <<'EOT';
300 cfg_hide_edge_borders(none)
301 cfg_hide_edge_borders(vertical)
302 cfg_hide_edge_borders(horizontal)
303 cfg_hide_edge_borders(both)
304 cfg_hide_edge_borders(smart)
305 EOT
306
307 is(parser_calls($config),
308    $expected,
309    'hide_edge_borders ok');
310
311 ################################################################################
312 # focus_follows_mouse
313 ################################################################################
314
315 $config = <<'EOT';
316 focus_follows_mouse yes
317 focus_follows_mouse no
318 EOT
319
320 $expected = <<'EOT';
321 cfg_focus_follows_mouse(yes)
322 cfg_focus_follows_mouse(no)
323 EOT
324
325 is(parser_calls($config),
326    $expected,
327    'focus_follows_mouse ok');
328
329 ################################################################################
330 # mouse_warping
331 ################################################################################
332
333 $config = <<'EOT';
334 mouse_warping output
335 mouse_warping none
336 EOT
337
338 $expected = <<'EOT';
339 cfg_mouse_warping(output)
340 cfg_mouse_warping(none)
341 EOT
342
343 is(parser_calls($config),
344    $expected,
345    'mouse_warping ok');
346
347 ################################################################################
348 # force_display_urgency_hint
349 ################################################################################
350
351 is(parser_calls('force_display_urgency_hint 300'),
352    "cfg_force_display_urgency_hint(300)\n",
353    'force_display_urgency_hint ok');
354
355 is(parser_calls('force_display_urgency_hint 500 ms'),
356    "cfg_force_display_urgency_hint(500)\n",
357    'force_display_urgency_hint ok');
358
359 is(parser_calls('force_display_urgency_hint 700ms'),
360    "cfg_force_display_urgency_hint(700)\n",
361    'force_display_urgency_hint ok');
362
363 $config = <<'EOT';
364 force_display_urgency_hint 300
365 force_display_urgency_hint 500 ms
366 force_display_urgency_hint 700ms
367 force_display_urgency_hint 700
368 EOT
369
370 $expected = <<'EOT';
371 cfg_force_display_urgency_hint(300)
372 cfg_force_display_urgency_hint(500)
373 cfg_force_display_urgency_hint(700)
374 cfg_force_display_urgency_hint(700)
375 EOT
376
377 is(parser_calls($config),
378    $expected,
379    'force_display_urgency_hint ok');
380
381 ################################################################################
382 # workspace
383 ################################################################################
384
385 $config = <<'EOT';
386 workspace 3 output VGA-1
387 workspace "4: output" output VGA-2
388 workspace bleh output LVDS1/I_1
389 EOT
390
391 $expected = <<'EOT';
392 cfg_workspace(3, VGA-1)
393 cfg_workspace(4: output, VGA-2)
394 cfg_workspace(bleh, LVDS1/I_1)
395 EOT
396
397 is(parser_calls($config),
398    $expected,
399    'workspace ok');
400
401 ################################################################################
402 # ipc-socket
403 ################################################################################
404
405 $config = <<'EOT';
406 ipc-socket /tmp/i3.sock
407 ipc_socket ~/.i3/i3.sock
408 EOT
409
410 $expected = <<'EOT';
411 cfg_ipc_socket(/tmp/i3.sock)
412 cfg_ipc_socket(~/.i3/i3.sock)
413 EOT
414
415 is(parser_calls($config),
416    $expected,
417    'ipc-socket ok');
418
419 ################################################################################
420 # colors
421 ################################################################################
422
423 $config = <<'EOT';
424 client.focused          #4c7899 #285577 #ffffff #2e9ef4 #b34d4c
425 client.focused_inactive #333333 #5f676a #ffffff #484e50
426 client.unfocused        #333333 #222222 #888888 #292d2e
427 client.urgent           #2f343a #900000 #ffffff #900000 #c00000
428 client.placeholder      #000000 #0c0c0c #ffffff #000000
429 EOT
430
431 $expected = <<'EOT';
432 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4, #b34d4c)
433 cfg_color(client.focused_inactive, #333333, #5f676a, #ffffff, #484e50, NULL)
434 cfg_color(client.unfocused, #333333, #222222, #888888, #292d2e, NULL)
435 cfg_color(client.urgent, #2f343a, #900000, #ffffff, #900000, #c00000)
436 cfg_color(client.placeholder, #000000, #0c0c0c, #ffffff, #000000, NULL)
437 EOT
438
439 is(parser_calls($config),
440    $expected,
441    'colors ok');
442
443 ################################################################################
444 # Verify that errors don’t harm subsequent valid statements
445 ################################################################################
446
447 $config = <<'EOT';
448 hide_edge_border both
449 client.focused          #4c7899 #285577 #ffffff #2e9ef4
450 EOT
451
452 my $expected_all_tokens = "ERROR: CONFIG: Expected one of these tokens: <end>, '#', '" . join("', '", 'set ', 'set      ', qw(
453         set_from_resource
454         bindsym
455         bindcode
456         bind
457         bar
458         font
459         mode
460         floating_minimum_size
461         floating_maximum_size
462         floating_modifier
463         default_orientation
464         workspace_layout
465         new_window
466         new_float
467         hide_edge_borders
468         for_window
469         assign
470         no_focus
471         focus_follows_mouse
472         mouse_warping
473         force_focus_wrapping
474         force_xinerama
475         force-xinerama
476         disable_randr15
477         disable-randr15
478         workspace_auto_back_and_forth
479         fake_outputs
480         fake-outputs
481         force_display_urgency_hint
482         focus_on_window_activation
483         show_marks
484         workspace
485         ipc_socket
486         ipc-socket
487         restart_state
488         popup_during_fullscreen
489         exec_always
490         exec
491         client.background
492         client.focused_inactive
493         client.focused
494         client.unfocused
495         client.urgent
496         client.placeholder
497     )) . "'\n";
498
499 my $expected_end = <<'EOT';
500 ERROR: CONFIG: (in file <stdin>)
501 ERROR: CONFIG: Line   1: hide_edge_border both
502 ERROR: CONFIG:           ^^^^^^^^^^^^^^^^^^^^^
503 ERROR: CONFIG: Line   2: client.focused          #4c7899 #285577 #ffffff #2e9ef4
504 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4, NULL)
505 EOT
506
507 $expected = $expected_all_tokens . $expected_end;
508
509 is(parser_calls($config),
510    $expected,
511    'errors dont harm subsequent statements');
512
513 $config = <<'EOT';
514 hide_edge_borders FOOBAR
515 client.focused          #4c7899 #285577 #ffffff #2e9ef4
516 EOT
517
518 $expected = <<'EOT';
519 ERROR: CONFIG: Expected one of these tokens: 'none', 'vertical', 'horizontal', 'both', 'smart', '1', 'yes', 'true', 'on', 'enable', 'active'
520 ERROR: CONFIG: (in file <stdin>)
521 ERROR: CONFIG: Line   1: hide_edge_borders FOOBAR
522 ERROR: CONFIG:                             ^^^^^^
523 ERROR: CONFIG: Line   2: client.focused          #4c7899 #285577 #ffffff #2e9ef4
524 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4, NULL)
525 EOT
526
527 is(parser_calls($config),
528    $expected,
529    'errors dont harm subsequent statements');
530
531 ################################################################################
532 # Regression: semicolons end comments, but shouldn’t
533 ################################################################################
534
535 $config = <<'EOT';
536 # "foo" client.focused          #4c7899 #285577 #ffffff #2e9ef4
537 EOT
538
539 $expected = <<'EOT';
540
541 EOT
542
543 is(parser_calls($config),
544    $expected,
545    'semicolon does not end a comment line');
546
547 ################################################################################
548 # Error message with 2+2 lines of context
549 ################################################################################
550
551 $config = <<'EOT';
552 # i3 config file (v4)
553
554 font foobar
555
556 unknown qux
557
558 # yay
559 # this should not show up
560 EOT
561
562 my $expected_head = <<'EOT';
563 cfg_font(foobar)
564 EOT
565
566 my $expected_tail = <<'EOT';
567 ERROR: CONFIG: (in file <stdin>)
568 ERROR: CONFIG: Line   3: font foobar
569 ERROR: CONFIG: Line   4: 
570 ERROR: CONFIG: Line   5: unknown qux
571 ERROR: CONFIG:           ^^^^^^^^^^^
572 ERROR: CONFIG: Line   6: 
573 ERROR: CONFIG: Line   7: # yay
574 EOT
575
576 $expected = $expected_head . $expected_all_tokens . $expected_tail;
577
578 is(parser_calls($config),
579    $expected,
580    'error message (2+2 context) ok');
581
582 ################################################################################
583 # Error message with 0+0 lines of context
584 ################################################################################
585
586 $config = <<'EOT';
587 unknown qux
588 EOT
589
590 $expected_tail = <<'EOT';
591 ERROR: CONFIG: (in file <stdin>)
592 ERROR: CONFIG: Line   1: unknown qux
593 ERROR: CONFIG:           ^^^^^^^^^^^
594 EOT
595
596 $expected = $expected_all_tokens . $expected_tail;
597
598 is(parser_calls($config),
599    $expected,
600    'error message (0+0 context) ok');
601
602 ################################################################################
603 # Error message with 1+0 lines of context
604 ################################################################################
605
606 $config = <<'EOT';
607 # context before
608 unknown qux
609 EOT
610
611 $expected_tail = <<'EOT';
612 ERROR: CONFIG: (in file <stdin>)
613 ERROR: CONFIG: Line   1: # context before
614 ERROR: CONFIG: Line   2: unknown qux
615 ERROR: CONFIG:           ^^^^^^^^^^^
616 EOT
617
618 $expected = $expected_all_tokens . $expected_tail;
619
620 is(parser_calls($config),
621    $expected,
622    'error message (1+0 context) ok');
623
624 ################################################################################
625 # Error message with 0+1 lines of context
626 ################################################################################
627
628 $config = <<'EOT';
629 unknown qux
630 # context after
631 EOT
632
633 $expected_tail = <<'EOT';
634 ERROR: CONFIG: (in file <stdin>)
635 ERROR: CONFIG: Line   1: unknown qux
636 ERROR: CONFIG:           ^^^^^^^^^^^
637 ERROR: CONFIG: Line   2: # context after
638 EOT
639
640 $expected = $expected_all_tokens . $expected_tail;
641
642 is(parser_calls($config),
643    $expected,
644    'error message (0+1 context) ok');
645
646 ################################################################################
647 # Error message with 0+2 lines of context
648 ################################################################################
649
650 $config = <<'EOT';
651 unknown qux
652 # context after
653 # context 2 after
654 EOT
655
656 $expected_tail = <<'EOT';
657 ERROR: CONFIG: (in file <stdin>)
658 ERROR: CONFIG: Line   1: unknown qux
659 ERROR: CONFIG:           ^^^^^^^^^^^
660 ERROR: CONFIG: Line   2: # context after
661 ERROR: CONFIG: Line   3: # context 2 after
662 EOT
663
664 $expected = $expected_all_tokens . $expected_tail;
665
666 is(parser_calls($config),
667    $expected,
668    'error message (0+2 context) ok');
669
670 ################################################################################
671 # Error message within mode blocks
672 ################################################################################
673
674 $config = <<'EOT';
675 mode "yo" {
676     bindsym x resize shrink left
677     unknown qux
678 }
679 EOT
680
681 $expected = <<'EOT';
682 cfg_enter_mode((null), yo)
683 cfg_mode_binding(bindsym, (null), x, (null), (null), (null), (null), resize shrink left)
684 ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', '}'
685 ERROR: CONFIG: (in file <stdin>)
686 ERROR: CONFIG: Line   1: mode "yo" {
687 ERROR: CONFIG: Line   2:     bindsym x resize shrink left
688 ERROR: CONFIG: Line   3:     unknown qux
689 ERROR: CONFIG:               ^^^^^^^^^^^
690 ERROR: CONFIG: Line   4: }
691 EOT
692
693 is(parser_calls($config),
694    $expected,
695    'error message (mode block) ok');
696
697 ################################################################################
698 # Error message within bar blocks
699 ################################################################################
700
701 $config = <<'EOT';
702 bar {
703     output LVDS-1
704     unknown qux
705 }
706 EOT
707
708 $expected = <<'EOT';
709 cfg_bar_start()
710 cfg_bar_output(LVDS-1)
711 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', '}'
712 ERROR: CONFIG: (in file <stdin>)
713 ERROR: CONFIG: Line   1: bar {
714 ERROR: CONFIG: Line   2:     output LVDS-1
715 ERROR: CONFIG: Line   3:     unknown qux
716 ERROR: CONFIG:               ^^^^^^^^^^^
717 ERROR: CONFIG: Line   4: }
718 cfg_bar_finish()
719 EOT
720
721 is(parser_calls($config),
722    $expected,
723    'error message (bar block) ok');
724
725 done_testing;