2 # vim:ts=4:sw=4:expandtab
3 # !NO_I3_INSTANCE! will prevent complete-run.pl from starting i3
5 # Tests if i3-migrate-config-to-v4 correctly migrates all config file
6 # directives and commands
10 use File::Temp qw(tempfile tempdir);
13 # reads in a whole file
15 open my $fh, '<', shift;
23 my ($fh, $tmpfile) = tempfile('/tmp/i3-migrate-cfg.XXXXXX', UNLINK => 1);
27 my $cmd = "sh -c 'exec " . abs_path("../i3-migrate-config-to-v4") . " --v3 <$tmpfile'";
28 return [ split /\n/, qx($cmd) ];
32 my ($lines, $pattern) = @_;
34 for my $line (@$lines) {
35 return 1 if $line =~ $pattern;
41 #####################################################################
42 # check that some directives remain untouched
43 #####################################################################
46 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
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');
53 floating_Modifier Mod1
54 focus_follows_mouse true
55 ipc-socket /tmp/i3-ipc.sock
56 ipc_socket /tmp/i3-ipc.sock
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
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');
83 #####################################################################
84 # check whether the bar colors get removed properly
85 #####################################################################
88 bar.focused #FFFF00 #FFFF00 #FFFF00
89 bar.unfocused #FFFF00 #FFFF00 #FFFF00
90 bar.urgent #FFFF00 #FFFF00 #FFFF00
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');
98 #####################################################################
99 # check whether the other directives get converted correctly
100 #####################################################################
103 new_container stacking
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');
114 #####################################################################
115 # check whether new_window's parameters get changed correctly
116 #####################################################################
118 $output = migrate_config('new_window bb');
119 ok(line_exists($output, qr|^new_window none$|), 'new_window bb changed');
121 $output = migrate_config('new_window bn');
122 ok(line_exists($output, qr|^new_window normal$|), 'new_window bn changed');
124 $output = migrate_config('new_window bp');
125 ok(line_exists($output, qr|^new_window 1pixel$|), 'new_window bp changed');
127 #####################################################################
128 # check that some commands remain untouched
129 #####################################################################
132 bindsym Mod1+s exec /usr/bin/urxvt
133 bindsym Mod1+s mark foo
134 bindsym Mod1+s restart
135 bindsym Mod1+s reload
137 bindsym Mod1+s stack-limit cols 2
138 bindsym Mod1+s stack-limit rows 3
139 bind Mod1+c exec /usr/bin/urxvt
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');
158 #####################################################################
159 # check the simple command replacements
160 #####################################################################
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');
221 #####################################################################
222 # check more advanced replacements
223 #####################################################################
226 bindsym Mod1+s goto foo
229 $output = migrate_config($input);
230 ok(line_exists($output, qr|^bindsym Mod1\+s \[con_mark="foo"\] focus$|), 'goto replaced');
232 #####################################################################
233 # check whether focus's parameters get changed correctly
234 #####################################################################
236 $output = migrate_config('bindsym Mod1+f focus 3');
237 ok(line_exists($output, qr|^#.*focus.*obsolete.*focus 3$|), 'focus [number] gone');
239 $output = migrate_config('bindsym Mod1+f focus floating');
240 ok(line_exists($output, qr|^bindsym Mod1\+f focus floating$|), 'focus floating unchanged');
242 $output = migrate_config('bindsym Mod1+f focus tiling');
243 ok(line_exists($output, qr|^bindsym Mod1\+f focus tiling$|), 'focus tiling unchanged');
245 $output = migrate_config('bindsym Mod1+f focus ft');
246 ok(line_exists($output, qr|^bindsym Mod1\+f focus mode_toggle$|), 'focus ft changed');
248 #####################################################################
249 # check whether resize's parameters get changed correctly
250 #####################################################################
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');
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');
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');
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');
264 #####################################################################
265 # also resizing, but with indention this time
266 #####################################################################
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');
271 #####################################################################
272 # check whether jump's parameters get changed correctly
273 #####################################################################
275 $output = migrate_config('bindsym Mod1+f jump 3');
276 ok(line_exists($output, qr|^#.*obsolete.*jump 3$|), 'jump to workspace removed');
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');
281 $output = migrate_config('bindsym Mod1+f jump "XTerm"');
282 ok(line_exists($output, qr|^bindsym Mod1\+f \[class="XTerm"\] focus$|), 'jump changed');
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');
287 #####################################################################
288 # check whether workspace commands are handled correctly
289 #####################################################################
291 $output = migrate_config('workspace 3 output VGA-1');
292 ok(line_exists($output, qr|^workspace 3 output VGA-1$|), 'workspace assignment unchanged');
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');
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');
306 # The same, but in reverse order
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');
315 $output = migrate_config('bindsym Mod1+3 3');
316 ok(line_exists($output, qr|^bindsym Mod1\+3 workspace 3|), 'workspace changed');
318 $output = migrate_config('bindsym Mod1+3 m3');
319 ok(line_exists($output, qr|^bindsym Mod1\+3 move workspace 3|), 'move workspace changed');
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');
329 #####################################################################
330 # check whether an i3bar call is added if the workspace bar bar was enabled
331 #####################################################################
333 $output = migrate_config('');
334 ok(line_exists($output, qr|bar {|), 'i3bar added');
336 $output = migrate_config('workspace_bar enable');
337 ok(line_exists($output, qr|bar {|), 'i3bar added');
339 $output = migrate_config('workspace_bar no');
340 ok(!line_exists($output, qr|bar {|), 'no i3bar added');
342 #####################################################################
343 # check whether the mode command gets quotes
344 #####################################################################
346 $output = migrate_config('bindsym Mod1+m mode foobar');
347 ok(line_exists($output, qr|^bindsym Mod1\+m mode "foobar"|), 'mode got quotes');