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