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
51 my $expected = <<'EOT';
53 cfg_mode_binding(bindsym, Mod1,Shift, x, (null), resize grow)
54 cfg_mode_binding(bindcode, Mod1, 44, (null), resize shrink)
55 cfg_mode_binding(bindsym, Mod1, x, --release, exec foo)
58 is(parser_calls($config),
60 'single number (move workspace 3) ok');
62 ################################################################################
63 # exec and exec_always
64 ################################################################################
68 exec --no-startup-id /tmp/foo.sh
70 exec_always --no-startup-id /tmp/bar.sh
74 cfg_exec(exec, (null), geeqie)
75 cfg_exec(exec, --no-startup-id, /tmp/foo.sh)
76 cfg_exec(exec_always, (null), firefox)
77 cfg_exec(exec_always, --no-startup-id, /tmp/bar.sh)
80 is(parser_calls($config),
84 ################################################################################
86 ################################################################################
89 for_window [class="^Chrome"] floating enable
93 cfg_criteria_add(class, ^Chrome)
94 cfg_for_window(floating enable)
97 is(parser_calls($config),
101 ################################################################################
103 ################################################################################
106 assign [class="^Chrome"] 4
107 assign [class="^Chrome"] named workspace
108 assign [class="^Chrome"] "quoted named workspace"
109 assign [class="^Chrome"] → "quoted named workspace"
113 cfg_criteria_add(class, ^Chrome)
115 cfg_criteria_add(class, ^Chrome)
116 cfg_assign(named workspace)
117 cfg_criteria_add(class, ^Chrome)
118 cfg_assign(quoted named workspace)
119 cfg_criteria_add(class, ^Chrome)
120 cfg_assign(quoted named workspace)
123 is(parser_calls($config),
127 ################################################################################
128 # floating_minimum_size / floating_maximum_size
129 ################################################################################
132 floating_minimum_size 80x55
133 floating_minimum_size 80 x 55
134 floating_maximum_size 73 x 10
138 cfg_floating_minimum_size(80, 55)
139 cfg_floating_minimum_size(80, 55)
140 cfg_floating_maximum_size(73, 10)
143 is(parser_calls($config),
145 'floating_minimum_size ok');
147 ################################################################################
148 # popup_during_fullscreen
149 ################################################################################
152 popup_during_fullscreen ignore
153 popup_during_fullscreen leave_fullscreen
154 popup_during_fullscreen SMArt
158 cfg_popup_during_fullscreen(ignore)
159 cfg_popup_during_fullscreen(leave_fullscreen)
160 cfg_popup_during_fullscreen(smart)
163 is(parser_calls($config),
165 'popup_during_fullscreen ok');
168 ################################################################################
170 ################################################################################
173 floating_modifier Mod1
174 floating_modifier mOd1
178 cfg_floating_modifier(Mod1)
179 cfg_floating_modifier(Mod1)
182 is(parser_calls($config),
184 'floating_modifier ok');
186 ################################################################################
187 # default_orientation
188 ################################################################################
191 default_orientation horizontal
192 default_orientation vertical
193 default_orientation auto
197 cfg_default_orientation(horizontal)
198 cfg_default_orientation(vertical)
199 cfg_default_orientation(auto)
202 is(parser_calls($config),
204 'default_orientation ok');
206 ################################################################################
208 ################################################################################
211 workspace_layout default
212 workspace_layout stacked
213 workspace_layout stacking
214 workspace_layout tabbed
218 cfg_workspace_layout(default)
219 cfg_workspace_layout(stacked)
220 cfg_workspace_layout(stacking)
221 cfg_workspace_layout(tabbed)
224 is(parser_calls($config),
226 'workspace_layout ok');
228 ################################################################################
229 # workspace assignments, with trailing whitespace (ticket #921)
230 ################################################################################
233 workspace "3" output DP-1
234 workspace "3" output VGA-1
238 cfg_workspace(3, DP-1)
239 cfg_workspace(3, VGA-1)
242 is(parser_calls($config),
244 'workspace assignment ok');
246 ################################################################################
248 ################################################################################
260 cfg_new_window(new_window, 1pixel, -1)
261 cfg_new_window(new_window, normal, 2)
262 cfg_new_window(new_window, none, -1)
263 cfg_new_window(new_float, 1pixel, -1)
264 cfg_new_window(new_float, normal, 2)
265 cfg_new_window(new_float, none, -1)
268 is(parser_calls($config),
272 ################################################################################
274 ################################################################################
277 hide_edge_borders none
278 hide_edge_borders vertical
279 hide_edge_borders horizontal
280 hide_edge_borders both
284 cfg_hide_edge_borders(none)
285 cfg_hide_edge_borders(vertical)
286 cfg_hide_edge_borders(horizontal)
287 cfg_hide_edge_borders(both)
290 is(parser_calls($config),
292 'hide_edge_borders ok');
294 ################################################################################
295 # focus_follows_mouse
296 ################################################################################
299 focus_follows_mouse yes
300 focus_follows_mouse no
304 cfg_focus_follows_mouse(yes)
305 cfg_focus_follows_mouse(no)
308 is(parser_calls($config),
310 'focus_follows_mouse ok');
312 ################################################################################
313 # force_display_urgency_hint
314 ################################################################################
316 is(parser_calls('force_display_urgency_hint 300'),
317 "cfg_force_display_urgency_hint(300)\n",
318 'force_display_urgency_hint ok');
320 is(parser_calls('force_display_urgency_hint 500 ms'),
321 "cfg_force_display_urgency_hint(500)\n",
322 'force_display_urgency_hint ok');
324 is(parser_calls('force_display_urgency_hint 700ms'),
325 "cfg_force_display_urgency_hint(700)\n",
326 'force_display_urgency_hint ok');
329 force_display_urgency_hint 300
330 force_display_urgency_hint 500 ms
331 force_display_urgency_hint 700ms
332 force_display_urgency_hint 700
336 cfg_force_display_urgency_hint(300)
337 cfg_force_display_urgency_hint(500)
338 cfg_force_display_urgency_hint(700)
339 cfg_force_display_urgency_hint(700)
342 is(parser_calls($config),
344 'force_display_urgency_hint ok');
346 ################################################################################
348 ################################################################################
351 workspace 3 output VGA-1
352 workspace "4: output" output VGA-2
353 workspace bleh output LVDS1/I_1
357 cfg_workspace(3, VGA-1)
358 cfg_workspace(4: output, VGA-2)
359 cfg_workspace(bleh, LVDS1/I_1)
362 is(parser_calls($config),
366 ################################################################################
368 ################################################################################
371 ipc-socket /tmp/i3.sock
372 ipc_socket ~/.i3/i3.sock
376 cfg_ipc_socket(/tmp/i3.sock)
377 cfg_ipc_socket(~/.i3/i3.sock)
380 is(parser_calls($config),
384 ################################################################################
386 ################################################################################
389 client.focused #4c7899 #285577 #ffffff #2e9ef4
390 client.focused_inactive #333333 #5f676a #ffffff #484e50
391 client.unfocused #333333 #222222 #888888 #292d2e
392 client.urgent #2f343a #900000 #ffffff #900000
396 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4)
397 cfg_color(client.focused_inactive, #333333, #5f676a, #ffffff, #484e50)
398 cfg_color(client.unfocused, #333333, #222222, #888888, #292d2e)
399 cfg_color(client.urgent, #2f343a, #900000, #ffffff, #900000)
402 is(parser_calls($config),
406 ################################################################################
407 # Verify that errors don’t harm subsequent valid statements
408 ################################################################################
411 hide_edge_border both
412 client.focused #4c7899 #285577 #ffffff #2e9ef4
415 my $expected_all_tokens = <<'EOT';
416 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', 'focus_follows_mouse', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent'
419 my $expected_end = <<'EOT';
420 ERROR: CONFIG: (in file <stdin>)
421 ERROR: CONFIG: Line 1: hide_edge_border both
422 ERROR: CONFIG: ^^^^^^^^^^^^^^^^^^^^^
423 ERROR: CONFIG: Line 2: client.focused #4c7899 #285577 #ffffff #2e9ef4
424 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4)
427 $expected = $expected_all_tokens . $expected_end;
429 is(parser_calls($config),
431 'errors dont harm subsequent statements');
434 hide_edge_borders FOOBAR
435 client.focused #4c7899 #285577 #ffffff #2e9ef4
439 ERROR: CONFIG: Expected one of these tokens: 'none', 'vertical', 'horizontal', 'both', '1', 'yes', 'true', 'on', 'enable', 'active'
440 ERROR: CONFIG: (in file <stdin>)
441 ERROR: CONFIG: Line 1: hide_edge_borders FOOBAR
442 ERROR: CONFIG: ^^^^^^
443 ERROR: CONFIG: Line 2: client.focused #4c7899 #285577 #ffffff #2e9ef4
444 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4)
447 is(parser_calls($config),
449 'errors dont harm subsequent statements');
452 ################################################################################
453 # Error message with 2+2 lines of context
454 ################################################################################
457 # i3 config file (v4)
464 # this should not show up
467 my $expected_head = <<'EOT';
471 my $expected_tail = <<'EOT';
472 ERROR: CONFIG: (in file <stdin>)
473 ERROR: CONFIG: Line 3: font foobar
474 ERROR: CONFIG: Line 4:
475 ERROR: CONFIG: Line 5: unknown qux
476 ERROR: CONFIG: ^^^^^^^^^^^
477 ERROR: CONFIG: Line 6:
478 ERROR: CONFIG: Line 7: # yay
481 $expected = $expected_head . $expected_all_tokens . $expected_tail;
483 is(parser_calls($config),
485 'error message (2+2 context) ok');
487 ################################################################################
488 # Error message with 0+0 lines of context
489 ################################################################################
495 $expected_tail = <<'EOT';
496 ERROR: CONFIG: (in file <stdin>)
497 ERROR: CONFIG: Line 1: unknown qux
498 ERROR: CONFIG: ^^^^^^^^^^^
501 $expected = $expected_all_tokens . $expected_tail;
503 is(parser_calls($config),
505 'error message (0+0 context) ok');
507 ################################################################################
508 # Error message with 1+0 lines of context
509 ################################################################################
516 $expected_tail = <<'EOT';
517 ERROR: CONFIG: (in file <stdin>)
518 ERROR: CONFIG: Line 1: # context before
519 ERROR: CONFIG: Line 2: unknown qux
520 ERROR: CONFIG: ^^^^^^^^^^^
523 $expected = $expected_all_tokens . $expected_tail;
525 is(parser_calls($config),
527 'error message (1+0 context) ok');
529 ################################################################################
530 # Error message with 0+1 lines of context
531 ################################################################################
538 $expected_tail = <<'EOT';
539 ERROR: CONFIG: (in file <stdin>)
540 ERROR: CONFIG: Line 1: unknown qux
541 ERROR: CONFIG: ^^^^^^^^^^^
542 ERROR: CONFIG: Line 2: # context after
545 $expected = $expected_all_tokens . $expected_tail;
547 is(parser_calls($config),
549 'error message (0+1 context) ok');
551 ################################################################################
552 # Error message with 0+2 lines of context
553 ################################################################################
561 $expected_tail = <<'EOT';
562 ERROR: CONFIG: (in file <stdin>)
563 ERROR: CONFIG: Line 1: unknown qux
564 ERROR: CONFIG: ^^^^^^^^^^^
565 ERROR: CONFIG: Line 2: # context after
566 ERROR: CONFIG: Line 3: # context 2 after
569 $expected = $expected_all_tokens . $expected_tail;
571 is(parser_calls($config),
573 'error message (0+2 context) ok');
575 ################################################################################
576 # Error message within mode blocks
577 ################################################################################
581 bindsym x resize shrink left
588 cfg_mode_binding(bindsym, (null), x, (null), resize shrink left)
589 ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', '}'
590 ERROR: CONFIG: (in file <stdin>)
591 ERROR: CONFIG: Line 1: mode "yo" {
592 ERROR: CONFIG: Line 2: bindsym x resize shrink left
593 ERROR: CONFIG: Line 3: unknown qux
594 ERROR: CONFIG: ^^^^^^^^^^^
595 ERROR: CONFIG: Line 4: }
598 is(parser_calls($config),
600 'error message (mode block) ok');
602 ################################################################################
603 # Error message within bar blocks
604 ################################################################################
614 cfg_bar_output(LVDS-1)
615 ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'i3bar_command', 'status_command', 'socket_path', 'mode', 'modifier', 'position', 'output', 'tray_output', 'font', 'workspace_buttons', 'verbose', 'colors', '}'
616 ERROR: CONFIG: (in file <stdin>)
617 ERROR: CONFIG: Line 1: bar {
618 ERROR: CONFIG: Line 2: output LVDS-1
619 ERROR: CONFIG: Line 3: unknown qux
620 ERROR: CONFIG: ^^^^^^^^^^^
621 ERROR: CONFIG: Line 4: }
625 is(parser_calls($config),
627 'error message (bar block) ok');