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