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