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
53 my $expected = <<'EOT';
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)
62 is(parser_calls($config),
66 ################################################################################
67 # exec and exec_always
68 ################################################################################
72 exec --no-startup-id /tmp/foo.sh
74 exec_always --no-startup-id /tmp/bar.sh
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)
84 is(parser_calls($config),
88 ################################################################################
90 ################################################################################
93 for_window [class="^Chrome"] floating enable
97 cfg_criteria_add(class, ^Chrome)
98 cfg_for_window(floating enable)
101 is(parser_calls($config),
105 ################################################################################
107 ################################################################################
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"
117 cfg_criteria_add(class, ^Chrome)
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)
127 is(parser_calls($config),
131 ################################################################################
132 # floating_minimum_size / floating_maximum_size
133 ################################################################################
136 floating_minimum_size 80x55
137 floating_minimum_size 80 x 55
138 floating_maximum_size 73 x 10
142 cfg_floating_minimum_size(80, 55)
143 cfg_floating_minimum_size(80, 55)
144 cfg_floating_maximum_size(73, 10)
147 is(parser_calls($config),
149 'floating_minimum_size ok');
151 ################################################################################
152 # popup_during_fullscreen
153 ################################################################################
156 popup_during_fullscreen ignore
157 popup_during_fullscreen leave_fullscreen
158 popup_during_fullscreen SMArt
162 cfg_popup_during_fullscreen(ignore)
163 cfg_popup_during_fullscreen(leave_fullscreen)
164 cfg_popup_during_fullscreen(smart)
167 is(parser_calls($config),
169 'popup_during_fullscreen ok');
172 ################################################################################
174 ################################################################################
177 floating_modifier Mod1
178 floating_modifier mOd1
182 cfg_floating_modifier(Mod1)
183 cfg_floating_modifier(Mod1)
186 is(parser_calls($config),
188 'floating_modifier ok');
190 ################################################################################
191 # default_orientation
192 ################################################################################
195 default_orientation horizontal
196 default_orientation vertical
197 default_orientation auto
201 cfg_default_orientation(horizontal)
202 cfg_default_orientation(vertical)
203 cfg_default_orientation(auto)
206 is(parser_calls($config),
208 'default_orientation ok');
210 ################################################################################
212 ################################################################################
215 workspace_layout default
216 workspace_layout stacked
217 workspace_layout stacking
218 workspace_layout tabbed
222 cfg_workspace_layout(default)
223 cfg_workspace_layout(stacked)
224 cfg_workspace_layout(stacking)
225 cfg_workspace_layout(tabbed)
228 is(parser_calls($config),
230 'workspace_layout ok');
232 ################################################################################
233 # workspace assignments, with trailing whitespace (ticket #921)
234 ################################################################################
237 workspace "3" output DP-1
238 workspace "3" output VGA-1
242 cfg_workspace(3, DP-1)
243 cfg_workspace(3, VGA-1)
246 is(parser_calls($config),
248 'workspace assignment ok');
250 ################################################################################
252 ################################################################################
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)
272 is(parser_calls($config),
276 ################################################################################
278 ################################################################################
281 hide_edge_borders none
282 hide_edge_borders vertical
283 hide_edge_borders horizontal
284 hide_edge_borders both
288 cfg_hide_edge_borders(none)
289 cfg_hide_edge_borders(vertical)
290 cfg_hide_edge_borders(horizontal)
291 cfg_hide_edge_borders(both)
294 is(parser_calls($config),
296 'hide_edge_borders ok');
298 ################################################################################
299 # focus_follows_mouse
300 ################################################################################
303 focus_follows_mouse yes
304 focus_follows_mouse no
308 cfg_focus_follows_mouse(yes)
309 cfg_focus_follows_mouse(no)
312 is(parser_calls($config),
314 'focus_follows_mouse ok');
316 ################################################################################
318 ################################################################################
326 cfg_mouse_warping(output)
327 cfg_mouse_warping(none)
330 is(parser_calls($config),
334 ################################################################################
335 # force_display_urgency_hint
336 ################################################################################
338 is(parser_calls('force_display_urgency_hint 300'),
339 "cfg_force_display_urgency_hint(300)\n",
340 'force_display_urgency_hint ok');
342 is(parser_calls('force_display_urgency_hint 500 ms'),
343 "cfg_force_display_urgency_hint(500)\n",
344 'force_display_urgency_hint ok');
346 is(parser_calls('force_display_urgency_hint 700ms'),
347 "cfg_force_display_urgency_hint(700)\n",
348 'force_display_urgency_hint ok');
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
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)
364 is(parser_calls($config),
366 'force_display_urgency_hint ok');
368 ################################################################################
370 ################################################################################
373 workspace 3 output VGA-1
374 workspace "4: output" output VGA-2
375 workspace bleh output LVDS1/I_1
379 cfg_workspace(3, VGA-1)
380 cfg_workspace(4: output, VGA-2)
381 cfg_workspace(bleh, LVDS1/I_1)
384 is(parser_calls($config),
388 ################################################################################
390 ################################################################################
393 ipc-socket /tmp/i3.sock
394 ipc_socket ~/.i3/i3.sock
398 cfg_ipc_socket(/tmp/i3.sock)
399 cfg_ipc_socket(~/.i3/i3.sock)
402 is(parser_calls($config),
406 ################################################################################
408 ################################################################################
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
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)
426 is(parser_calls($config),
430 ################################################################################
431 # Verify that errors don’t harm subsequent valid statements
432 ################################################################################
435 hide_edge_border both
436 client.focused #4c7899 #285577 #ffffff #2e9ef4
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'
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)
451 $expected = $expected_all_tokens . $expected_end;
453 is(parser_calls($config),
455 'errors dont harm subsequent statements');
458 hide_edge_borders FOOBAR
459 client.focused #4c7899 #285577 #ffffff #2e9ef4
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)
471 is(parser_calls($config),
473 'errors dont harm subsequent statements');
475 ################################################################################
476 # Regression: semicolons end comments, but shouldn’t
477 ################################################################################
480 # "foo" client.focused #4c7899 #285577 #ffffff #2e9ef4
487 is(parser_calls($config),
489 'semicolon does not end a comment line');
491 ################################################################################
492 # Error message with 2+2 lines of context
493 ################################################################################
496 # i3 config file (v4)
503 # this should not show up
506 my $expected_head = <<'EOT';
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
520 $expected = $expected_head . $expected_all_tokens . $expected_tail;
522 is(parser_calls($config),
524 'error message (2+2 context) ok');
526 ################################################################################
527 # Error message with 0+0 lines of context
528 ################################################################################
534 $expected_tail = <<'EOT';
535 ERROR: CONFIG: (in file <stdin>)
536 ERROR: CONFIG: Line 1: unknown qux
537 ERROR: CONFIG: ^^^^^^^^^^^
540 $expected = $expected_all_tokens . $expected_tail;
542 is(parser_calls($config),
544 'error message (0+0 context) ok');
546 ################################################################################
547 # Error message with 1+0 lines of context
548 ################################################################################
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: ^^^^^^^^^^^
562 $expected = $expected_all_tokens . $expected_tail;
564 is(parser_calls($config),
566 'error message (1+0 context) ok');
568 ################################################################################
569 # Error message with 0+1 lines of context
570 ################################################################################
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
584 $expected = $expected_all_tokens . $expected_tail;
586 is(parser_calls($config),
588 'error message (0+1 context) ok');
590 ################################################################################
591 # Error message with 0+2 lines of context
592 ################################################################################
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
608 $expected = $expected_all_tokens . $expected_tail;
610 is(parser_calls($config),
612 'error message (0+2 context) ok');
614 ################################################################################
615 # Error message within mode blocks
616 ################################################################################
620 bindsym x resize shrink left
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: }
637 is(parser_calls($config),
639 'error message (mode block) ok');
641 ################################################################################
642 # Error message within bar blocks
643 ################################################################################
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: }
664 is(parser_calls($config),
666 'error message (bar block) ok');