]> git.sur5r.net Git - i3/i3/blob - testcases/t/159-socketpaths.t
Merge branch 'fix-floating-pos'
[i3/i3] / testcases / t / 159-socketpaths.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 # !NO_I3_INSTANCE! will prevent complete-run.pl from starting i3
4 #
5 # Tests if the various ipc_socket_path options are correctly handled
6 #
7 use i3test;
8 use File::Temp qw(tempfile tempdir);
9 use POSIX qw(getuid);
10 use v5.10;
11
12 #####################################################################
13 # default case: socket will be created in /tmp/i3-<username>/ipc-socket.<pid>
14 #####################################################################
15
16 my $config = <<EOT;
17 # i3 config file (v4)
18 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
19 EOT
20
21 # ensure XDG_RUNTIME_DIR is not set
22 delete $ENV{XDG_RUNTIME_DIR};
23
24 # See which files exist in /tmp before to not mistakenly check an already
25 # existing tmpdir of another i3 instance.
26 my @files_before = </tmp/i3-*>;
27 my $pid = launch_with_config($config, 1);
28 my @files_after = </tmp/i3-*>;
29 @files_after = grep { !($_ ~~ @files_before) } @files_after;
30
31 is(@files_after, 1, 'one new temp directory');
32
33 my $folder = "/tmp/i3-" . getpwuid(getuid());
34 like($files_after[0], qr/^$folder/, 'temp directory matches expected pattern');
35 $folder = $files_after[0];
36
37 ok(-d $folder, "folder $folder exists");
38 my $socketpath = "$folder/ipc-socket." . $pid;
39 ok(-S $socketpath, "file $socketpath exists and is a socket");
40
41 exit_gracefully($pid);
42
43 #####################################################################
44 # XDG_RUNTIME_DIR case: socket gets created in $XDG_RUNTIME_DIR/i3/ipc-socket.<pid>
45 #####################################################################
46
47 my $rtdir = tempdir(CLEANUP => 1);
48
49 ok(! -e "$rtdir/i3", "$rtdir/i3 does not exist yet");
50
51 $ENV{XDG_RUNTIME_DIR} = $rtdir;
52
53 $pid = launch_with_config($config, 1);
54
55 ok(-d "$rtdir/i3", "$rtdir/i3 exists and is a directory");
56 $socketpath = "$rtdir/i3/ipc-socket." . $pid;
57 ok(-S $socketpath, "file $socketpath exists and is a socket");
58
59 exit_gracefully($pid);
60
61 #####################################################################
62 # configuration file case: socket gets placed whereever we specify
63 #####################################################################
64
65 my $tmpdir = tempdir(CLEANUP => 1);
66 $socketpath = $tmpdir . "/config.sock";
67 ok(! -e $socketpath, "$socketpath does not exist yet");
68
69 $config = <<EOT;
70 # i3 config file (v4)
71 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
72 ipc-socket $socketpath
73 EOT
74
75 $pid = launch_with_config($config, 1);
76
77 ok(-S $socketpath, "file $socketpath exists and is a socket");
78
79 exit_gracefully($pid);
80
81 done_testing;