]> git.sur5r.net Git - i3/i3/blob - testcases/t/201-config-parser.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 201-config-parser.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
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.
20 #
21 use i3test i3_autostart => 0;
22 use IPC::Run qw(run);
23
24 sub parser_calls {
25     my ($command) = @_;
26
27     my $stdout;
28     run [ '../test.config_parser', $command ],
29         '>&-',
30         '2>', \$stdout;
31     # TODO: use a timeout, so that we can error out if it doesn’t terminate
32
33     # Filter out all debugging output.
34     my @lines = split("\n", $stdout);
35     @lines = grep { not /^# / } @lines;
36
37     # The criteria management calls are irrelevant and not what we want to test
38     # in the first place.
39     @lines = grep { !(/cfg_criteria_init/ || /cfg_criteria_pop_state/) } @lines;
40     return join("\n", @lines) . "\n";
41 }
42
43 my $config = <<'EOT';
44 mode "meh" {
45     bindsym Mod1 + Shift +   x resize grow
46     bindcode Mod1+44 resize shrink
47     bindsym --release Mod1+x exec foo
48 }
49 EOT
50
51 my $expected = <<'EOT';
52 cfg_enter_mode(meh)
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)
56 EOT
57
58 is(parser_calls($config),
59    $expected,
60    'single number (move workspace 3) ok');
61
62 ################################################################################
63 # exec and exec_always
64 ################################################################################
65
66 $config = <<'EOT';
67 exec geeqie
68 exec --no-startup-id /tmp/foo.sh
69 exec_always firefox
70 exec_always --no-startup-id /tmp/bar.sh
71 EOT
72
73 $expected = <<'EOT';
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)
78 EOT
79
80 is(parser_calls($config),
81    $expected,
82    'exec okay');
83
84 ################################################################################
85 # for_window
86 ################################################################################
87
88 $config = <<'EOT';
89 for_window [class="^Chrome"] floating enable
90 EOT
91
92 $expected = <<'EOT';
93 cfg_criteria_add(class, ^Chrome)
94 cfg_for_window(floating enable)
95 EOT
96
97 is(parser_calls($config),
98    $expected,
99    'for_window okay');
100
101 ################################################################################
102 # assign
103 ################################################################################
104
105 $config = <<'EOT';
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"
110 EOT
111
112 $expected = <<'EOT';
113 cfg_criteria_add(class, ^Chrome)
114 cfg_assign(4)
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)
121 EOT
122
123 is(parser_calls($config),
124    $expected,
125    'for_window okay');
126
127 ################################################################################
128 # floating_minimum_size / floating_maximum_size
129 ################################################################################
130
131 $config = <<'EOT';
132 floating_minimum_size 80x55
133 floating_minimum_size 80    x  55  
134 floating_maximum_size 73 x 10
135 EOT
136
137 $expected = <<'EOT';
138 cfg_floating_minimum_size(80, 55)
139 cfg_floating_minimum_size(80, 55)
140 cfg_floating_maximum_size(73, 10)
141 EOT
142
143 is(parser_calls($config),
144    $expected,
145    'floating_minimum_size ok');
146
147 ################################################################################
148 # floating_modifier
149 ################################################################################
150
151 $config = <<'EOT';
152 floating_modifier Mod1
153 floating_modifier mOd1
154 EOT
155
156 $expected = <<'EOT';
157 cfg_floating_modifier(Mod1)
158 cfg_floating_modifier(Mod1)
159 EOT
160
161 is(parser_calls($config),
162    $expected,
163    'floating_modifier ok');
164
165 ################################################################################
166 # default_orientation
167 ################################################################################
168
169 $config = <<'EOT';
170 default_orientation horizontal
171 default_orientation vertical
172 default_orientation auto
173 EOT
174
175 $expected = <<'EOT';
176 cfg_default_orientation(horizontal)
177 cfg_default_orientation(vertical)
178 cfg_default_orientation(auto)
179 EOT
180
181 is(parser_calls($config),
182    $expected,
183    'default_orientation ok');
184
185 ################################################################################
186 # workspace_layout
187 ################################################################################
188
189 $config = <<'EOT';
190 workspace_layout default
191 workspace_layout stacked
192 workspace_layout stacking
193 workspace_layout tabbed
194 EOT
195
196 $expected = <<'EOT';
197 cfg_workspace_layout(default)
198 cfg_workspace_layout(stacked)
199 cfg_workspace_layout(stacking)
200 cfg_workspace_layout(tabbed)
201 EOT
202
203 is(parser_calls($config),
204    $expected,
205    'workspace_layout ok');
206
207 ################################################################################
208 # new_window
209 ################################################################################
210
211 $config = <<'EOT';
212 new_window 1pixel
213 new_window normal
214 new_window none
215 new_float 1pixel
216 new_float normal
217 new_float none
218 EOT
219
220 $expected = <<'EOT';
221 cfg_new_window(new_window, 1pixel, -1)
222 cfg_new_window(new_window, normal, 2)
223 cfg_new_window(new_window, none, -1)
224 cfg_new_window(new_float, 1pixel, -1)
225 cfg_new_window(new_float, normal, 2)
226 cfg_new_window(new_float, none, -1)
227 EOT
228
229 is(parser_calls($config),
230    $expected,
231    'new_window ok');
232
233 ################################################################################
234 # hide_edge_borders
235 ################################################################################
236
237 $config = <<'EOT';
238 hide_edge_borders none
239 hide_edge_borders vertical
240 hide_edge_borders horizontal
241 hide_edge_borders both
242 EOT
243
244 $expected = <<'EOT';
245 cfg_hide_edge_borders(none)
246 cfg_hide_edge_borders(vertical)
247 cfg_hide_edge_borders(horizontal)
248 cfg_hide_edge_borders(both)
249 EOT
250
251 is(parser_calls($config),
252    $expected,
253    'hide_edge_borders ok');
254
255 ################################################################################
256 # focus_follows_mouse
257 ################################################################################
258
259 $config = <<'EOT';
260 focus_follows_mouse yes
261 focus_follows_mouse no
262 EOT
263
264 $expected = <<'EOT';
265 cfg_focus_follows_mouse(yes)
266 cfg_focus_follows_mouse(no)
267 EOT
268
269 is(parser_calls($config),
270    $expected,
271    'focus_follows_mouse ok');
272
273 ################################################################################
274 # force_display_urgency_hint
275 ################################################################################
276
277 is(parser_calls('force_display_urgency_hint 300'),
278    "cfg_force_display_urgency_hint(300)\n",
279    'force_display_urgency_hint ok');
280
281 is(parser_calls('force_display_urgency_hint 500 ms'),
282    "cfg_force_display_urgency_hint(500)\n",
283    'force_display_urgency_hint ok');
284
285 is(parser_calls('force_display_urgency_hint 700ms'),
286    "cfg_force_display_urgency_hint(700)\n",
287    'force_display_urgency_hint ok');
288
289 $config = <<'EOT';
290 force_display_urgency_hint 300
291 force_display_urgency_hint 500 ms
292 force_display_urgency_hint 700ms
293 force_display_urgency_hint 700
294 EOT
295
296 $expected = <<'EOT';
297 cfg_force_display_urgency_hint(300)
298 cfg_force_display_urgency_hint(500)
299 cfg_force_display_urgency_hint(700)
300 cfg_force_display_urgency_hint(700)
301 EOT
302
303 is(parser_calls($config),
304    $expected,
305    'force_display_urgency_hint ok');
306
307 ################################################################################
308 # workspace
309 ################################################################################
310
311 $config = <<'EOT';
312 workspace 3 output VGA-1
313 workspace "4: output" output VGA-2
314 workspace bleh output LVDS1/I_1
315 EOT
316
317 $expected = <<'EOT';
318 cfg_workspace(3, VGA-1)
319 cfg_workspace(4: output, VGA-2)
320 cfg_workspace(bleh, LVDS1/I_1)
321 EOT
322
323 is(parser_calls($config),
324    $expected,
325    'workspace ok');
326
327 ################################################################################
328 # ipc-socket
329 ################################################################################
330
331 $config = <<'EOT';
332 ipc-socket /tmp/i3.sock
333 ipc_socket ~/.i3/i3.sock
334 EOT
335
336 $expected = <<'EOT';
337 cfg_ipc_socket(/tmp/i3.sock)
338 cfg_ipc_socket(~/.i3/i3.sock)
339 EOT
340
341 is(parser_calls($config),
342    $expected,
343    'ipc-socket ok');
344
345 ################################################################################
346 # colors
347 ################################################################################
348
349 $config = <<'EOT';
350 client.focused          #4c7899 #285577 #ffffff #2e9ef4
351 client.focused_inactive #333333 #5f676a #ffffff #484e50
352 client.unfocused        #333333 #222222 #888888 #292d2e
353 client.urgent           #2f343a #900000 #ffffff #900000
354 EOT
355
356 $expected = <<'EOT';
357 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4)
358 cfg_color(client.focused_inactive, #333333, #5f676a, #ffffff, #484e50)
359 cfg_color(client.unfocused, #333333, #222222, #888888, #292d2e)
360 cfg_color(client.urgent, #2f343a, #900000, #ffffff, #900000)
361 EOT
362
363 is(parser_calls($config),
364    $expected,
365    'colors ok');
366
367 ################################################################################
368 # Verify that errors don’t harm subsequent valid statements
369 ################################################################################
370
371 $config = <<'EOT';
372 hide_edge_border both
373 client.focused          #4c7899 #285577 #ffffff #2e9ef4
374 EOT
375
376 $expected = <<'EOT';
377 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'
378 ERROR: CONFIG: (in file <stdin>)
379 ERROR: CONFIG: Line   1: hide_edge_border both
380 ERROR: CONFIG:           ^^^^^^^^^^^^^^^^^^^^^
381 ERROR: CONFIG: Line   2: client.focused          #4c7899 #285577 #ffffff #2e9ef4
382 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4)
383 EOT
384
385 is(parser_calls($config),
386    $expected,
387    'errors dont harm subsequent statements');
388
389 $config = <<'EOT';
390 hide_edge_borders FOOBAR
391 client.focused          #4c7899 #285577 #ffffff #2e9ef4
392 EOT
393
394 $expected = <<'EOT';
395 ERROR: CONFIG: Expected one of these tokens: 'none', 'vertical', 'horizontal', 'both', '1', 'yes', 'true', 'on', 'enable', 'active'
396 ERROR: CONFIG: (in file <stdin>)
397 ERROR: CONFIG: Line   1: hide_edge_borders FOOBAR
398 ERROR: CONFIG:                             ^^^^^^
399 ERROR: CONFIG: Line   2: client.focused          #4c7899 #285577 #ffffff #2e9ef4
400 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4)
401 EOT
402
403 is(parser_calls($config),
404    $expected,
405    'errors dont harm subsequent statements');
406
407
408 ################################################################################
409 # Error message with 2+2 lines of context
410 ################################################################################
411
412 $config = <<'EOT';
413 # i3 config file (v4)
414
415 font foobar
416
417 unknown qux
418
419 # yay
420 # this should not show up
421 EOT
422
423 $expected = <<'EOT';
424 cfg_font(foobar)
425 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'
426 ERROR: CONFIG: (in file <stdin>)
427 ERROR: CONFIG: Line   3: font foobar
428 ERROR: CONFIG: Line   4: 
429 ERROR: CONFIG: Line   5: unknown qux
430 ERROR: CONFIG:           ^^^^^^^^^^^
431 ERROR: CONFIG: Line   6: 
432 ERROR: CONFIG: Line   7: # yay
433 EOT
434
435 is(parser_calls($config),
436    $expected,
437    'error message (2+2 context) ok');
438
439 ################################################################################
440 # Error message with 0+0 lines of context
441 ################################################################################
442
443 $config = <<'EOT';
444 unknown qux
445 EOT
446
447 $expected = <<'EOT';
448 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'
449 ERROR: CONFIG: (in file <stdin>)
450 ERROR: CONFIG: Line   1: unknown qux
451 ERROR: CONFIG:           ^^^^^^^^^^^
452 EOT
453
454 is(parser_calls($config),
455    $expected,
456    'error message (0+0 context) ok');
457
458 ################################################################################
459 # Error message with 1+0 lines of context
460 ################################################################################
461
462 $config = <<'EOT';
463 # context before
464 unknown qux
465 EOT
466
467 $expected = <<'EOT';
468 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'
469 ERROR: CONFIG: (in file <stdin>)
470 ERROR: CONFIG: Line   1: # context before
471 ERROR: CONFIG: Line   2: unknown qux
472 ERROR: CONFIG:           ^^^^^^^^^^^
473 EOT
474
475 is(parser_calls($config),
476    $expected,
477    'error message (1+0 context) ok');
478
479 ################################################################################
480 # Error message with 0+1 lines of context
481 ################################################################################
482
483 $config = <<'EOT';
484 unknown qux
485 # context after
486 EOT
487
488 $expected = <<'EOT';
489 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'
490 ERROR: CONFIG: (in file <stdin>)
491 ERROR: CONFIG: Line   1: unknown qux
492 ERROR: CONFIG:           ^^^^^^^^^^^
493 ERROR: CONFIG: Line   2: # context after
494 EOT
495
496 is(parser_calls($config),
497    $expected,
498    'error message (0+1 context) ok');
499
500 ################################################################################
501 # Error message with 0+2 lines of context
502 ################################################################################
503
504 $config = <<'EOT';
505 unknown qux
506 # context after
507 # context 2 after
508 EOT
509
510 $expected = <<'EOT';
511 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'
512 ERROR: CONFIG: (in file <stdin>)
513 ERROR: CONFIG: Line   1: unknown qux
514 ERROR: CONFIG:           ^^^^^^^^^^^
515 ERROR: CONFIG: Line   2: # context after
516 ERROR: CONFIG: Line   3: # context 2 after
517 EOT
518
519 is(parser_calls($config),
520    $expected,
521    'error message (0+2 context) ok');
522
523 ################################################################################
524 # Error message within mode blocks
525 ################################################################################
526
527 $config = <<'EOT';
528 mode "yo" {
529     bindsym x resize shrink left
530     unknown qux
531 }
532 EOT
533
534 $expected = <<'EOT';
535 cfg_enter_mode(yo)
536 cfg_mode_binding(bindsym, (null), x, (null), resize shrink left)
537 ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', '}'
538 ERROR: CONFIG: (in file <stdin>)
539 ERROR: CONFIG: Line   1: mode "yo" {
540 ERROR: CONFIG: Line   2:     bindsym x resize shrink left
541 ERROR: CONFIG: Line   3:     unknown qux
542 ERROR: CONFIG:               ^^^^^^^^^^^
543 ERROR: CONFIG: Line   4: }
544 EOT
545
546 is(parser_calls($config),
547    $expected,
548    'error message (mode block) ok');
549
550 ################################################################################
551 # Error message within bar blocks
552 ################################################################################
553
554 $config = <<'EOT';
555 bar {
556     output LVDS-1
557     unknown qux
558 }
559 EOT
560
561 $expected = <<'EOT';
562 cfg_bar_output(LVDS-1)
563 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', '}'
564 ERROR: CONFIG: (in file <stdin>)
565 ERROR: CONFIG: Line   1: bar {
566 ERROR: CONFIG: Line   2:     output LVDS-1
567 ERROR: CONFIG: Line   3:     unknown qux
568 ERROR: CONFIG:               ^^^^^^^^^^^
569 ERROR: CONFIG: Line   4: }
570 cfg_bar_finish()
571 EOT
572
573 is(parser_calls($config),
574    $expected,
575    'error message (bar block) ok');
576
577 done_testing;