2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • https://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"] workspace number 3
120 assign [class="^Chrome"] named workspace
121 assign [class="^Chrome"] "quoted named workspace"
122 assign [class="^Chrome"] → "quoted named workspace"
126 cfg_criteria_add(class, ^Chrome)
128 cfg_criteria_add(class, ^Chrome)
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)
138 is(parser_calls($config),
142 ################################################################################
143 # floating_minimum_size / floating_maximum_size
144 ################################################################################
147 floating_minimum_size 80x55
148 floating_minimum_size 80 x 55
149 floating_maximum_size 73 x 10
153 cfg_floating_minimum_size(80, 55)
154 cfg_floating_minimum_size(80, 55)
155 cfg_floating_maximum_size(73, 10)
158 is(parser_calls($config),
160 'floating_minimum_size ok');
162 ################################################################################
163 # popup_during_fullscreen
164 ################################################################################
167 popup_during_fullscreen ignore
168 popup_during_fullscreen leave_fullscreen
169 popup_during_fullscreen SMArt
173 cfg_popup_during_fullscreen(ignore)
174 cfg_popup_during_fullscreen(leave_fullscreen)
175 cfg_popup_during_fullscreen(smart)
178 is(parser_calls($config),
180 'popup_during_fullscreen ok');
183 ################################################################################
185 ################################################################################
188 floating_modifier Mod1
189 floating_modifier mOd1
193 cfg_floating_modifier(Mod1)
194 cfg_floating_modifier(Mod1)
197 is(parser_calls($config),
199 'floating_modifier ok');
201 ################################################################################
202 # default_orientation
203 ################################################################################
206 default_orientation horizontal
207 default_orientation vertical
208 default_orientation auto
212 cfg_default_orientation(horizontal)
213 cfg_default_orientation(vertical)
214 cfg_default_orientation(auto)
217 is(parser_calls($config),
219 'default_orientation ok');
221 ################################################################################
223 ################################################################################
226 workspace_layout default
227 workspace_layout stacked
228 workspace_layout stacking
229 workspace_layout tabbed
233 cfg_workspace_layout(default)
234 cfg_workspace_layout(stacked)
235 cfg_workspace_layout(stacking)
236 cfg_workspace_layout(tabbed)
239 is(parser_calls($config),
241 'workspace_layout ok');
243 ################################################################################
244 # workspace assignments, with trailing whitespace (ticket #921)
245 ################################################################################
248 workspace "3" output DP-1
249 workspace "3" output VGA-1
253 cfg_workspace(3, DP-1)
254 cfg_workspace(3, VGA-1)
257 is(parser_calls($config),
259 'workspace assignment ok');
261 ################################################################################
263 ################################################################################
269 default_border 1pixel
270 default_border normal
275 default_floating_border 1pixel
276 default_floating_border normal
277 default_floating_border none
281 cfg_default_border(new_window, 1pixel, -1)
282 cfg_default_border(new_window, normal, 2)
283 cfg_default_border(new_window, none, -1)
284 cfg_default_border(default_border, 1pixel, -1)
285 cfg_default_border(default_border, normal, 2)
286 cfg_default_border(default_border, none, -1)
287 cfg_default_border(new_float, 1pixel, -1)
288 cfg_default_border(new_float, normal, 2)
289 cfg_default_border(new_float, none, -1)
290 cfg_default_border(default_floating_border, 1pixel, -1)
291 cfg_default_border(default_floating_border, normal, 2)
292 cfg_default_border(default_floating_border, none, -1)
295 # TODO: are there no tests for "border pixel 1" etc?
297 is(parser_calls($config),
301 ################################################################################
303 ################################################################################
306 hide_edge_borders none
307 hide_edge_borders vertical
308 hide_edge_borders horizontal
309 hide_edge_borders both
310 hide_edge_borders smart
314 cfg_hide_edge_borders(none)
315 cfg_hide_edge_borders(vertical)
316 cfg_hide_edge_borders(horizontal)
317 cfg_hide_edge_borders(both)
318 cfg_hide_edge_borders(smart)
321 is(parser_calls($config),
323 'hide_edge_borders ok');
325 ################################################################################
326 # focus_follows_mouse
327 ################################################################################
330 focus_follows_mouse yes
331 focus_follows_mouse no
335 cfg_focus_follows_mouse(yes)
336 cfg_focus_follows_mouse(no)
339 is(parser_calls($config),
341 'focus_follows_mouse ok');
343 ################################################################################
345 ################################################################################
353 cfg_mouse_warping(output)
354 cfg_mouse_warping(none)
357 is(parser_calls($config),
361 ################################################################################
362 # force_display_urgency_hint
363 ################################################################################
365 is(parser_calls('force_display_urgency_hint 300'),
366 "cfg_force_display_urgency_hint(300)\n",
367 'force_display_urgency_hint ok');
369 is(parser_calls('force_display_urgency_hint 500 ms'),
370 "cfg_force_display_urgency_hint(500)\n",
371 'force_display_urgency_hint ok');
373 is(parser_calls('force_display_urgency_hint 700ms'),
374 "cfg_force_display_urgency_hint(700)\n",
375 'force_display_urgency_hint ok');
378 force_display_urgency_hint 300
379 force_display_urgency_hint 500 ms
380 force_display_urgency_hint 700ms
381 force_display_urgency_hint 700
385 cfg_force_display_urgency_hint(300)
386 cfg_force_display_urgency_hint(500)
387 cfg_force_display_urgency_hint(700)
388 cfg_force_display_urgency_hint(700)
391 is(parser_calls($config),
393 'force_display_urgency_hint ok');
395 ################################################################################
397 ################################################################################
400 workspace 3 output VGA-1
401 workspace "4: output" output VGA-2
402 workspace bleh output LVDS1/I_1
406 cfg_workspace(3, VGA-1)
407 cfg_workspace(4: output, VGA-2)
408 cfg_workspace(bleh, LVDS1/I_1)
411 is(parser_calls($config),
415 ################################################################################
417 ################################################################################
420 ipc-socket /tmp/i3.sock
421 ipc_socket ~/.i3/i3.sock
425 cfg_ipc_socket(/tmp/i3.sock)
426 cfg_ipc_socket(~/.i3/i3.sock)
429 is(parser_calls($config),
433 ################################################################################
435 ################################################################################
438 client.focused #4c7899 #285577 #ffffff #2e9ef4 #b34d4c
439 client.focused_inactive #333333 #5f676a #ffffff #484e50
440 client.unfocused #333333 #222222 #888888 #292d2e
441 client.urgent #2f343a #900000 #ffffff #900000 #c00000
442 client.placeholder #000000 #0c0c0c #ffffff #000000
446 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4, #b34d4c)
447 cfg_color(client.focused_inactive, #333333, #5f676a, #ffffff, #484e50, NULL)
448 cfg_color(client.unfocused, #333333, #222222, #888888, #292d2e, NULL)
449 cfg_color(client.urgent, #2f343a, #900000, #ffffff, #900000, #c00000)
450 cfg_color(client.placeholder, #000000, #0c0c0c, #ffffff, #000000, NULL)
453 is(parser_calls($config),
457 ################################################################################
458 # Verify that errors don’t harm subsequent valid statements
459 ################################################################################
462 hide_edge_border both
463 client.focused #4c7899 #285577 #ffffff #2e9ef4
466 my $expected_all_tokens = "ERROR: CONFIG: Expected one of these tokens: <end>, '#', '" . join("', '", 'set ', 'set ', qw(
474 floating_minimum_size
475 floating_maximum_size
481 default_floating_border
495 workspace_auto_back_and_forth
498 force_display_urgency_hint
499 focus_on_window_activation
506 popup_during_fullscreen
510 client.focused_inactive
517 my $expected_end = <<'EOT';
518 ERROR: CONFIG: (in file <stdin>)
519 ERROR: CONFIG: Line 1: hide_edge_border both
520 ERROR: CONFIG: ^^^^^^^^^^^^^^^^^^^^^
521 ERROR: CONFIG: Line 2: client.focused #4c7899 #285577 #ffffff #2e9ef4
522 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4, NULL)
525 $expected = $expected_all_tokens . $expected_end;
527 is(parser_calls($config),
529 'errors dont harm subsequent statements');
532 hide_edge_borders FOOBAR
533 client.focused #4c7899 #285577 #ffffff #2e9ef4
537 ERROR: CONFIG: Expected one of these tokens: 'none', 'vertical', 'horizontal', 'both', 'smart', '1', 'yes', 'true', 'on', 'enable', 'active'
538 ERROR: CONFIG: (in file <stdin>)
539 ERROR: CONFIG: Line 1: hide_edge_borders FOOBAR
540 ERROR: CONFIG: ^^^^^^
541 ERROR: CONFIG: Line 2: client.focused #4c7899 #285577 #ffffff #2e9ef4
542 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4, NULL)
545 is(parser_calls($config),
547 'errors dont harm subsequent statements');
549 ################################################################################
550 # Regression: semicolons end comments, but shouldn’t
551 ################################################################################
554 # "foo" client.focused #4c7899 #285577 #ffffff #2e9ef4
561 is(parser_calls($config),
563 'semicolon does not end a comment line');
565 ################################################################################
566 # Error message with 2+2 lines of context
567 ################################################################################
570 # i3 config file (v4)
577 # this should not show up
580 my $expected_head = <<'EOT';
584 my $expected_tail = <<'EOT';
585 ERROR: CONFIG: (in file <stdin>)
586 ERROR: CONFIG: Line 3: font foobar
587 ERROR: CONFIG: Line 4:
588 ERROR: CONFIG: Line 5: unknown qux
589 ERROR: CONFIG: ^^^^^^^^^^^
590 ERROR: CONFIG: Line 6:
591 ERROR: CONFIG: Line 7: # yay
594 $expected = $expected_head . $expected_all_tokens . $expected_tail;
596 is(parser_calls($config),
598 'error message (2+2 context) ok');
600 ################################################################################
601 # Error message with 0+0 lines of context
602 ################################################################################
608 $expected_tail = <<'EOT';
609 ERROR: CONFIG: (in file <stdin>)
610 ERROR: CONFIG: Line 1: unknown qux
611 ERROR: CONFIG: ^^^^^^^^^^^
614 $expected = $expected_all_tokens . $expected_tail;
616 is(parser_calls($config),
618 'error message (0+0 context) ok');
620 ################################################################################
621 # Error message with 1+0 lines of context
622 ################################################################################
629 $expected_tail = <<'EOT';
630 ERROR: CONFIG: (in file <stdin>)
631 ERROR: CONFIG: Line 1: # context before
632 ERROR: CONFIG: Line 2: unknown qux
633 ERROR: CONFIG: ^^^^^^^^^^^
636 $expected = $expected_all_tokens . $expected_tail;
638 is(parser_calls($config),
640 'error message (1+0 context) ok');
642 ################################################################################
643 # Error message with 0+1 lines of context
644 ################################################################################
651 $expected_tail = <<'EOT';
652 ERROR: CONFIG: (in file <stdin>)
653 ERROR: CONFIG: Line 1: unknown qux
654 ERROR: CONFIG: ^^^^^^^^^^^
655 ERROR: CONFIG: Line 2: # context after
658 $expected = $expected_all_tokens . $expected_tail;
660 is(parser_calls($config),
662 'error message (0+1 context) ok');
664 ################################################################################
665 # Error message with 0+2 lines of context
666 ################################################################################
674 $expected_tail = <<'EOT';
675 ERROR: CONFIG: (in file <stdin>)
676 ERROR: CONFIG: Line 1: unknown qux
677 ERROR: CONFIG: ^^^^^^^^^^^
678 ERROR: CONFIG: Line 2: # context after
679 ERROR: CONFIG: Line 3: # context 2 after
682 $expected = $expected_all_tokens . $expected_tail;
684 is(parser_calls($config),
686 'error message (0+2 context) ok');
688 ################################################################################
689 # Error message within mode blocks
690 ################################################################################
694 bindsym x resize shrink left
700 cfg_enter_mode((null), yo)
701 cfg_mode_binding(bindsym, (null), x, (null), (null), (null), (null), resize shrink left)
702 ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', '}'
703 ERROR: CONFIG: (in file <stdin>)
704 ERROR: CONFIG: Line 1: mode "yo" {
705 ERROR: CONFIG: Line 2: bindsym x resize shrink left
706 ERROR: CONFIG: Line 3: unknown qux
707 ERROR: CONFIG: ^^^^^^^^^^^
708 ERROR: CONFIG: Line 4: }
711 is(parser_calls($config),
713 'error message (mode block) ok');
715 ################################################################################
716 # Error message within bar blocks
717 ################################################################################
728 cfg_bar_output(LVDS-1)
729 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', 'strip_workspace_name', 'verbose', 'colors', '}'
730 ERROR: CONFIG: (in file <stdin>)
731 ERROR: CONFIG: Line 1: bar {
732 ERROR: CONFIG: Line 2: output LVDS-1
733 ERROR: CONFIG: Line 3: unknown qux
734 ERROR: CONFIG: ^^^^^^^^^^^
735 ERROR: CONFIG: Line 4: }
739 is(parser_calls($config),
741 'error message (bar block) ok');