]> 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 }
48 EOT
49
50 my $expected = <<'EOT';
51 cfg_enter_mode(meh)
52 cfg_mode_binding(bindsym, Mod1,Shift, x, (null), resize grow)
53 cfg_mode_binding(bindcode, Mod1, 44, (null), resize shrink)
54 EOT
55
56 is(parser_calls($config),
57    $expected,
58    'single number (move workspace 3) ok');
59
60 ################################################################################
61 # exec and exec_always
62 ################################################################################
63
64 $config = <<'EOT';
65 exec geeqie
66 exec --no-startup-id /tmp/foo.sh
67 exec_always firefox
68 exec_always --no-startup-id /tmp/bar.sh
69 EOT
70
71 $expected = <<'EOT';
72 cfg_exec(exec, (null), geeqie)
73 cfg_exec(exec, --no-startup-id, /tmp/foo.sh)
74 cfg_exec(exec_always, (null), firefox)
75 cfg_exec(exec_always, --no-startup-id, /tmp/bar.sh)
76 EOT
77
78 is(parser_calls($config),
79    $expected,
80    'exec okay');
81
82 ################################################################################
83 # for_window
84 ################################################################################
85
86 $config = <<'EOT';
87 for_window [class="^Chrome"] floating enable
88 EOT
89
90 $expected = <<'EOT';
91 cfg_criteria_add(class, ^Chrome)
92 cfg_for_window(floating enable)
93 EOT
94
95 is(parser_calls($config),
96    $expected,
97    'for_window okay');
98
99 ################################################################################
100 # assign
101 ################################################################################
102
103 $config = <<'EOT';
104 assign [class="^Chrome"] 4
105 assign [class="^Chrome"] named workspace
106 assign [class="^Chrome"] "quoted named workspace"
107 assign [class="^Chrome"] → "quoted named workspace"
108 EOT
109
110 $expected = <<'EOT';
111 cfg_criteria_add(class, ^Chrome)
112 cfg_assign(4)
113 cfg_criteria_add(class, ^Chrome)
114 cfg_assign(named workspace)
115 cfg_criteria_add(class, ^Chrome)
116 cfg_assign(quoted named workspace)
117 cfg_criteria_add(class, ^Chrome)
118 cfg_assign(quoted named workspace)
119 EOT
120
121 is(parser_calls($config),
122    $expected,
123    'for_window okay');
124
125 ################################################################################
126 # floating_minimum_size / floating_maximum_size
127 ################################################################################
128
129 $config = <<'EOT';
130 floating_minimum_size 80x55
131 floating_minimum_size 80    x  55  
132 floating_maximum_size 73 x 10
133 EOT
134
135 $expected = <<'EOT';
136 cfg_floating_minimum_size(80, 55)
137 cfg_floating_minimum_size(80, 55)
138 cfg_floating_maximum_size(73, 10)
139 EOT
140
141 is(parser_calls($config),
142    $expected,
143    'floating_minimum_size ok');
144
145 ################################################################################
146 # floating_modifier
147 ################################################################################
148
149 $config = <<'EOT';
150 floating_modifier Mod1
151 floating_modifier mOd1
152 EOT
153
154 $expected = <<'EOT';
155 cfg_floating_modifier(Mod1)
156 cfg_floating_modifier(Mod1)
157 EOT
158
159 is(parser_calls($config),
160    $expected,
161    'floating_modifier ok');
162
163 ################################################################################
164 # default_orientation
165 ################################################################################
166
167 $config = <<'EOT';
168 default_orientation horizontal
169 default_orientation vertical
170 default_orientation auto
171 EOT
172
173 $expected = <<'EOT';
174 cfg_default_orientation(horizontal)
175 cfg_default_orientation(vertical)
176 cfg_default_orientation(auto)
177 EOT
178
179 is(parser_calls($config),
180    $expected,
181    'default_orientation ok');
182
183 ################################################################################
184 # workspace_layout
185 ################################################################################
186
187 $config = <<'EOT';
188 workspace_layout default
189 workspace_layout stacked
190 workspace_layout stacking
191 workspace_layout tabbed
192 EOT
193
194 $expected = <<'EOT';
195 cfg_workspace_layout(default)
196 cfg_workspace_layout(stacked)
197 cfg_workspace_layout(stacking)
198 cfg_workspace_layout(tabbed)
199 EOT
200
201 is(parser_calls($config),
202    $expected,
203    'workspace_layout ok');
204
205 ################################################################################
206 # new_window
207 ################################################################################
208
209 $config = <<'EOT';
210 new_window 1pixel
211 new_window normal
212 new_window none
213 new_float 1pixel
214 new_float normal
215 new_float none
216 EOT
217
218 $expected = <<'EOT';
219 cfg_new_window(new_window, 1pixel, -1)
220 cfg_new_window(new_window, normal, 2)
221 cfg_new_window(new_window, none, -1)
222 cfg_new_window(new_float, 1pixel, -1)
223 cfg_new_window(new_float, normal, 2)
224 cfg_new_window(new_float, none, -1)
225 EOT
226
227 is(parser_calls($config),
228    $expected,
229    'new_window ok');
230
231 ################################################################################
232 # hide_edge_borders
233 ################################################################################
234
235 $config = <<'EOT';
236 hide_edge_borders none
237 hide_edge_borders vertical
238 hide_edge_borders horizontal
239 hide_edge_borders both
240 EOT
241
242 $expected = <<'EOT';
243 cfg_hide_edge_borders(none)
244 cfg_hide_edge_borders(vertical)
245 cfg_hide_edge_borders(horizontal)
246 cfg_hide_edge_borders(both)
247 EOT
248
249 is(parser_calls($config),
250    $expected,
251    'hide_edge_borders ok');
252
253 ################################################################################
254 # focus_follows_mouse
255 ################################################################################
256
257 $config = <<'EOT';
258 focus_follows_mouse yes
259 focus_follows_mouse no
260 EOT
261
262 $expected = <<'EOT';
263 cfg_focus_follows_mouse(yes)
264 cfg_focus_follows_mouse(no)
265 EOT
266
267 is(parser_calls($config),
268    $expected,
269    'focus_follows_mouse ok');
270
271 ################################################################################
272 # force_display_urgency_hint
273 ################################################################################
274
275 is(parser_calls('force_display_urgency_hint 300'),
276    "cfg_force_display_urgency_hint(300)\n",
277    'force_display_urgency_hint ok');
278
279 is(parser_calls('force_display_urgency_hint 500 ms'),
280    "cfg_force_display_urgency_hint(500)\n",
281    'force_display_urgency_hint ok');
282
283 is(parser_calls('force_display_urgency_hint 700ms'),
284    "cfg_force_display_urgency_hint(700)\n",
285    'force_display_urgency_hint ok');
286
287 $config = <<'EOT';
288 force_display_urgency_hint 300
289 force_display_urgency_hint 500 ms
290 force_display_urgency_hint 700ms
291 force_display_urgency_hint 700
292 EOT
293
294 $expected = <<'EOT';
295 cfg_force_display_urgency_hint(300)
296 cfg_force_display_urgency_hint(500)
297 cfg_force_display_urgency_hint(700)
298 cfg_force_display_urgency_hint(700)
299 EOT
300
301 is(parser_calls($config),
302    $expected,
303    'force_display_urgency_hint ok');
304
305 ################################################################################
306 # workspace
307 ################################################################################
308
309 $config = <<'EOT';
310 workspace 3 output VGA-1
311 workspace "4: output" output VGA-2
312 workspace bleh output LVDS1/I_1
313 EOT
314
315 $expected = <<'EOT';
316 cfg_workspace(3, VGA-1)
317 cfg_workspace(4: output, VGA-2)
318 cfg_workspace(bleh, LVDS1/I_1)
319 EOT
320
321 is(parser_calls($config),
322    $expected,
323    'workspace ok');
324
325 ################################################################################
326 # ipc-socket
327 ################################################################################
328
329 $config = <<'EOT';
330 ipc-socket /tmp/i3.sock
331 ipc_socket ~/.i3/i3.sock
332 EOT
333
334 $expected = <<'EOT';
335 cfg_ipc_socket(/tmp/i3.sock)
336 cfg_ipc_socket(~/.i3/i3.sock)
337 EOT
338
339 is(parser_calls($config),
340    $expected,
341    'ipc-socket ok');
342
343 ################################################################################
344 # colors
345 ################################################################################
346
347 $config = <<'EOT';
348 client.focused          #4c7899 #285577 #ffffff #2e9ef4
349 client.focused_inactive #333333 #5f676a #ffffff #484e50
350 client.unfocused        #333333 #222222 #888888 #292d2e
351 client.urgent           #2f343a #900000 #ffffff #900000
352 EOT
353
354 $expected = <<'EOT';
355 cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4)
356 cfg_color(client.focused_inactive, #333333, #5f676a, #ffffff, #484e50)
357 cfg_color(client.unfocused, #333333, #222222, #888888, #292d2e)
358 cfg_color(client.urgent, #2f343a, #900000, #ffffff, #900000)
359 EOT
360
361 is(parser_calls($config),
362    $expected,
363    'colors ok');
364
365 ################################################################################
366 # Error message with 2+2 lines of context
367 ################################################################################
368
369 $config = <<'EOT';
370 # i3 config file (v4)
371
372 font foobar
373
374 unknown qux
375
376 # yay
377 # this should not show up
378 EOT
379
380 $expected = <<'EOT';
381 cfg_font(foobar)
382 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'
383 ERROR: CONFIG: (in file <stdin>)
384 ERROR: CONFIG: Line   3: font foobar
385 ERROR: CONFIG: Line   4: 
386 ERROR: CONFIG: Line   5: unknown qux
387 ERROR: CONFIG:           ^^^^^^^^^^^
388 ERROR: CONFIG: Line   6: 
389 ERROR: CONFIG: Line   7: # yay
390 EOT
391
392 is(parser_calls($config),
393    $expected,
394    'error message (2+2 context) ok');
395
396 ################################################################################
397 # Error message with 0+0 lines of context
398 ################################################################################
399
400 $config = <<'EOT';
401 unknown qux
402 EOT
403
404 $expected = <<'EOT';
405 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'
406 ERROR: CONFIG: (in file <stdin>)
407 ERROR: CONFIG: Line   1: unknown qux
408 ERROR: CONFIG:           ^^^^^^^^^^^
409 EOT
410
411 is(parser_calls($config),
412    $expected,
413    'error message (0+0 context) ok');
414
415 ################################################################################
416 # Error message with 1+0 lines of context
417 ################################################################################
418
419 $config = <<'EOT';
420 # context before
421 unknown qux
422 EOT
423
424 $expected = <<'EOT';
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   1: # context before
428 ERROR: CONFIG: Line   2: unknown qux
429 ERROR: CONFIG:           ^^^^^^^^^^^
430 EOT
431
432 is(parser_calls($config),
433    $expected,
434    'error message (1+0 context) ok');
435
436 ################################################################################
437 # Error message with 0+1 lines of context
438 ################################################################################
439
440 $config = <<'EOT';
441 unknown qux
442 # context after
443 EOT
444
445 $expected = <<'EOT';
446 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'
447 ERROR: CONFIG: (in file <stdin>)
448 ERROR: CONFIG: Line   1: unknown qux
449 ERROR: CONFIG:           ^^^^^^^^^^^
450 ERROR: CONFIG: Line   2: # context after
451 EOT
452
453 is(parser_calls($config),
454    $expected,
455    'error message (0+1 context) ok');
456
457 ################################################################################
458 # Error message with 0+2 lines of context
459 ################################################################################
460
461 $config = <<'EOT';
462 unknown qux
463 # context after
464 # context 2 after
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: unknown qux
471 ERROR: CONFIG:           ^^^^^^^^^^^
472 ERROR: CONFIG: Line   2: # context after
473 ERROR: CONFIG: Line   3: # context 2 after
474 EOT
475
476 is(parser_calls($config),
477    $expected,
478    'error message (0+2 context) ok');
479
480 ################################################################################
481 # Error message within mode blocks
482 ################################################################################
483
484 $config = <<'EOT';
485 mode "yo" {
486     bindsym x resize shrink left
487     unknown qux
488 }
489 EOT
490
491 $expected = <<'EOT';
492 cfg_enter_mode(yo)
493 cfg_mode_binding(bindsym, (null), x, (null), resize shrink left)
494 ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', '}'
495 ERROR: CONFIG: (in file <stdin>)
496 ERROR: CONFIG: Line   1: mode "yo" {
497 ERROR: CONFIG: Line   2:     bindsym x resize shrink left
498 ERROR: CONFIG: Line   3:     unknown qux
499 ERROR: CONFIG:               ^^^^^^^^^^^
500 ERROR: CONFIG: Line   4: }
501 EOT
502
503 is(parser_calls($config),
504    $expected,
505    'error message (mode block) ok');
506
507 ################################################################################
508 # Error message within bar blocks
509 ################################################################################
510
511 $config = <<'EOT';
512 bar {
513     output LVDS-1
514     unknown qux
515 }
516 EOT
517
518 $expected = <<'EOT';
519 cfg_bar_output(LVDS-1)
520 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', '}'
521 ERROR: CONFIG: (in file <stdin>)
522 ERROR: CONFIG: Line   1: bar {
523 ERROR: CONFIG: Line   2:     output LVDS-1
524 ERROR: CONFIG: Line   3:     unknown qux
525 ERROR: CONFIG:               ^^^^^^^^^^^
526 ERROR: CONFIG: Line   4: }
527 EOT
528
529 is(parser_calls($config),
530    $expected,
531    'error message (bar block) ok');
532
533 done_testing;