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