]> git.sur5r.net Git - i3/i3/blob - testcases/t/159-socketpaths.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 159-socketpaths.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Tests if the various ipc_socket_path options are correctly handled
5 #
6 use i3test i3_autostart => 0;
7 use File::Temp qw(tempfile tempdir);
8 use File::Basename;
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 my $pid = launch_with_config($config, dont_add_socket_path => 1, dont_create_temp_dir => 1);
25 my $socketpath = get_socket_path(0);
26 my $folder = "/tmp/i3-" . getpwuid(getuid());
27 like(dirname($socketpath), qr/^$folder/, 'temp directory matches expected pattern');
28 $folder = dirname($socketpath);
29
30 ok(-d $folder, "folder $folder exists");
31 $socketpath = "$folder/ipc-socket." . $pid;
32 ok(-S $socketpath, "file $socketpath exists and is a socket");
33
34 exit_gracefully($pid);
35
36 #####################################################################
37 # XDG_RUNTIME_DIR case: socket gets created in $XDG_RUNTIME_DIR/i3/ipc-socket.<pid>
38 #####################################################################
39
40 my $rtdir = tempdir(CLEANUP => 1);
41
42 ok(! -e "$rtdir/i3", "$rtdir/i3 does not exist yet");
43
44 $ENV{XDG_RUNTIME_DIR} = $rtdir;
45
46 $pid = launch_with_config($config, dont_add_socket_path => 1, dont_create_temp_dir => 1);
47
48 ok(-d "$rtdir/i3", "$rtdir/i3 exists and is a directory");
49 $socketpath = "$rtdir/i3/ipc-socket." . $pid;
50 ok(-S $socketpath, "file $socketpath exists and is a socket");
51
52 exit_gracefully($pid);
53
54 #####################################################################
55 # configuration file case: socket gets placed whereever we specify
56 #####################################################################
57
58 my $tmpdir = tempdir(CLEANUP => 1);
59 $socketpath = $tmpdir . "/config.sock";
60 ok(! -e $socketpath, "$socketpath does not exist yet");
61
62 $config = <<EOT;
63 # i3 config file (v4)
64 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
65 ipc-socket $socketpath
66 EOT
67
68 $pid = launch_with_config($config, dont_add_socket_path => 1, dont_create_temp_dir => 1);
69
70 ok(-S $socketpath, "file $socketpath exists and is a socket");
71
72 exit_gracefully($pid);
73
74 done_testing;