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
52 bindsym --exclude-titlebar button3 nop
53 bindsym --whole-window --border --exclude-titlebar button3 nop
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)
70 is(parser_calls($config),
74 ################################################################################
75 # exec and exec_always
76 ################################################################################
80 exec --no-startup-id /tmp/foo.sh
82 exec_always --no-startup-id /tmp/bar.sh
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)
92 is(parser_calls($config),
96 ################################################################################
98 ################################################################################
101 for_window [class="^Chrome"] floating enable
105 cfg_criteria_add(class, ^Chrome)
106 cfg_for_window(floating enable)
109 is(parser_calls($config),
113 ################################################################################
115 ################################################################################
118 assign [class="^Chrome"] 4
119 assign [class="^Chrome"] named workspace
120 assign [class="^Chrome"] "quoted named workspace"
121 assign [class="^Chrome"] → "quoted named workspace"
125 cfg_criteria_add(class, ^Chrome)
127 cfg_criteria_add(class, ^Chrome)
128 cfg_assign(named workspace)
129 cfg_criteria_add(class, ^Chrome)
130 cfg_assign(quoted named workspace)
131 cfg_criteria_add(class, ^Chrome)
132 cfg_assign(quoted named workspace)
135 is(parser_calls($config),
139 ################################################################################
140 # floating_minimum_size / floating_maximum_size
141 ################################################################################
144 floating_minimum_size 80x55
145 floating_minimum_size 80 x 55
146 floating_maximum_size 73 x 10
150 cfg_floating_minimum_size(80, 55)
151 cfg_floating_minimum_size(80, 55)
152 cfg_floating_maximum_size(73, 10)
155 is(parser_calls($config),
157 'floating_minimum_size ok');
159 ################################################################################
160 # popup_during_fullscreen
161 ################################################################################
164 popup_during_fullscreen ignore
165 popup_during_fullscreen leave_fullscreen
166 popup_during_fullscreen SMArt
170 cfg_popup_during_fullscreen(ignore)
171 cfg_popup_during_fullscreen(leave_fullscreen)
172 cfg_popup_during_fullscreen(smart)
175 is(parser_calls($config),
177 'popup_during_fullscreen ok');
180 ################################################################################
182 ################################################################################
185 floating_modifier Mod1
186 floating_modifier mOd1
190 cfg_floating_modifier(Mod1)
191 cfg_floating_modifier(Mod1)
194 is(parser_calls($config),
196 'floating_modifier ok');
198 ################################################################################
199 # default_orientation
200 ################################################################################
203 default_orientation horizontal
204 default_orientation vertical
205 default_orientation auto
209 cfg_default_orientation(horizontal)
210 cfg_default_orientation(vertical)
211 cfg_default_orientation(auto)
214 is(parser_calls($config),
216 'default_orientation ok');
218 ################################################################################
220 ################################################################################
223 workspace_layout default
224 workspace_layout stacked
225 workspace_layout stacking
226 workspace_layout tabbed
230 cfg_workspace_layout(default)
231 cfg_workspace_layout(stacked)
232 cfg_workspace_layout(stacking)
233 cfg_workspace_layout(tabbed)
236 is(parser_calls($config),
238 'workspace_layout ok');
240 ################################################################################
241 # workspace assignments, with trailing whitespace (ticket #921)
242 ################################################################################
245 workspace "3" output DP-1
246 workspace "3" output VGA-1
250 cfg_workspace(3, DP-1)
251 cfg_workspace(3, VGA-1)
254 is(parser_calls($config),
256 'workspace assignment ok');
258 ################################################################################
260 ################################################################################
272 cfg_new_window(new_window, 1pixel, -1)
273 cfg_new_window(new_window, normal, 2)
274 cfg_new_window(new_window, none, -1)
275 cfg_new_window(new_float, 1pixel, -1)
276 cfg_new_window(new_float, normal, 2)
277 cfg_new_window(new_float, none, -1)
280 is(parser_calls($config),
284 ################################################################################
286 ################################################################################
289 hide_edge_borders none
290 hide_edge_borders vertical
291 hide_edge_borders horizontal
292 hide_edge_borders both
293 hide_edge_borders smart
297 cfg_hide_edge_borders(none)
298 cfg_hide_edge_borders(vertical)
299 cfg_hide_edge_borders(horizontal)
300 cfg_hide_edge_borders(both)
301 cfg_hide_edge_borders(smart)
304 is(parser_calls($config),
306 'hide_edge_borders ok');
308 ################################################################################
309 # focus_follows_mouse
310 ################################################################################
313 focus_follows_mouse yes
314 focus_follows_mouse no
318 cfg_focus_follows_mouse(yes)
319 cfg_focus_follows_mouse(no)
322 is(parser_calls($config),
324 'focus_follows_mouse ok');
326 ################################################################################
328 ################################################################################
336 cfg_mouse_warping(output)
337 cfg_mouse_warping(none)
340 is(parser_calls($config),
344 ################################################################################
345 # force_display_urgency_hint
346 ################################################################################
348 is(parser_calls('force_display_urgency_hint 300'),
349 "cfg_force_display_urgency_hint(300)\n",
350 'force_display_urgency_hint ok');
352 is(parser_calls('force_display_urgency_hint 500 ms'),
353 "cfg_force_display_urgency_hint(500)\n",
354 'force_display_urgency_hint ok');
356 is(parser_calls('force_display_urgency_hint 700ms'),
357 "cfg_force_display_urgency_hint(700)\n",
358 'force_display_urgency_hint ok');
361 force_display_urgency_hint 300
362 force_display_urgency_hint 500 ms
363 force_display_urgency_hint 700ms
364 force_display_urgency_hint 700
368 cfg_force_display_urgency_hint(300)
369 cfg_force_display_urgency_hint(500)
370 cfg_force_display_urgency_hint(700)
371 cfg_force_display_urgency_hint(700)
374 is(parser_calls($config),
376 'force_display_urgency_hint ok');
378 ################################################################################
380 ################################################################################
383 workspace 3 output VGA-1
384 workspace "4: output" output VGA-2
385 workspace bleh output LVDS1/I_1
389 cfg_workspace(3, VGA-1)
390 cfg_workspace(4: output, VGA-2)
391 cfg_workspace(bleh, LVDS1/I_1)
394 is(parser_calls($config),
398 ################################################################################
400 ################################################################################
403 ipc-socket /tmp/i3.sock
404 ipc_socket ~/.i3/i3.sock
408 cfg_ipc_socket(/tmp/i3.sock)
409 cfg_ipc_socket(~/.i3/i3.sock)
412 is(parser_calls($config),
416 ################################################################################
418 ################################################################################
421 client.focused #4c7899 #285577 #ffffff #2e9ef4 #b34d4c
422 client.focused_inactive #333333 #5f676a #ffffff #484e50
423 client.unfocused #333333 #222222 #888888 #292d2e
424 client.urgent #2f343a #900000 #ffffff #900000 #c00000
425 client.placeholder #000000 #0c0c0c #ffffff #000000
429 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4, #b34d4c)
430 cfg_color(client.focused_inactive, #333333, #5f676a, #ffffff, #484e50, NULL)
431 cfg_color(client.unfocused, #333333, #222222, #888888, #292d2e, NULL)
432 cfg_color(client.urgent, #2f343a, #900000, #ffffff, #900000, #c00000)
433 cfg_color(client.placeholder, #000000, #0c0c0c, #ffffff, #000000, NULL)
436 is(parser_calls($config),
440 ################################################################################
441 # Verify that errors don’t harm subsequent valid statements
442 ################################################################################
445 hide_edge_border both
446 client.focused #4c7899 #285577 #ffffff #2e9ef4
449 my $expected_all_tokens = "ERROR: CONFIG: Expected one of these tokens: <end>, '#', '" . join("', '", 'set ', 'set ', qw(
457 floating_minimum_size
458 floating_maximum_size
475 workspace_auto_back_and_forth
478 force_display_urgency_hint
479 focus_on_window_activation
485 popup_during_fullscreen
489 client.focused_inactive
496 my $expected_end = <<'EOT';
497 ERROR: CONFIG: (in file <stdin>)
498 ERROR: CONFIG: Line 1: hide_edge_border both
499 ERROR: CONFIG: ^^^^^^^^^^^^^^^^^^^^^
500 ERROR: CONFIG: Line 2: client.focused #4c7899 #285577 #ffffff #2e9ef4
501 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4, NULL)
504 $expected = $expected_all_tokens . $expected_end;
506 is(parser_calls($config),
508 'errors dont harm subsequent statements');
511 hide_edge_borders FOOBAR
512 client.focused #4c7899 #285577 #ffffff #2e9ef4
516 ERROR: CONFIG: Expected one of these tokens: 'none', 'vertical', 'horizontal', 'both', 'smart', '1', 'yes', 'true', 'on', 'enable', 'active'
517 ERROR: CONFIG: (in file <stdin>)
518 ERROR: CONFIG: Line 1: hide_edge_borders FOOBAR
519 ERROR: CONFIG: ^^^^^^
520 ERROR: CONFIG: Line 2: client.focused #4c7899 #285577 #ffffff #2e9ef4
521 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4, NULL)
524 is(parser_calls($config),
526 'errors dont harm subsequent statements');
528 ################################################################################
529 # Regression: semicolons end comments, but shouldn’t
530 ################################################################################
533 # "foo" client.focused #4c7899 #285577 #ffffff #2e9ef4
540 is(parser_calls($config),
542 'semicolon does not end a comment line');
544 ################################################################################
545 # Error message with 2+2 lines of context
546 ################################################################################
549 # i3 config file (v4)
556 # this should not show up
559 my $expected_head = <<'EOT';
563 my $expected_tail = <<'EOT';
564 ERROR: CONFIG: (in file <stdin>)
565 ERROR: CONFIG: Line 3: font foobar
566 ERROR: CONFIG: Line 4:
567 ERROR: CONFIG: Line 5: unknown qux
568 ERROR: CONFIG: ^^^^^^^^^^^
569 ERROR: CONFIG: Line 6:
570 ERROR: CONFIG: Line 7: # yay
573 $expected = $expected_head . $expected_all_tokens . $expected_tail;
575 is(parser_calls($config),
577 'error message (2+2 context) ok');
579 ################################################################################
580 # Error message with 0+0 lines of context
581 ################################################################################
587 $expected_tail = <<'EOT';
588 ERROR: CONFIG: (in file <stdin>)
589 ERROR: CONFIG: Line 1: unknown qux
590 ERROR: CONFIG: ^^^^^^^^^^^
593 $expected = $expected_all_tokens . $expected_tail;
595 is(parser_calls($config),
597 'error message (0+0 context) ok');
599 ################################################################################
600 # Error message with 1+0 lines of context
601 ################################################################################
608 $expected_tail = <<'EOT';
609 ERROR: CONFIG: (in file <stdin>)
610 ERROR: CONFIG: Line 1: # context before
611 ERROR: CONFIG: Line 2: unknown qux
612 ERROR: CONFIG: ^^^^^^^^^^^
615 $expected = $expected_all_tokens . $expected_tail;
617 is(parser_calls($config),
619 'error message (1+0 context) ok');
621 ################################################################################
622 # Error message with 0+1 lines of context
623 ################################################################################
630 $expected_tail = <<'EOT';
631 ERROR: CONFIG: (in file <stdin>)
632 ERROR: CONFIG: Line 1: unknown qux
633 ERROR: CONFIG: ^^^^^^^^^^^
634 ERROR: CONFIG: Line 2: # context after
637 $expected = $expected_all_tokens . $expected_tail;
639 is(parser_calls($config),
641 'error message (0+1 context) ok');
643 ################################################################################
644 # Error message with 0+2 lines of context
645 ################################################################################
653 $expected_tail = <<'EOT';
654 ERROR: CONFIG: (in file <stdin>)
655 ERROR: CONFIG: Line 1: unknown qux
656 ERROR: CONFIG: ^^^^^^^^^^^
657 ERROR: CONFIG: Line 2: # context after
658 ERROR: CONFIG: Line 3: # context 2 after
661 $expected = $expected_all_tokens . $expected_tail;
663 is(parser_calls($config),
665 'error message (0+2 context) ok');
667 ################################################################################
668 # Error message within mode blocks
669 ################################################################################
673 bindsym x resize shrink left
679 cfg_enter_mode((null), yo)
680 cfg_mode_binding(bindsym, (null), x, (null), (null), (null), (null), resize shrink left)
681 ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', '}'
682 ERROR: CONFIG: (in file <stdin>)
683 ERROR: CONFIG: Line 1: mode "yo" {
684 ERROR: CONFIG: Line 2: bindsym x resize shrink left
685 ERROR: CONFIG: Line 3: unknown qux
686 ERROR: CONFIG: ^^^^^^^^^^^
687 ERROR: CONFIG: Line 4: }
690 is(parser_calls($config),
692 'error message (mode block) ok');
694 ################################################################################
695 # Error message within bar blocks
696 ################################################################################
707 cfg_bar_output(LVDS-1)
708 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', '}'
709 ERROR: CONFIG: (in file <stdin>)
710 ERROR: CONFIG: Line 1: bar {
711 ERROR: CONFIG: Line 2: output LVDS-1
712 ERROR: CONFIG: Line 3: unknown qux
713 ERROR: CONFIG: ^^^^^^^^^^^
714 ERROR: CONFIG: Line 4: }
718 is(parser_calls($config),
720 'error message (bar block) ok');