#!perl # vim:ts=4:sw=4:expandtab # # Please read the following documents before working on tests: # • http://build.i3wm.org/docs/testsuite.html # (or docs/testsuite) # # • http://build.i3wm.org/docs/lib-i3test.html # (alternatively: perldoc ./testcases/lib/i3test.pm) # # • http://build.i3wm.org/docs/ipc.html # (or docs/ipc) # # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf # (unless you are already familiar with Perl) # # Tests if i3-migrate-config-to-v4 correctly migrates all config file # directives and commands # use i3test i3_autostart => 0; use Cwd qw(abs_path); use File::Temp qw(tempfile tempdir); 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('/tmp/i3-migrate-cfg.XXXXXX', UNLINK => 1); 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 = <[0], qr|^new_window none$|, 'new_window bb changed'); like($output->[1], qr|^new_window normal$|, 'new_window bn changed'); like($output->[2], qr|^new_window 1pixel$|, 'new_window bp changed'); ##################################################################### # check that some commands remain untouched ##################################################################### $input = <[0], qr|^#.*focus.*obsolete.*focus 3$|, 'focus [number] gone'); like($output->[1], qr|^bindsym Mod1\+f focus floating$|, 'focus floating unchanged'); like($output->[2], qr|^bindsym Mod1\+f focus tiling$|, 'focus tiling unchanged'); like($output->[3], qr|^bindsym Mod1\+f focus mode_toggle$|, 'focus ft changed'); ##################################################################### # check whether resize's parameters get changed correctly ##################################################################### $input = <[0], qr|^bindsym Mod1\+f resize grow left 10 px$|, 'resize left changed'); like($output->[1], qr|^bindsym Mod1\+f resize shrink up 20 px$|, 'resize top changed'); like($output->[2], qr|^bindsym Mod1\+f resize shrink right 20 px$|, 'resize right changed'); like($output->[3], qr|^bindsym Mod1\+f resize grow down 23 px$|, 'resize bottom changed'); ##################################################################### # also resizing, but with indention this time ##################################################################### like($output->[4], qr|^bindsym Mod1\+f resize grow left 10 px$|, 'resize left changed'); ##################################################################### # check whether jump's parameters get changed correctly ##################################################################### $input = <[0], qr|^#.*obsolete.*jump 3$|, 'jump to workspace removed'); like($output->[1], qr|^#.*obsolete.*jump 3 4 5$|, 'jump to workspace + col/row removed'); like($output->[2], qr|^bindsym Mod1\+f \[class="XTerm"\] focus$|, 'jump changed'); like($output->[3], 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 = <