2 # vim:ts=4:sw=4:expandtab
4 # Tests if i3-migrate-config-to-v4 correctly migrates all config file
5 # directives and commands
7 use i3test i3_autostart => 0;
9 use File::Temp qw(tempfile tempdir);
12 # reads in a whole file
14 open my $fh, '<', shift;
22 my ($fh, $tmpfile) = tempfile('/tmp/i3-migrate-cfg.XXXXXX', UNLINK => 1);
26 my $cmd = "sh -c 'exec " . abs_path("../i3-migrate-config-to-v4") . " --v3 <$tmpfile'";
27 return [ split /\n/, qx($cmd) ];
31 my ($lines, $pattern) = @_;
33 for my $line (@$lines) {
34 return 1 if $line =~ $pattern;
40 #####################################################################
41 # check that some directives remain untouched
42 #####################################################################
45 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
48 my $output = migrate_config($input);
49 ok(line_exists($output, qr|font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1|), 'font directive unchanged');
52 floating_Modifier Mod1
53 focus_follows_mouse true
54 ipc-socket /tmp/i3-ipc.sock
55 ipc_socket /tmp/i3-ipc.sock
60 client.focused #2F343A #900000 #FFFFFF
61 client.focused_inactive #FF0000 #FF0000 #FF0000
62 client.unfocused #00FF00 #00FF00 #00FF00
63 client.urgent #0000FF #0000FF #0000FF
64 client.background #000000
67 $output = migrate_config($input);
68 ok(line_exists($output, qr|^floating_Modifier Mod1$|), 'floating_modifier unchanged');
69 ok(line_exists($output, qr|^focus_follows_mouse true$|), 'focus_follows_mouse unchanged');
70 ok(line_exists($output, qr|^ipc-socket /tmp/i3-ipc.sock$|), 'ipc-socket unchanged');
71 ok(line_exists($output, qr|^ipc_socket /tmp/i3-ipc.sock$|), 'ipc_socket unchanged');
72 ok(line_exists($output, qr|^exec /usr/bin/i3|), 'exec unchanged');
73 ok(line_exists($output, qr|^set stuff Mod1|), 'set unchanged');
74 ok(line_exists($output, qr|^assign "XTerm" → 3|), 'assign unchanged');
75 ok(line_exists($output, qr|^assign "XTerm" → ~5|), 'assign unchanged');
76 ok(line_exists($output, qr|^client\.focused #2F343A #900000 #FFFFFF$|), 'client.focused unchanged');
77 ok(line_exists($output, qr|^client\.focused_inactive #FF0000 #FF0000 #FF0000$|), 'client.focused_inactive unchanged');
78 ok(line_exists($output, qr|^client\.unfocused #00FF00 #00FF00 #00FF00$|), 'client.unfocused unchanged');
79 ok(line_exists($output, qr|^client\.urgent #0000FF #0000FF #0000FF$|), 'client.urgent unchanged');
80 ok(line_exists($output, qr|^client\.background #000000$|), 'client.background unchanged');
82 #####################################################################
83 # check whether the bar colors get removed properly
84 #####################################################################
87 bar.focused #FFFF00 #FFFF00 #FFFF00
88 bar.unfocused #FFFF00 #FFFF00 #FFFF00
89 bar.urgent #FFFF00 #FFFF00 #FFFF00
92 $output = migrate_config($input);
93 ok(!line_exists($output, qr|^bar\.|), 'no bar. lines');
94 ok(line_exists($output, qr|^#.*REMOVED bar|), 'note bar. removed');
97 #####################################################################
98 # check whether the other directives get converted correctly
99 #####################################################################
102 new_container stacking
107 $output = migrate_config($input);
108 ok(line_exists($output, qr|^workspace_layout stacking$|), 'new_container changed');
109 ok(line_exists($output, qr|REMOVED workspace_bar|), 'workspace_bar removed');
110 ok(!line_exists($output, qr|^workspace_bar|), 'no workspace_bar in the output');
111 ok(line_exists($output, qr|^new_window none$|), 'new_window changed');
113 #####################################################################
114 # check whether new_window's parameters get changed correctly
115 #####################################################################
117 $output = migrate_config('new_window bb');
118 ok(line_exists($output, qr|^new_window none$|), 'new_window bb changed');
120 $output = migrate_config('new_window bn');
121 ok(line_exists($output, qr|^new_window normal$|), 'new_window bn changed');
123 $output = migrate_config('new_window bp');
124 ok(line_exists($output, qr|^new_window 1pixel$|), 'new_window bp changed');
126 #####################################################################
127 # check that some commands remain untouched
128 #####################################################################
131 bindsym Mod1+s exec /usr/bin/urxvt
132 bindsym Mod1+s mark foo
133 bindsym Mod1+s restart
134 bindsym Mod1+s reload
136 bindsym Mod1+s stack-limit cols 2
137 bindsym Mod1+s stack-limit rows 3
138 bind Mod1+c exec /usr/bin/urxvt
144 $output = migrate_config($input);
145 ok(line_exists($output, qr|^bindsym Mod1\+s exec /usr/bin/urxvt$|), 'exec unchanged');
146 ok(line_exists($output, qr|^bindsym Mod1\+s mark foo$|), 'mark unchanged');
147 ok(line_exists($output, qr|^bindsym Mod1\+s restart$|), 'restart unchanged');
148 ok(line_exists($output, qr|^bindsym Mod1\+s reload$|), 'reload unchanged');
149 ok(line_exists($output, qr|^bindsym Mod1\+s exit$|), 'exit unchanged');
150 ok(line_exists($output, qr|^bindsym Mod1\+s stack-limit cols 2$|), 'stack-limit unchanged');
151 ok(line_exists($output, qr|^bindsym Mod1\+s stack-limit rows 3$|), 'stack-limit unchanged');
152 ok(line_exists($output, qr|^bindcode Mod1\+c exec /usr/bin/urxvt$|), 'bind changed to bindcode');
153 ok(line_exists($output, qr|^mode "asdf" {$|), 'mode asdf unchanged');
154 ok(line_exists($output, qr|^bindcode 36 mode \"default\"$|), 'mode default unchanged');
155 ok(line_exists($output, qr|^}$|), 'closing mode bracket still there');
157 #####################################################################
158 # check the simple command replacements
159 #####################################################################
195 $output = migrate_config($input);
196 ok(line_exists($output, qr|^bindsym Mod1\+s layout stacking$|), 's replaced');
197 ok(line_exists($output, qr|^bindsym Mod1\+s layout default$|), 'd replaced');
198 ok(line_exists($output, qr|^bindsym Mod1\+s layout tabbed$|), 'T replaced');
199 ok(line_exists($output, qr|^bindsym Mod1\+s fullscreen$|), 'f replaced');
200 ok(line_exists($output, qr|^bindsym Mod1\+s fullscreen global$|), 'fg replaced');
201 ok(line_exists($output, qr|^bindsym Mod1\+s floating toggle$|), 't replaced');
202 ok(line_exists($output, qr|^bindsym Mod1\+s focus left$|), 'h replaced');
203 ok(line_exists($output, qr|^bindsym Mod1\+s focus down$|), 'j replaced');
204 ok(line_exists($output, qr|^bindsym Mod1\+s focus up$|), 'k replaced');
205 ok(line_exists($output, qr|^bindsym Mod1\+s focus right$|), 'l replaced');
206 ok(line_exists($output, qr|^bindsym Mod1\+s move left$|), 'mh replaced');
207 ok(line_exists($output, qr|^bindsym Mod1\+s move down$|), 'mj replaced');
208 ok(line_exists($output, qr|^bindsym Mod1\+s move up$|), 'mk replaced');
209 ok(line_exists($output, qr|^bindsym Mod1\+s move right$|), 'ml replaced');
210 ok(line_exists($output, qr|^bindsym Mod1\+s border normal$|), 'bn replaced');
211 ok(line_exists($output, qr|^bindsym Mod1\+s border 1pixel$|), 'bp replaced');
212 ok(line_exists($output, qr|^bindsym Mod1\+s border none$|), 'bb replaced');
213 ok(line_exists($output, qr|^bindsym Mod1\+s border toggle$|), 'bt replaced');
214 ok(line_exists($output, qr|^bindsym Mod1\+j focus parent; focus left$|), 'with container replaced with focus parent; focus left');
215 ok(line_exists($output, qr|^bindsym Mod1\+j focus parent; move right$|), 'with container replaced with focus parent; move right');
216 ok(line_exists($output, qr|^bindsym Mod1\+k kill$|), 'kill unchanged');
217 ok(line_exists($output, qr|^bindsym Mod1\+n workspace next$|), 'nw replaced');
218 ok(line_exists($output, qr|^bindsym Mod1\+p workspace prev$|), 'pw replaced');
220 #####################################################################
221 # check more advanced replacements
222 #####################################################################
225 bindsym Mod1+s goto foo
228 $output = migrate_config($input);
229 ok(line_exists($output, qr|^bindsym Mod1\+s \[con_mark="foo"\] focus$|), 'goto replaced');
231 #####################################################################
232 # check whether focus's parameters get changed correctly
233 #####################################################################
235 $output = migrate_config('bindsym Mod1+f focus 3');
236 ok(line_exists($output, qr|^#.*focus.*obsolete.*focus 3$|), 'focus [number] gone');
238 $output = migrate_config('bindsym Mod1+f focus floating');
239 ok(line_exists($output, qr|^bindsym Mod1\+f focus floating$|), 'focus floating unchanged');
241 $output = migrate_config('bindsym Mod1+f focus tiling');
242 ok(line_exists($output, qr|^bindsym Mod1\+f focus tiling$|), 'focus tiling unchanged');
244 $output = migrate_config('bindsym Mod1+f focus ft');
245 ok(line_exists($output, qr|^bindsym Mod1\+f focus mode_toggle$|), 'focus ft changed');
247 #####################################################################
248 # check whether resize's parameters get changed correctly
249 #####################################################################
251 $output = migrate_config('bindsym Mod1+f resize left +10');
252 ok(line_exists($output, qr|^bindsym Mod1\+f resize grow left 10 px$|), 'resize left changed');
254 $output = migrate_config('bindsym Mod1+f resize top -20');
255 ok(line_exists($output, qr|^bindsym Mod1\+f resize shrink up 20 px$|), 'resize top changed');
257 $output = migrate_config('bindsym Mod1+f resize right -20');
258 ok(line_exists($output, qr|^bindsym Mod1\+f resize shrink right 20 px$|), 'resize right changed');
260 $output = migrate_config('bindsym Mod1+f resize bottom +23');
261 ok(line_exists($output, qr|^bindsym Mod1\+f resize grow down 23 px$|), 'resize bottom changed');
263 #####################################################################
264 # also resizing, but with indention this time
265 #####################################################################
267 $output = migrate_config("bindsym Mod1+f resize left \t +10");
268 ok(line_exists($output, qr|^bindsym Mod1\+f resize grow left 10 px$|), 'resize left changed');
270 #####################################################################
271 # check whether jump's parameters get changed correctly
272 #####################################################################
274 $output = migrate_config('bindsym Mod1+f jump 3');
275 ok(line_exists($output, qr|^#.*obsolete.*jump 3$|), 'jump to workspace removed');
277 $output = migrate_config('bindsym Mod1+f jump 3 4 5');
278 ok(line_exists($output, qr|^#.*obsolete.*jump 3 4 5$|), 'jump to workspace + col/row removed');
280 $output = migrate_config('bindsym Mod1+f jump "XTerm"');
281 ok(line_exists($output, qr|^bindsym Mod1\+f \[class="XTerm"\] focus$|), 'jump changed');
283 $output = migrate_config('bindsym Mod1+f jump "XTerm/irssi"');
284 ok(line_exists($output, qr|^bindsym Mod1\+f \[class="XTerm" title="irssi"\] focus$|), 'jump changed');
286 #####################################################################
287 # check whether workspace commands are handled correctly
288 #####################################################################
290 $output = migrate_config('workspace 3 output VGA-1');
291 ok(line_exists($output, qr|^workspace 3 output VGA-1$|), 'workspace assignment unchanged');
293 $output = migrate_config('workspace 3 work');
294 ok(!line_exists($output, qr|^workspace|), 'workspace name not present');
295 ok(line_exists($output, qr|#.*workspace name.*bindings|), 'note present');
301 $output = migrate_config($input);
302 ok(!line_exists($output, qr|^workspace|), 'workspace name not present');
303 ok(line_exists($output, qr|^bindsym Mod1\+3 workspace work|), 'named workspace in bindings');
305 # The same, but in reverse order
310 $output = migrate_config($input);
311 ok(!line_exists($output, qr|^workspace|), 'workspace name not present');
312 ok(line_exists($output, qr|^bindsym Mod1\+3 workspace work|), 'named workspace in bindings');
314 $output = migrate_config('bindsym Mod1+3 3');
315 ok(line_exists($output, qr|^bindsym Mod1\+3 workspace 3|), 'workspace changed');
317 $output = migrate_config('bindsym Mod1+3 m3');
318 ok(line_exists($output, qr|^bindsym Mod1\+3 move container to workspace 3|), 'move workspace changed');
324 $output = migrate_config($input);
325 ok(!line_exists($output, qr|^workspace|), 'workspace name not present');
326 ok(line_exists($output, qr|^bindsym Mod1\+3 move container to workspace work|), 'move to named workspace in bindings');
328 #####################################################################
329 # check whether an i3bar call is added if the workspace bar bar was enabled
330 #####################################################################
332 $output = migrate_config('');
333 ok(line_exists($output, qr|bar {|), 'i3bar added');
335 $output = migrate_config('workspace_bar enable');
336 ok(line_exists($output, qr|bar {|), 'i3bar added');
338 $output = migrate_config('workspace_bar no');
339 ok(!line_exists($output, qr|bar {|), 'no i3bar added');
341 #####################################################################
342 # check whether the mode command gets quotes
343 #####################################################################
345 $output = migrate_config('bindsym Mod1+m mode foobar');
346 ok(line_exists($output, qr|^bindsym Mod1\+m mode "foobar"|), 'mode got quotes');