2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Makes sure i3 deletes its temporary directory when exiting.
19 # Bug still in: 4.7.2-186-g617afc6
20 use i3test i3_autostart => 0;
22 use File::Temp qw(tempfile tempdir);
23 use X11::XCB qw(:all);
27 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
30 # ensure XDG_RUNTIME_DIR is not set
31 delete $ENV{XDG_RUNTIME_DIR};
33 my $pid = launch_with_config($config, dont_add_socket_path => 1, dont_create_temp_dir => 1);
34 my $socketpath = get_socket_path(0);
35 my $tmpdir = dirname($socketpath);
37 ok(-d $tmpdir, "tmpdir $tmpdir exists");
39 # Clear the error logfile. The testsuite runs in an environment where RandR is
40 # not supported, so there always is a message about xinerama in the error
42 my @errorlogfiles = <$tmpdir/errorlog.*>;
43 for my $fn (@errorlogfiles) {
44 open(my $fh, '>', $fn);
48 exit_gracefully($pid);
50 ok(! -d $tmpdir, "tmpdir $tmpdir was cleaned up");
52 diag('contents = ' . Dumper(<$tmpdir/*>));
55 $pid = launch_with_config($config, dont_add_socket_path => 1, dont_create_temp_dir => 1);
56 $socketpath = get_socket_path(0);
57 $tmpdir = dirname($socketpath);
59 ok(-d $tmpdir, "tmpdir $tmpdir exists");
61 # Clear the error logfile. The testsuite runs in an environment where RandR is
62 # not supported, so there always is a message about xinerama in the error
64 @errorlogfiles = <$tmpdir/errorlog.*>;
65 for my $fn (@errorlogfiles) {
66 open(my $fh, '>', $fn);
70 diag('socket path before restarting is ' . $socketpath);
74 # The socket path will be different, and we use that for checking whether i3 has restarted yet.
75 while (get_socket_path(0) eq $socketpath) {
79 my $new_tmpdir = dirname(get_socket_path());
83 # Clear the error logfile. The testsuite runs in an environment where RandR is
84 # not supported, so there always is a message about xinerama in the error
86 @errorlogfiles = <$new_tmpdir/errorlog.*>;
87 for my $fn (@errorlogfiles) {
88 open(my $fh, '>', $fn);
92 exit_gracefully($pid);
94 ok(! -d $tmpdir, "old tmpdir $tmpdir was cleaned up");
96 diag('contents = ' . Dumper(<$tmpdir/*>));
99 ok(! -d $new_tmpdir, "new tmpdir $new_tmpdir was cleaned up");
100 if (-d $new_tmpdir) {
101 diag('contents = ' . Dumper(<$new_tmpdir/*>));
104 ################################################################################
105 # Regression: with a socket path outside of tmpdir, i3 would delete the tmpdir
106 # prematurely and could not use it for storing the restart layout.
107 ################################################################################
109 # Set XDG_RUNTIME_DIR to a temp directory so that i3 will create its directory
110 # in there and we’ll be able to find it. Necessary because we cannot deduce the
111 # temp directory from the socket path (which we explicitly set).
112 $ENV{XDG_RUNTIME_DIR} = tempdir(CLEANUP => 1);
114 my ($outfh, $outname) = tempfile('/tmp/i3-socket.XXXXXX', UNLINK => 1);
116 # i3 config file (v4)
117 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
122 $pid = launch_with_config($config, dont_add_socket_path => 1, dont_create_temp_dir => 1);
123 $socketpath = get_socket_path(0);
125 sub get_config_path {
126 my $atom = $x->atom(name => 'I3_CONFIG_PATH');
127 my $cookie = $x->get_property(0, $x->get_root_window(), $atom->id, GET_PROPERTY_TYPE_ANY, 0, 256);
128 my $reply = $x->get_property_reply($cookie->{sequence});
129 return $reply->{value};
132 my ($outfh2, $outname2) = tempfile('/tmp/i3-socket.XXXXXX', UNLINK => 1);
133 my $config_path = get_config_path();
134 open(my $configfh, '>', $config_path);
136 # i3 config file (v4)
137 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
141 $tmpdir = $ENV{XDG_RUNTIME_DIR} . '/i3';
143 ok(-d $tmpdir, "tmpdir $tmpdir exists");
145 # Clear the error logfile. The testsuite runs in an environment where RandR is
146 # not supported, so there always is a message about xinerama in the error
148 @errorlogfiles = <$tmpdir/errorlog.*>;
149 for my $fn (@errorlogfiles) {
150 open(my $fh, '>', $fn);
154 my $tmp = fresh_workspace;
155 my $win = open_window;
157 my ($nodes, $focus) = get_ws_content($tmp);
158 is($nodes->[0]->{border}, 'none', 'border is none');
162 # The socket path will be different, and we use that for checking whether i3 has restarted yet.
163 while (get_socket_path(0) eq $socketpath) {
167 $new_tmpdir = $ENV{XDG_RUNTIME_DIR} . '/i3';
171 ($nodes, $focus) = get_ws_content($tmp);
172 is($nodes->[0]->{border}, 'none', 'border still none after restart');
174 exit_gracefully($pid);