]> git.sur5r.net Git - i3/i3/blob - testcases/t/159-socketpaths.t
Fix spelling mistakes
[i3/i3] / testcases / t / 159-socketpaths.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Tests if the various ipc_socket_path options are correctly handled
18 #
19 use i3test i3_autostart => 0;
20 use File::Temp qw(tempfile tempdir);
21 use File::Basename;
22 use POSIX qw(getuid);
23 use v5.10;
24
25 #####################################################################
26 # default case: socket will be created in /tmp/i3-<username>/ipc-socket.<pid>
27 #####################################################################
28
29 my $config = <<EOT;
30 # i3 config file (v4)
31 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
32 EOT
33
34 # ensure XDG_RUNTIME_DIR is not set
35 delete $ENV{XDG_RUNTIME_DIR};
36
37 my $pid = launch_with_config($config, dont_add_socket_path => 1, dont_create_temp_dir => 1);
38 my $socketpath = get_socket_path(0);
39 my $folder = "/tmp/i3-" . getpwuid(getuid());
40 like(dirname($socketpath), qr/^$folder/, 'temp directory matches expected pattern');
41 $folder = dirname($socketpath);
42
43 ok(-d $folder, "folder $folder exists");
44 $socketpath = "$folder/ipc-socket." . $pid;
45 ok(-S $socketpath, "file $socketpath exists and is a socket");
46
47 exit_gracefully($pid);
48
49 #####################################################################
50 # XDG_RUNTIME_DIR case: socket gets created in $XDG_RUNTIME_DIR/i3/ipc-socket.<pid>
51 #####################################################################
52
53 my $rtdir = tempdir(CLEANUP => 1);
54
55 ok(! -e "$rtdir/i3", "$rtdir/i3 does not exist yet");
56
57 $ENV{XDG_RUNTIME_DIR} = $rtdir;
58
59 $pid = launch_with_config($config, dont_add_socket_path => 1, dont_create_temp_dir => 1);
60
61 ok(-d "$rtdir/i3", "$rtdir/i3 exists and is a directory");
62 $socketpath = "$rtdir/i3/ipc-socket." . $pid;
63 ok(-S $socketpath, "file $socketpath exists and is a socket");
64
65 exit_gracefully($pid);
66
67 #####################################################################
68 # configuration file case: socket gets placed wherever we specify
69 #####################################################################
70
71 my $tmpdir = tempdir(CLEANUP => 1);
72 $socketpath = $tmpdir . "/config.sock";
73 ok(! -e $socketpath, "$socketpath does not exist yet");
74
75 $config = <<EOT;
76 # i3 config file (v4)
77 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
78 ipc-socket $socketpath
79 EOT
80
81 $pid = launch_with_config($config, dont_add_socket_path => 1, dont_create_temp_dir => 1);
82
83 ok(-S $socketpath, "file $socketpath exists and is a socket");
84
85 exit_gracefully($pid);
86
87 done_testing;