]> git.sur5r.net Git - i3/i3/blob - testcases/t/59-socketpaths.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 59-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 Cwd qw(abs_path);
9 use Proc::Background;
10 use File::Temp qw(tempfile tempdir);
11 use POSIX qw(getuid);
12 use v5.10;
13
14 # assuming we are run by complete-run.pl
15 my $i3_path = abs_path("../i3");
16
17 #####################################################################
18 # default case: socket will be created in /tmp/i3-<username>/ipc-socket.<pid>
19 #####################################################################
20
21 my ($fh, $tmpfile) = tempfile('/tmp/i3-test-config.XXXXXX', UNLINK => 1);
22 say $fh "# i3 config file (v4)";
23 say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
24 close($fh);
25
26 diag("Starting i3");
27 my $i3cmd = "unset XDG_RUNTIME_DIR; exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
28 my $process = Proc::Background->new($i3cmd);
29 sleep 1;
30
31 diag("pid = " . $process->pid);
32
33 my $folder = "/tmp/i3-" . getpwuid(getuid());
34 ok(-d $folder, "folder $folder exists");
35 my $socketpath = "$folder/ipc-socket." . $process->pid;
36 ok(-S $socketpath, "file $socketpath exists and is a socket");
37
38 exit_gracefully($process->pid, $socketpath);
39
40 sleep 0.25;
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 $i3cmd = "export XDG_RUNTIME_DIR=$rtdir; exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
51 $process = Proc::Background->new($i3cmd);
52 sleep 1;
53
54 ok(-d "$rtdir/i3", "$rtdir/i3 exists and is a directory");
55 $socketpath = "$rtdir/i3/ipc-socket." . $process->pid;
56 ok(-S $socketpath, "file $socketpath exists and is a socket");
57
58 exit_gracefully($process->pid, $socketpath);
59
60 sleep 0.25;
61
62 #####################################################################
63 # configuration file case: socket gets placed whereever we specify
64 #####################################################################
65
66 my $tmpdir = tempdir(CLEANUP => 1);
67 $socketpath = $tmpdir . "/config.sock";
68 ok(! -e $socketpath, "$socketpath does not exist yet");
69
70 ($fh, $tmpfile) = tempfile('/tmp/i3-test-config.XXXXXX', UNLINK => 1);
71 say $fh "# i3 config file (v4)";
72 say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
73 say $fh "ipc-socket $socketpath";
74 close($fh);
75
76 $i3cmd = "export XDG_RUNTIME_DIR=$rtdir; exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
77 $process = Proc::Background->new($i3cmd);
78 sleep 1;
79
80 ok(-S $socketpath, "file $socketpath exists and is a socket");
81
82 exit_gracefully($process->pid, $socketpath);
83
84 done_testing;