]> git.sur5r.net Git - i3/i3/blob - testcases/t/201-config-parser.t
introduced i3 command for changing the hidden state and the mode of i3bar
[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         '>/dev/null',
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 # popup_during_fullscreen
149 ################################################################################
150
151 $config = <<'EOT';
152 popup_during_fullscreen ignore
153 popup_during_fullscreen leave_fullscreen
154 popup_during_fullscreen SMArt
155 EOT
156
157 $expected = <<'EOT';
158 cfg_popup_during_fullscreen(ignore)
159 cfg_popup_during_fullscreen(leave_fullscreen)
160 cfg_popup_during_fullscreen(smart)
161 EOT
162
163 is(parser_calls($config),
164    $expected,
165    'popup_during_fullscreen ok');
166
167
168 ################################################################################
169 # floating_modifier
170 ################################################################################
171
172 $config = <<'EOT';
173 floating_modifier Mod1
174 floating_modifier mOd1
175 EOT
176
177 $expected = <<'EOT';
178 cfg_floating_modifier(Mod1)
179 cfg_floating_modifier(Mod1)
180 EOT
181
182 is(parser_calls($config),
183    $expected,
184    'floating_modifier ok');
185
186 ################################################################################
187 # default_orientation
188 ################################################################################
189
190 $config = <<'EOT';
191 default_orientation horizontal
192 default_orientation vertical
193 default_orientation auto
194 EOT
195
196 $expected = <<'EOT';
197 cfg_default_orientation(horizontal)
198 cfg_default_orientation(vertical)
199 cfg_default_orientation(auto)
200 EOT
201
202 is(parser_calls($config),
203    $expected,
204    'default_orientation ok');
205
206 ################################################################################
207 # workspace_layout
208 ################################################################################
209
210 $config = <<'EOT';
211 workspace_layout default
212 workspace_layout stacked
213 workspace_layout stacking
214 workspace_layout tabbed
215 EOT
216
217 $expected = <<'EOT';
218 cfg_workspace_layout(default)
219 cfg_workspace_layout(stacked)
220 cfg_workspace_layout(stacking)
221 cfg_workspace_layout(tabbed)
222 EOT
223
224 is(parser_calls($config),
225    $expected,
226    'workspace_layout ok');
227
228 ################################################################################
229 # workspace assignments, with trailing whitespace (ticket #921)
230 ################################################################################
231
232 $config = <<'EOT';
233 workspace "3" output DP-1 
234 workspace "3" output            VGA-1   
235 EOT
236
237 $expected = <<'EOT';
238 cfg_workspace(3, DP-1)
239 cfg_workspace(3, VGA-1)
240 EOT
241
242 is(parser_calls($config),
243    $expected,
244    'workspace assignment ok');
245
246 ################################################################################
247 # new_window
248 ################################################################################
249
250 $config = <<'EOT';
251 new_window 1pixel
252 new_window normal
253 new_window none
254 new_float 1pixel
255 new_float normal
256 new_float none
257 EOT
258
259 $expected = <<'EOT';
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)
266 EOT
267
268 is(parser_calls($config),
269    $expected,
270    'new_window ok');
271
272 ################################################################################
273 # hide_edge_borders
274 ################################################################################
275
276 $config = <<'EOT';
277 hide_edge_borders none
278 hide_edge_borders vertical
279 hide_edge_borders horizontal
280 hide_edge_borders both
281 EOT
282
283 $expected = <<'EOT';
284 cfg_hide_edge_borders(none)
285 cfg_hide_edge_borders(vertical)
286 cfg_hide_edge_borders(horizontal)
287 cfg_hide_edge_borders(both)
288 EOT
289
290 is(parser_calls($config),
291    $expected,
292    'hide_edge_borders ok');
293
294 ################################################################################
295 # focus_follows_mouse
296 ################################################################################
297
298 $config = <<'EOT';
299 focus_follows_mouse yes
300 focus_follows_mouse no
301 EOT
302
303 $expected = <<'EOT';
304 cfg_focus_follows_mouse(yes)
305 cfg_focus_follows_mouse(no)
306 EOT
307
308 is(parser_calls($config),
309    $expected,
310    'focus_follows_mouse ok');
311
312 ################################################################################
313 # force_display_urgency_hint
314 ################################################################################
315
316 is(parser_calls('force_display_urgency_hint 300'),
317    "cfg_force_display_urgency_hint(300)\n",
318    'force_display_urgency_hint ok');
319
320 is(parser_calls('force_display_urgency_hint 500 ms'),
321    "cfg_force_display_urgency_hint(500)\n",
322    'force_display_urgency_hint ok');
323
324 is(parser_calls('force_display_urgency_hint 700ms'),
325    "cfg_force_display_urgency_hint(700)\n",
326    'force_display_urgency_hint ok');
327
328 $config = <<'EOT';
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
333 EOT
334
335 $expected = <<'EOT';
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)
340 EOT
341
342 is(parser_calls($config),
343    $expected,
344    'force_display_urgency_hint ok');
345
346 ################################################################################
347 # workspace
348 ################################################################################
349
350 $config = <<'EOT';
351 workspace 3 output VGA-1
352 workspace "4: output" output VGA-2
353 workspace bleh output LVDS1/I_1
354 EOT
355
356 $expected = <<'EOT';
357 cfg_workspace(3, VGA-1)
358 cfg_workspace(4: output, VGA-2)
359 cfg_workspace(bleh, LVDS1/I_1)
360 EOT
361
362 is(parser_calls($config),
363    $expected,
364    'workspace ok');
365
366 ################################################################################
367 # ipc-socket
368 ################################################################################
369
370 $config = <<'EOT';
371 ipc-socket /tmp/i3.sock
372 ipc_socket ~/.i3/i3.sock
373 EOT
374
375 $expected = <<'EOT';
376 cfg_ipc_socket(/tmp/i3.sock)
377 cfg_ipc_socket(~/.i3/i3.sock)
378 EOT
379
380 is(parser_calls($config),
381    $expected,
382    'ipc-socket ok');
383
384 ################################################################################
385 # colors
386 ################################################################################
387
388 $config = <<'EOT';
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
393 EOT
394
395 $expected = <<'EOT';
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)
400 EOT
401
402 is(parser_calls($config),
403    $expected,
404    'colors ok');
405
406 ################################################################################
407 # Verify that errors don’t harm subsequent valid statements
408 ################################################################################
409
410 $config = <<'EOT';
411 hide_edge_border both
412 client.focused          #4c7899 #285577 #ffffff #2e9ef4
413 EOT
414
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'
417 EOT
418
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)
425 EOT
426
427 $expected = $expected_all_tokens . $expected_end;
428
429 is(parser_calls($config),
430    $expected,
431    'errors dont harm subsequent statements');
432
433 $config = <<'EOT';
434 hide_edge_borders FOOBAR
435 client.focused          #4c7899 #285577 #ffffff #2e9ef4
436 EOT
437
438 $expected = <<'EOT';
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)
445 EOT
446
447 is(parser_calls($config),
448    $expected,
449    'errors dont harm subsequent statements');
450
451 ################################################################################
452 # Regression: semicolons end comments, but shouldn’t
453 ################################################################################
454
455 $config = <<'EOT';
456 # "foo" client.focused          #4c7899 #285577 #ffffff #2e9ef4
457 EOT
458
459 $expected = <<'EOT';
460
461 EOT
462
463 is(parser_calls($config),
464    $expected,
465    'semicolon does not end a comment line');
466
467 ################################################################################
468 # Error message with 2+2 lines of context
469 ################################################################################
470
471 $config = <<'EOT';
472 # i3 config file (v4)
473
474 font foobar
475
476 unknown qux
477
478 # yay
479 # this should not show up
480 EOT
481
482 my $expected_head = <<'EOT';
483 cfg_font(foobar)
484 EOT
485
486 my $expected_tail = <<'EOT';
487 ERROR: CONFIG: (in file <stdin>)
488 ERROR: CONFIG: Line   3: font foobar
489 ERROR: CONFIG: Line   4: 
490 ERROR: CONFIG: Line   5: unknown qux
491 ERROR: CONFIG:           ^^^^^^^^^^^
492 ERROR: CONFIG: Line   6: 
493 ERROR: CONFIG: Line   7: # yay
494 EOT
495
496 $expected = $expected_head . $expected_all_tokens . $expected_tail;
497
498 is(parser_calls($config),
499    $expected,
500    'error message (2+2 context) ok');
501
502 ################################################################################
503 # Error message with 0+0 lines of context
504 ################################################################################
505
506 $config = <<'EOT';
507 unknown qux
508 EOT
509
510 $expected_tail = <<'EOT';
511 ERROR: CONFIG: (in file <stdin>)
512 ERROR: CONFIG: Line   1: unknown qux
513 ERROR: CONFIG:           ^^^^^^^^^^^
514 EOT
515
516 $expected = $expected_all_tokens . $expected_tail;
517
518 is(parser_calls($config),
519    $expected,
520    'error message (0+0 context) ok');
521
522 ################################################################################
523 # Error message with 1+0 lines of context
524 ################################################################################
525
526 $config = <<'EOT';
527 # context before
528 unknown qux
529 EOT
530
531 $expected_tail = <<'EOT';
532 ERROR: CONFIG: (in file <stdin>)
533 ERROR: CONFIG: Line   1: # context before
534 ERROR: CONFIG: Line   2: unknown qux
535 ERROR: CONFIG:           ^^^^^^^^^^^
536 EOT
537
538 $expected = $expected_all_tokens . $expected_tail;
539
540 is(parser_calls($config),
541    $expected,
542    'error message (1+0 context) ok');
543
544 ################################################################################
545 # Error message with 0+1 lines of context
546 ################################################################################
547
548 $config = <<'EOT';
549 unknown qux
550 # context after
551 EOT
552
553 $expected_tail = <<'EOT';
554 ERROR: CONFIG: (in file <stdin>)
555 ERROR: CONFIG: Line   1: unknown qux
556 ERROR: CONFIG:           ^^^^^^^^^^^
557 ERROR: CONFIG: Line   2: # context after
558 EOT
559
560 $expected = $expected_all_tokens . $expected_tail;
561
562 is(parser_calls($config),
563    $expected,
564    'error message (0+1 context) ok');
565
566 ################################################################################
567 # Error message with 0+2 lines of context
568 ################################################################################
569
570 $config = <<'EOT';
571 unknown qux
572 # context after
573 # context 2 after
574 EOT
575
576 $expected_tail = <<'EOT';
577 ERROR: CONFIG: (in file <stdin>)
578 ERROR: CONFIG: Line   1: unknown qux
579 ERROR: CONFIG:           ^^^^^^^^^^^
580 ERROR: CONFIG: Line   2: # context after
581 ERROR: CONFIG: Line   3: # context 2 after
582 EOT
583
584 $expected = $expected_all_tokens . $expected_tail;
585
586 is(parser_calls($config),
587    $expected,
588    'error message (0+2 context) ok');
589
590 ################################################################################
591 # Error message within mode blocks
592 ################################################################################
593
594 $config = <<'EOT';
595 mode "yo" {
596     bindsym x resize shrink left
597     unknown qux
598 }
599 EOT
600
601 $expected = <<'EOT';
602 cfg_enter_mode(yo)
603 cfg_mode_binding(bindsym, (null), x, (null), resize shrink left)
604 ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', '}'
605 ERROR: CONFIG: (in file <stdin>)
606 ERROR: CONFIG: Line   1: mode "yo" {
607 ERROR: CONFIG: Line   2:     bindsym x resize shrink left
608 ERROR: CONFIG: Line   3:     unknown qux
609 ERROR: CONFIG:               ^^^^^^^^^^^
610 ERROR: CONFIG: Line   4: }
611 EOT
612
613 is(parser_calls($config),
614    $expected,
615    'error message (mode block) ok');
616
617 ################################################################################
618 # Error message within bar blocks
619 ################################################################################
620
621 $config = <<'EOT';
622 bar {
623     output LVDS-1
624     unknown qux
625 }
626 EOT
627
628 $expected = <<'EOT';
629 cfg_bar_output(LVDS-1)
630 ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'i3bar_command', 'status_command', 'socket_path', 'mode', 'hidden_state', 'id', 'modifier', 'position', 'output', 'tray_output', 'font', 'workspace_buttons', 'verbose', 'colors', '}'
631 ERROR: CONFIG: (in file <stdin>)
632 ERROR: CONFIG: Line   1: bar {
633 ERROR: CONFIG: Line   2:     output LVDS-1
634 ERROR: CONFIG: Line   3:     unknown qux
635 ERROR: CONFIG:               ^^^^^^^^^^^
636 ERROR: CONFIG: Line   4: }
637 cfg_bar_finish()
638 EOT
639
640 is(parser_calls($config),
641    $expected,
642    'error message (bar block) ok');
643
644 done_testing;