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