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