]> git.sur5r.net Git - i3/i3/blob - testcases/t/171-config-migrate.t
Added missing bar section for tray_output primary
[i3/i3] / testcases / t / 171-config-migrate.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 if i3-migrate-config-to-v4 correctly migrates all config file
18 # directives and commands
19 #
20 use i3test i3_autostart => 0;
21 use Cwd qw(abs_path);
22 use File::Temp qw(tempfile tempdir);
23 use v5.10;
24
25 # reads in a whole file
26 sub slurp {
27     open my $fh, '<', shift;
28     local $/;
29     <$fh>;
30 }
31
32 sub migrate_config {
33     my ($config) = @_;
34
35     my ($fh, $tmpfile) = tempfile('/tmp/i3-migrate-cfg.XXXXXX', UNLINK => 1);
36     print $fh $config;
37     close($fh);
38
39     my $cmd = "sh -c 'exec " . abs_path("../i3-migrate-config-to-v4") . " --v3 <$tmpfile'";
40     return [ split /\n/, qx($cmd) ];
41 }
42
43 sub line_exists {
44     my ($lines, $pattern) = @_;
45
46     for my $line (@$lines) {
47         return 1 if $line =~ $pattern;
48     }
49
50     return 0
51 }
52
53 #####################################################################
54 # check that some directives remain untouched
55 #####################################################################
56
57 my $input = <<EOT;
58     font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
59 EOT
60
61 my $output = migrate_config($input);
62 ok(line_exists($output, qr|font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1|), 'font directive unchanged');
63
64 $input = <<EOT;
65     floating_Modifier Mod1
66     focus_follows_mouse true
67     ipc-socket /tmp/i3-ipc.sock
68     ipc_socket /tmp/i3-ipc.sock
69     exec /usr/bin/i3
70     set stuff Mod1
71     assign "XTerm" → 3
72     assign "XTerm" → ~5
73     client.focused #2F343A #900000 #FFFFFF
74     client.focused_inactive #FF0000 #FF0000 #FF0000
75     client.unfocused #00FF00 #00FF00 #00FF00
76     client.urgent #0000FF #0000FF #0000FF
77     client.background #000000
78 EOT
79
80 $output = migrate_config($input);
81 ok(line_exists($output, qr|^floating_Modifier Mod1$|), 'floating_modifier unchanged');
82 ok(line_exists($output, qr|^focus_follows_mouse true$|), 'focus_follows_mouse unchanged');
83 ok(line_exists($output, qr|^ipc-socket /tmp/i3-ipc.sock$|), 'ipc-socket unchanged');
84 ok(line_exists($output, qr|^ipc_socket /tmp/i3-ipc.sock$|), 'ipc_socket unchanged');
85 ok(line_exists($output, qr|^exec /usr/bin/i3|), 'exec unchanged');
86 ok(line_exists($output, qr|^set stuff Mod1|), 'set unchanged');
87 ok(line_exists($output, qr|^assign "XTerm" → 3|), 'assign unchanged');
88 ok(line_exists($output, qr|^assign "XTerm" → ~5|), 'assign unchanged');
89 ok(line_exists($output, qr|^client\.focused #2F343A #900000 #FFFFFF$|), 'client.focused unchanged');
90 ok(line_exists($output, qr|^client\.focused_inactive #FF0000 #FF0000 #FF0000$|), 'client.focused_inactive unchanged');
91 ok(line_exists($output, qr|^client\.unfocused #00FF00 #00FF00 #00FF00$|), 'client.unfocused unchanged');
92 ok(line_exists($output, qr|^client\.urgent #0000FF #0000FF #0000FF$|), 'client.urgent unchanged');
93 ok(line_exists($output, qr|^client\.background #000000$|), 'client.background unchanged');
94
95 #####################################################################
96 # check whether the bar colors get removed properly
97 #####################################################################
98
99 $input = <<EOT;
100     bar.focused #FFFF00 #FFFF00 #FFFF00
101     bar.unfocused #FFFF00 #FFFF00 #FFFF00
102     bar.urgent #FFFF00 #FFFF00 #FFFF00
103 EOT
104
105 $output = migrate_config($input);
106 ok(!line_exists($output, qr|^bar\.|), 'no bar. lines');
107 ok(line_exists($output, qr|^#.*REMOVED bar|), 'note bar. removed');
108
109
110 #####################################################################
111 # check whether the other directives get converted correctly
112 #####################################################################
113
114 $input = <<EOT;
115     new_container stacking
116     workspace_bar no
117     new_window bb
118 EOT
119
120 $output = migrate_config($input);
121 ok(line_exists($output, qr|^workspace_layout stacking$|), 'new_container changed');
122 ok(line_exists($output, qr|REMOVED workspace_bar|), 'workspace_bar removed');
123 ok(!line_exists($output, qr|^workspace_bar|), 'no workspace_bar in the output');
124 ok(line_exists($output, qr|^new_window none$|), 'new_window changed');
125
126 #####################################################################
127 # check whether new_window's parameters get changed correctly
128 #####################################################################
129
130 $input = <<EOT;
131     new_window bb
132     new_window bn
133     new_window bp
134 EOT
135 $output = migrate_config($input);
136 like($output->[0], qr|^new_window none$|, 'new_window bb changed');
137 like($output->[1], qr|^new_window normal$|, 'new_window bn changed');
138 like($output->[2], qr|^new_window 1pixel$|, 'new_window bp changed');
139
140 #####################################################################
141 # check that some commands remain untouched
142 #####################################################################
143
144 $input = <<EOT;
145     bindsym Mod1+s exec /usr/bin/urxvt
146     bindsym Mod1+s mark foo
147     bindsym Mod1+s restart
148     bindsym Mod1+s reload
149     bindsym Mod1+s exit
150     bindsym Mod1+s stack-limit cols 2
151     bindsym Mod1+s stack-limit rows 3
152     bind Mod1+c exec /usr/bin/urxvt
153     mode "asdf" {
154         bind 36 mode default
155     }
156 EOT
157
158 $output = migrate_config($input);
159 ok(line_exists($output, qr|^bindsym Mod1\+s exec /usr/bin/urxvt$|), 'exec unchanged');
160 ok(line_exists($output, qr|^bindsym Mod1\+s mark foo$|), 'mark unchanged');
161 ok(line_exists($output, qr|^bindsym Mod1\+s restart$|), 'restart unchanged');
162 ok(line_exists($output, qr|^bindsym Mod1\+s reload$|), 'reload unchanged');
163 ok(line_exists($output, qr|^bindsym Mod1\+s exit$|), 'exit unchanged');
164 ok(line_exists($output, qr|^bindsym Mod1\+s stack-limit cols 2$|), 'stack-limit unchanged');
165 ok(line_exists($output, qr|^bindsym Mod1\+s stack-limit rows 3$|), 'stack-limit unchanged');
166 ok(line_exists($output, qr|^bindcode Mod1\+c exec /usr/bin/urxvt$|), 'bind changed to bindcode');
167 ok(line_exists($output, qr|^mode "asdf" {$|), 'mode asdf unchanged');
168 ok(line_exists($output, qr|^bindcode 36 mode \"default\"$|), 'mode default unchanged');
169 ok(line_exists($output, qr|^}$|), 'closing mode bracket still there');
170
171 #####################################################################
172 # check the simple command replacements
173 #####################################################################
174
175 $input = <<EOT;
176     bindsym Mod1+s s
177     bindsym Mod1+s d
178     bindsym Mod1+s T
179
180     bindsym Mod1+s f
181     bindsym Mod1+s fg
182
183     bindsym Mod1+s t
184
185     bindsym Mod1+s h
186     bindsym Mod1+s j
187     bindsym Mod1+s k
188     bindsym Mod1+s l
189
190     bindsym Mod1+s mh
191     bindsym Mod1+s mj
192     bindsym Mod1+s mk
193     bindsym Mod1+s ml
194
195     bindsym Mod1+s bn
196     bindsym Mod1+s bp
197     bindsym Mod1+s bb
198     bindsym Mod1+s bt
199
200     bindsym Mod1+j wch
201     bindsym Mod1+j wcml
202
203     bindsym Mod1+k kill
204
205     bindsym Mod1+n nw
206     bindsym Mod1+p pw
207 EOT
208
209 $output = migrate_config($input);
210 ok(line_exists($output, qr|^bindsym Mod1\+s layout stacking$|), 's replaced');
211 ok(line_exists($output, qr|^bindsym Mod1\+s layout toggle split$|), 'd replaced');
212 ok(line_exists($output, qr|^bindsym Mod1\+s layout tabbed$|), 'T replaced');
213 ok(line_exists($output, qr|^bindsym Mod1\+s fullscreen$|), 'f replaced');
214 ok(line_exists($output, qr|^bindsym Mod1\+s fullscreen global$|), 'fg replaced');
215 ok(line_exists($output, qr|^bindsym Mod1\+s floating toggle$|), 't replaced');
216 ok(line_exists($output, qr|^bindsym Mod1\+s focus left$|), 'h replaced');
217 ok(line_exists($output, qr|^bindsym Mod1\+s focus down$|), 'j replaced');
218 ok(line_exists($output, qr|^bindsym Mod1\+s focus up$|), 'k replaced');
219 ok(line_exists($output, qr|^bindsym Mod1\+s focus right$|), 'l replaced');
220 ok(line_exists($output, qr|^bindsym Mod1\+s move left$|), 'mh replaced');
221 ok(line_exists($output, qr|^bindsym Mod1\+s move down$|), 'mj replaced');
222 ok(line_exists($output, qr|^bindsym Mod1\+s move up$|), 'mk replaced');
223 ok(line_exists($output, qr|^bindsym Mod1\+s move right$|), 'ml replaced');
224 ok(line_exists($output, qr|^bindsym Mod1\+s border normal$|), 'bn replaced');
225 ok(line_exists($output, qr|^bindsym Mod1\+s border 1pixel$|), 'bp replaced');
226 ok(line_exists($output, qr|^bindsym Mod1\+s border none$|), 'bb replaced');
227 ok(line_exists($output, qr|^bindsym Mod1\+s border toggle$|), 'bt replaced');
228 ok(line_exists($output, qr|^bindsym Mod1\+j focus parent; focus left$|), 'with container replaced with focus parent; focus left');
229 ok(line_exists($output, qr|^bindsym Mod1\+j focus parent; move right$|), 'with container replaced with focus parent; move right');
230 ok(line_exists($output, qr|^bindsym Mod1\+k kill$|), 'kill unchanged');
231 ok(line_exists($output, qr|^bindsym Mod1\+n workspace next$|), 'nw replaced');
232 ok(line_exists($output, qr|^bindsym Mod1\+p workspace prev$|), 'pw replaced');
233
234 #####################################################################
235 # check more advanced replacements
236 #####################################################################
237
238 $input = <<EOT;
239     bindsym Mod1+s goto foo
240 EOT
241
242 $output = migrate_config($input);
243 ok(line_exists($output, qr|^bindsym Mod1\+s \[con_mark="foo"\] focus$|), 'goto replaced');
244
245 #####################################################################
246 # check whether focus's parameters get changed correctly
247 #####################################################################
248
249 $input = <<EOT;
250 bindsym Mod1+f focus 3
251 bindsym Mod1+f focus floating
252 bindsym Mod1+f focus tiling
253 bindsym Mod1+f focus ft
254 EOT
255
256 $output = migrate_config($input);
257 like($output->[0], qr|^#.*focus.*obsolete.*focus 3$|, 'focus [number] gone');
258 like($output->[1], qr|^bindsym Mod1\+f focus floating$|, 'focus floating unchanged');
259 like($output->[2], qr|^bindsym Mod1\+f focus tiling$|, 'focus tiling unchanged');
260 like($output->[3], qr|^bindsym Mod1\+f focus mode_toggle$|, 'focus ft changed');
261
262 #####################################################################
263 # check whether resize's parameters get changed correctly
264 #####################################################################
265
266 $input = <<EOT;
267 bindsym Mod1+f resize left +10
268 bindsym Mod1+f resize top -20
269 bindsym Mod1+f resize right -20
270 bindsym Mod1+f resize bottom +23
271 bindsym Mod1+f resize          left    \t +10
272 EOT
273
274 $output = migrate_config($input);
275 like($output->[0], qr|^bindsym Mod1\+f resize grow left 10 px$|, 'resize left changed');
276 like($output->[1], qr|^bindsym Mod1\+f resize shrink up 20 px$|, 'resize top changed');
277 like($output->[2], qr|^bindsym Mod1\+f resize shrink right 20 px$|, 'resize right changed');
278 like($output->[3], qr|^bindsym Mod1\+f resize grow down 23 px$|, 'resize bottom changed');
279
280 #####################################################################
281 # also resizing, but with indention this time
282 #####################################################################
283
284 like($output->[4], qr|^bindsym Mod1\+f resize grow left 10 px$|, 'resize left changed');
285
286 #####################################################################
287 # check whether jump's parameters get changed correctly
288 #####################################################################
289
290 $input = <<EOT;
291 bindsym Mod1+f jump 3
292 bindsym Mod1+f jump 3 4 5
293 bindsym Mod1+f jump "XTerm"
294 bindsym Mod1+f jump "XTerm/irssi"
295 EOT
296
297 $output = migrate_config($input);
298 like($output->[0], qr|^#.*obsolete.*jump 3$|, 'jump to workspace removed');
299 like($output->[1], qr|^#.*obsolete.*jump 3 4 5$|, 'jump to workspace + col/row removed');
300 like($output->[2], qr|^bindsym Mod1\+f \[class="XTerm"\] focus$|, 'jump changed');
301 like($output->[3], qr|^bindsym Mod1\+f \[class="XTerm" title="irssi"\] focus$|, 'jump changed');
302
303 #####################################################################
304 # check whether workspace commands are handled correctly
305 #####################################################################
306
307 $output = migrate_config('workspace 3 output VGA-1');
308 ok(line_exists($output, qr|^workspace 3 output VGA-1$|), 'workspace assignment unchanged');
309
310 $output = migrate_config('workspace 3 work');
311 ok(!line_exists($output, qr|^workspace|), 'workspace name not present');
312 ok(line_exists($output, qr|#.*workspace name.*bindings|), 'note present');
313
314 $input = <<EOT;
315     workspace 3 work
316     bindsym Mod1+3 3
317 EOT
318 $output = migrate_config($input);
319 ok(!line_exists($output, qr|^workspace|), 'workspace name not present');
320 ok(line_exists($output, qr|^bindsym Mod1\+3 workspace work|), 'named workspace in bindings');
321
322 # The same, but in reverse order
323 $input = <<EOT;
324     bindsym Mod1+3 3
325     workspace 3 work
326 EOT
327 $output = migrate_config($input);
328 ok(!line_exists($output, qr|^workspace|), 'workspace name not present');
329 ok(line_exists($output, qr|^bindsym Mod1\+3 workspace work|), 'named workspace in bindings');
330
331 $output = migrate_config('bindsym Mod1+3 3');
332 ok(line_exists($output, qr|^bindsym Mod1\+3 workspace 3|), 'workspace changed');
333
334 $output = migrate_config('bindsym Mod1+3 m3');
335 ok(line_exists($output, qr|^bindsym Mod1\+3 move container to workspace 3|), 'move workspace changed');
336
337 $input = <<EOT;
338     workspace 3 work
339     bindsym Mod1+3 m3
340 EOT
341 $output = migrate_config($input);
342 ok(!line_exists($output, qr|^workspace|), 'workspace name not present');
343 ok(line_exists($output, qr|^bindsym Mod1\+3 move container to workspace work|), 'move to named workspace in bindings');
344
345 #####################################################################
346 # check whether an i3bar call is added if the workspace bar bar was enabled
347 #####################################################################
348
349 $output = migrate_config('');
350 ok(line_exists($output, qr|bar {|), 'i3bar added');
351
352 $output = migrate_config('workspace_bar enable');
353 ok(line_exists($output, qr|bar {|), 'i3bar added');
354
355 $output = migrate_config('workspace_bar no');
356 ok(!line_exists($output, qr|bar {|), 'no i3bar added');
357
358 #####################################################################
359 # check whether the mode command gets quotes
360 #####################################################################
361
362 $output = migrate_config('bindsym Mod1+m mode foobar');
363 ok(line_exists($output, qr|^bindsym Mod1\+m mode "foobar"|), 'mode got quotes');
364
365 done_testing();