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 #####################################################################
122 $output = migrate_config($input);
123 like($output->[0], qr|^new_window none$|, 'new_window bb changed');
124 like($output->[1], qr|^new_window normal$|, 'new_window bn changed');
125 like($output->[2], 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 #####################################################################
237 bindsym Mod1+f focus 3
238 bindsym Mod1+f focus floating
239 bindsym Mod1+f focus tiling
240 bindsym Mod1+f focus ft
243 $output = migrate_config($input);
244 like($output->[0], qr|^#.*focus.*obsolete.*focus 3$|, 'focus [number] gone');
245 like($output->[1], qr|^bindsym Mod1\+f focus floating$|, 'focus floating unchanged');
246 like($output->[2], qr|^bindsym Mod1\+f focus tiling$|, 'focus tiling unchanged');
247 like($output->[3], qr|^bindsym Mod1\+f focus mode_toggle$|, 'focus ft changed');
249 #####################################################################
250 # check whether resize's parameters get changed correctly
251 #####################################################################
254 bindsym Mod1+f resize left +10
255 bindsym Mod1+f resize top -20
256 bindsym Mod1+f resize right -20
257 bindsym Mod1+f resize bottom +23
258 bindsym Mod1+f resize left \t +10
261 $output = migrate_config($input);
262 like($output->[0], qr|^bindsym Mod1\+f resize grow left 10 px$|, 'resize left changed');
263 like($output->[1], qr|^bindsym Mod1\+f resize shrink up 20 px$|, 'resize top changed');
264 like($output->[2], qr|^bindsym Mod1\+f resize shrink right 20 px$|, 'resize right changed');
265 like($output->[3], qr|^bindsym Mod1\+f resize grow down 23 px$|, 'resize bottom changed');
267 #####################################################################
268 # also resizing, but with indention this time
269 #####################################################################
271 like($output->[4], qr|^bindsym Mod1\+f resize grow left 10 px$|, 'resize left changed');
273 #####################################################################
274 # check whether jump's parameters get changed correctly
275 #####################################################################
278 bindsym Mod1+f jump 3
279 bindsym Mod1+f jump 3 4 5
280 bindsym Mod1+f jump "XTerm"
281 bindsym Mod1+f jump "XTerm/irssi"
284 $output = migrate_config($input);
285 like($output->[0], qr|^#.*obsolete.*jump 3$|, 'jump to workspace removed');
286 like($output->[1], qr|^#.*obsolete.*jump 3 4 5$|, 'jump to workspace + col/row removed');
287 like($output->[2], qr|^bindsym Mod1\+f \[class="XTerm"\] focus$|, 'jump changed');
288 like($output->[3], qr|^bindsym Mod1\+f \[class="XTerm" title="irssi"\] focus$|, 'jump changed');
290 #####################################################################
291 # check whether workspace commands are handled correctly
292 #####################################################################
294 $output = migrate_config('workspace 3 output VGA-1');
295 ok(line_exists($output, qr|^workspace 3 output VGA-1$|), 'workspace assignment unchanged');
297 $output = migrate_config('workspace 3 work');
298 ok(!line_exists($output, qr|^workspace|), 'workspace name not present');
299 ok(line_exists($output, qr|#.*workspace name.*bindings|), 'note present');
305 $output = migrate_config($input);
306 ok(!line_exists($output, qr|^workspace|), 'workspace name not present');
307 ok(line_exists($output, qr|^bindsym Mod1\+3 workspace work|), 'named workspace in bindings');
309 # The same, but in reverse order
314 $output = migrate_config($input);
315 ok(!line_exists($output, qr|^workspace|), 'workspace name not present');
316 ok(line_exists($output, qr|^bindsym Mod1\+3 workspace work|), 'named workspace in bindings');
318 $output = migrate_config('bindsym Mod1+3 3');
319 ok(line_exists($output, qr|^bindsym Mod1\+3 workspace 3|), 'workspace changed');
321 $output = migrate_config('bindsym Mod1+3 m3');
322 ok(line_exists($output, qr|^bindsym Mod1\+3 move container to workspace 3|), 'move workspace changed');
328 $output = migrate_config($input);
329 ok(!line_exists($output, qr|^workspace|), 'workspace name not present');
330 ok(line_exists($output, qr|^bindsym Mod1\+3 move container to workspace work|), 'move to named workspace in bindings');
332 #####################################################################
333 # check whether an i3bar call is added if the workspace bar bar was enabled
334 #####################################################################
336 $output = migrate_config('');
337 ok(line_exists($output, qr|bar {|), 'i3bar added');
339 $output = migrate_config('workspace_bar enable');
340 ok(line_exists($output, qr|bar {|), 'i3bar added');
342 $output = migrate_config('workspace_bar no');
343 ok(!line_exists($output, qr|bar {|), 'no i3bar added');
345 #####################################################################
346 # check whether the mode command gets quotes
347 #####################################################################
349 $output = migrate_config('bindsym Mod1+m mode foobar');
350 ok(line_exists($output, qr|^bindsym Mod1\+m mode "foobar"|), 'mode got quotes');