2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
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.
21 use i3test i3_autostart => 0;
28 run [ '../test.config_parser', $command ],
31 # TODO: use a timeout, so that we can error out if it doesn’t terminate
33 # Filter out all debugging output.
34 my @lines = split("\n", $stdout);
35 @lines = grep { not /^# / } @lines;
37 # The criteria management calls are irrelevant and not what we want to test
39 @lines = grep { !(/cfg_criteria_init/ || /cfg_criteria_pop_state/) } @lines;
40 return join("\n", @lines) . "\n";
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
55 my $expected = <<'EOT';
56 cfg_enter_mode((null), meh)
57 cfg_mode_binding(bindsym, Mod1,Shift, x, (null), (null), (null), resize grow)
58 cfg_mode_binding(bindcode, Mod1, 44, (null), (null), (null), resize shrink)
59 cfg_mode_binding(bindsym, Mod1, x, --release, (null), (null), exec foo)
60 cfg_mode_binding(bindsym, (null), button3, (null), (null), --whole-window, nop)
61 cfg_mode_binding(bindsym, (null), button3, --release, (null), --whole-window, nop)
62 cfg_mode_binding(bindsym, (null), button3, (null), --border, (null), nop)
63 cfg_mode_binding(bindsym, (null), button3, --release, --border, (null), nop)
66 is(parser_calls($config),
70 ################################################################################
71 # exec and exec_always
72 ################################################################################
76 exec --no-startup-id /tmp/foo.sh
78 exec_always --no-startup-id /tmp/bar.sh
82 cfg_exec(exec, (null), geeqie)
83 cfg_exec(exec, --no-startup-id, /tmp/foo.sh)
84 cfg_exec(exec_always, (null), firefox)
85 cfg_exec(exec_always, --no-startup-id, /tmp/bar.sh)
88 is(parser_calls($config),
92 ################################################################################
94 ################################################################################
97 for_window [class="^Chrome"] floating enable
101 cfg_criteria_add(class, ^Chrome)
102 cfg_for_window(floating enable)
105 is(parser_calls($config),
109 ################################################################################
111 ################################################################################
114 assign [class="^Chrome"] 4
115 assign [class="^Chrome"] named workspace
116 assign [class="^Chrome"] "quoted named workspace"
117 assign [class="^Chrome"] → "quoted named workspace"
121 cfg_criteria_add(class, ^Chrome)
123 cfg_criteria_add(class, ^Chrome)
124 cfg_assign(named workspace)
125 cfg_criteria_add(class, ^Chrome)
126 cfg_assign(quoted named workspace)
127 cfg_criteria_add(class, ^Chrome)
128 cfg_assign(quoted named workspace)
131 is(parser_calls($config),
135 ################################################################################
136 # floating_minimum_size / floating_maximum_size
137 ################################################################################
140 floating_minimum_size 80x55
141 floating_minimum_size 80 x 55
142 floating_maximum_size 73 x 10
146 cfg_floating_minimum_size(80, 55)
147 cfg_floating_minimum_size(80, 55)
148 cfg_floating_maximum_size(73, 10)
151 is(parser_calls($config),
153 'floating_minimum_size ok');
155 ################################################################################
156 # popup_during_fullscreen
157 ################################################################################
160 popup_during_fullscreen ignore
161 popup_during_fullscreen leave_fullscreen
162 popup_during_fullscreen SMArt
166 cfg_popup_during_fullscreen(ignore)
167 cfg_popup_during_fullscreen(leave_fullscreen)
168 cfg_popup_during_fullscreen(smart)
171 is(parser_calls($config),
173 'popup_during_fullscreen ok');
176 ################################################################################
178 ################################################################################
181 floating_modifier Mod1
182 floating_modifier mOd1
186 cfg_floating_modifier(Mod1)
187 cfg_floating_modifier(Mod1)
190 is(parser_calls($config),
192 'floating_modifier ok');
194 ################################################################################
195 # default_orientation
196 ################################################################################
199 default_orientation horizontal
200 default_orientation vertical
201 default_orientation auto
205 cfg_default_orientation(horizontal)
206 cfg_default_orientation(vertical)
207 cfg_default_orientation(auto)
210 is(parser_calls($config),
212 'default_orientation ok');
214 ################################################################################
216 ################################################################################
219 workspace_layout default
220 workspace_layout stacked
221 workspace_layout stacking
222 workspace_layout tabbed
226 cfg_workspace_layout(default)
227 cfg_workspace_layout(stacked)
228 cfg_workspace_layout(stacking)
229 cfg_workspace_layout(tabbed)
232 is(parser_calls($config),
234 'workspace_layout ok');
236 ################################################################################
237 # workspace assignments, with trailing whitespace (ticket #921)
238 ################################################################################
241 workspace "3" output DP-1
242 workspace "3" output VGA-1
246 cfg_workspace(3, DP-1)
247 cfg_workspace(3, VGA-1)
250 is(parser_calls($config),
252 'workspace assignment ok');
254 ################################################################################
256 ################################################################################
268 cfg_new_window(new_window, 1pixel, -1)
269 cfg_new_window(new_window, normal, 2)
270 cfg_new_window(new_window, none, -1)
271 cfg_new_window(new_float, 1pixel, -1)
272 cfg_new_window(new_float, normal, 2)
273 cfg_new_window(new_float, none, -1)
276 is(parser_calls($config),
280 ################################################################################
282 ################################################################################
285 hide_edge_borders none
286 hide_edge_borders vertical
287 hide_edge_borders horizontal
288 hide_edge_borders both
289 hide_edge_borders smart
293 cfg_hide_edge_borders(none)
294 cfg_hide_edge_borders(vertical)
295 cfg_hide_edge_borders(horizontal)
296 cfg_hide_edge_borders(both)
297 cfg_hide_edge_borders(smart)
300 is(parser_calls($config),
302 'hide_edge_borders ok');
304 ################################################################################
305 # focus_follows_mouse
306 ################################################################################
309 focus_follows_mouse yes
310 focus_follows_mouse no
314 cfg_focus_follows_mouse(yes)
315 cfg_focus_follows_mouse(no)
318 is(parser_calls($config),
320 'focus_follows_mouse ok');
322 ################################################################################
324 ################################################################################
332 cfg_mouse_warping(output)
333 cfg_mouse_warping(none)
336 is(parser_calls($config),
340 ################################################################################
341 # force_display_urgency_hint
342 ################################################################################
344 is(parser_calls('force_display_urgency_hint 300'),
345 "cfg_force_display_urgency_hint(300)\n",
346 'force_display_urgency_hint ok');
348 is(parser_calls('force_display_urgency_hint 500 ms'),
349 "cfg_force_display_urgency_hint(500)\n",
350 'force_display_urgency_hint ok');
352 is(parser_calls('force_display_urgency_hint 700ms'),
353 "cfg_force_display_urgency_hint(700)\n",
354 'force_display_urgency_hint ok');
357 force_display_urgency_hint 300
358 force_display_urgency_hint 500 ms
359 force_display_urgency_hint 700ms
360 force_display_urgency_hint 700
364 cfg_force_display_urgency_hint(300)
365 cfg_force_display_urgency_hint(500)
366 cfg_force_display_urgency_hint(700)
367 cfg_force_display_urgency_hint(700)
370 is(parser_calls($config),
372 'force_display_urgency_hint ok');
374 ################################################################################
376 ################################################################################
379 workspace 3 output VGA-1
380 workspace "4: output" output VGA-2
381 workspace bleh output LVDS1/I_1
385 cfg_workspace(3, VGA-1)
386 cfg_workspace(4: output, VGA-2)
387 cfg_workspace(bleh, LVDS1/I_1)
390 is(parser_calls($config),
394 ################################################################################
396 ################################################################################
399 ipc-socket /tmp/i3.sock
400 ipc_socket ~/.i3/i3.sock
404 cfg_ipc_socket(/tmp/i3.sock)
405 cfg_ipc_socket(~/.i3/i3.sock)
408 is(parser_calls($config),
412 ################################################################################
414 ################################################################################
417 client.focused #4c7899 #285577 #ffffff #2e9ef4 #b34d4c
418 client.focused_inactive #333333 #5f676a #ffffff #484e50
419 client.unfocused #333333 #222222 #888888 #292d2e
420 client.urgent #2f343a #900000 #ffffff #900000 #c00000
421 client.placeholder #000000 #0c0c0c #ffffff #000000
425 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4, #b34d4c)
426 cfg_color(client.focused_inactive, #333333, #5f676a, #ffffff, #484e50, NULL)
427 cfg_color(client.unfocused, #333333, #222222, #888888, #292d2e, NULL)
428 cfg_color(client.urgent, #2f343a, #900000, #ffffff, #900000, #c00000)
429 cfg_color(client.placeholder, #000000, #0c0c0c, #ffffff, #000000, NULL)
432 is(parser_calls($config),
436 ################################################################################
437 # Verify that errors don’t harm subsequent valid statements
438 ################################################################################
441 hide_edge_border both
442 client.focused #4c7899 #285577 #ffffff #2e9ef4
445 my $expected_all_tokens = <<'EOT';
446 ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'set_from_resource', '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'
449 my $expected_end = <<'EOT';
450 ERROR: CONFIG: (in file <stdin>)
451 ERROR: CONFIG: Line 1: hide_edge_border both
452 ERROR: CONFIG: ^^^^^^^^^^^^^^^^^^^^^
453 ERROR: CONFIG: Line 2: client.focused #4c7899 #285577 #ffffff #2e9ef4
454 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4, NULL)
457 $expected = $expected_all_tokens . $expected_end;
459 is(parser_calls($config),
461 'errors dont harm subsequent statements');
464 hide_edge_borders FOOBAR
465 client.focused #4c7899 #285577 #ffffff #2e9ef4
469 ERROR: CONFIG: Expected one of these tokens: 'none', 'vertical', 'horizontal', 'both', 'smart', '1', 'yes', 'true', 'on', 'enable', 'active'
470 ERROR: CONFIG: (in file <stdin>)
471 ERROR: CONFIG: Line 1: hide_edge_borders FOOBAR
472 ERROR: CONFIG: ^^^^^^
473 ERROR: CONFIG: Line 2: client.focused #4c7899 #285577 #ffffff #2e9ef4
474 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4, NULL)
477 is(parser_calls($config),
479 'errors dont harm subsequent statements');
481 ################################################################################
482 # Regression: semicolons end comments, but shouldn’t
483 ################################################################################
486 # "foo" client.focused #4c7899 #285577 #ffffff #2e9ef4
493 is(parser_calls($config),
495 'semicolon does not end a comment line');
497 ################################################################################
498 # Error message with 2+2 lines of context
499 ################################################################################
502 # i3 config file (v4)
509 # this should not show up
512 my $expected_head = <<'EOT';
516 my $expected_tail = <<'EOT';
517 ERROR: CONFIG: (in file <stdin>)
518 ERROR: CONFIG: Line 3: font foobar
519 ERROR: CONFIG: Line 4:
520 ERROR: CONFIG: Line 5: unknown qux
521 ERROR: CONFIG: ^^^^^^^^^^^
522 ERROR: CONFIG: Line 6:
523 ERROR: CONFIG: Line 7: # yay
526 $expected = $expected_head . $expected_all_tokens . $expected_tail;
528 is(parser_calls($config),
530 'error message (2+2 context) ok');
532 ################################################################################
533 # Error message with 0+0 lines of context
534 ################################################################################
540 $expected_tail = <<'EOT';
541 ERROR: CONFIG: (in file <stdin>)
542 ERROR: CONFIG: Line 1: unknown qux
543 ERROR: CONFIG: ^^^^^^^^^^^
546 $expected = $expected_all_tokens . $expected_tail;
548 is(parser_calls($config),
550 'error message (0+0 context) ok');
552 ################################################################################
553 # Error message with 1+0 lines of context
554 ################################################################################
561 $expected_tail = <<'EOT';
562 ERROR: CONFIG: (in file <stdin>)
563 ERROR: CONFIG: Line 1: # context before
564 ERROR: CONFIG: Line 2: unknown qux
565 ERROR: CONFIG: ^^^^^^^^^^^
568 $expected = $expected_all_tokens . $expected_tail;
570 is(parser_calls($config),
572 'error message (1+0 context) ok');
574 ################################################################################
575 # Error message with 0+1 lines of context
576 ################################################################################
583 $expected_tail = <<'EOT';
584 ERROR: CONFIG: (in file <stdin>)
585 ERROR: CONFIG: Line 1: unknown qux
586 ERROR: CONFIG: ^^^^^^^^^^^
587 ERROR: CONFIG: Line 2: # context after
590 $expected = $expected_all_tokens . $expected_tail;
592 is(parser_calls($config),
594 'error message (0+1 context) ok');
596 ################################################################################
597 # Error message with 0+2 lines of context
598 ################################################################################
606 $expected_tail = <<'EOT';
607 ERROR: CONFIG: (in file <stdin>)
608 ERROR: CONFIG: Line 1: unknown qux
609 ERROR: CONFIG: ^^^^^^^^^^^
610 ERROR: CONFIG: Line 2: # context after
611 ERROR: CONFIG: Line 3: # context 2 after
614 $expected = $expected_all_tokens . $expected_tail;
616 is(parser_calls($config),
618 'error message (0+2 context) ok');
620 ################################################################################
621 # Error message within mode blocks
622 ################################################################################
626 bindsym x resize shrink left
632 cfg_enter_mode((null), yo)
633 cfg_mode_binding(bindsym, (null), x, (null), (null), (null), resize shrink left)
634 ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', '}'
635 ERROR: CONFIG: (in file <stdin>)
636 ERROR: CONFIG: Line 1: mode "yo" {
637 ERROR: CONFIG: Line 2: bindsym x resize shrink left
638 ERROR: CONFIG: Line 3: unknown qux
639 ERROR: CONFIG: ^^^^^^^^^^^
640 ERROR: CONFIG: Line 4: }
643 is(parser_calls($config),
645 'error message (mode block) ok');
647 ################################################################################
648 # Error message within bar blocks
649 ################################################################################
660 cfg_bar_output(LVDS-1)
661 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', '}'
662 ERROR: CONFIG: (in file <stdin>)
663 ERROR: CONFIG: Line 1: bar {
664 ERROR: CONFIG: Line 2: output LVDS-1
665 ERROR: CONFIG: Line 3: unknown qux
666 ERROR: CONFIG: ^^^^^^^^^^^
667 ERROR: CONFIG: Line 4: }
671 is(parser_calls($config),
673 'error message (bar block) ok');