about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-12-16 09:30:28 +0000
committerEric Wong <e@80x24.org>2020-12-19 09:32:08 +0000
commitbcf5e76a87b46b038509b65ced64149e6d2b81c3 (patch)
treeafb6f36f8aa0e986908adbc60e2ba7a03ed50e87 /t
parente605ec76c5a3afe9390ca95709fed719a098235a (diff)
downloadpublic-inbox-bcf5e76a87b46b038509b65ced64149e6d2b81c3.tar.gz
While lei(1) socket connections can set environment variables
for its running context, it may not completely remove some of
them.  The background daemon just inherits whatever env the
client spawning it had.  This command ensures the persistent env
can be modified as needed.

Similar to env(1), this supports "-u", "-" (--clear), and
"-0"/"-z" switches.  It may be useful to unset or change
or even completely clear the environment independently
of what a socket client feeds us.

"-i" is omitted since "--ignore-environment" seems like a bad
name for a persistent daemon as opposed to a one-shot command.
"-" and --clear (like clearenv(3)) will completely clobber
the environment.

"Lonesome dash" support is added to our option/help parsing
for the "-" shortcut to "--clear".
Getopt::Long doesn't seem to support specs like "clear|" or
"stdin|", but only "", so we do a little pre/post-processing
to merge the cases.
Diffstat (limited to 't')
-rw-r--r--t/lei.t31
1 files changed, 31 insertions, 0 deletions
diff --git a/t/lei.t b/t/lei.t
index 507c7164..53268908 100644
--- a/t/lei.t
+++ b/t/lei.t
@@ -20,6 +20,7 @@ delete local $ENV{XDG_DATA_HOME};
 delete local $ENV{XDG_CONFIG_HOME};
 local $ENV{XDG_RUNTIME_DIR} = "$home/xdg_run";
 local $ENV{HOME} = $home;
+local $ENV{FOO} = 'BAR';
 mkdir "$home/xdg_run", 0700 or BAIL_OUT "mkdir: $!";
 
 my $test_lei_common = sub {
@@ -104,6 +105,36 @@ SKIP: {
         chomp(my $pid_again = $out);
         is($pid, $pid_again, 'daemon-pid idempotent');
 
+        $out = '';
+        ok(run_script([qw(lei daemon-env -0)], undef, $opt), 'show env');
+        is($err, '', 'no errors in env dump');
+        my @env = split(/\0/, $out);
+        is(scalar grep(/\AHOME=\Q$home\E\z/, @env), 1, 'env has HOME');
+        is(scalar grep(/\AFOO=BAR\z/, @env), 1, 'env has FOO=BAR');
+        is(scalar grep(/\AXDG_RUNTIME_DIR=/, @env), 1, 'has XDG_RUNTIME_DIR');
+
+        $out = '';
+        ok(run_script([qw(lei daemon-env -u FOO)], undef, $opt), 'unset');
+        is($out.$err, '', 'no output for unset');
+        ok(run_script([qw(lei daemon-env -0)], undef, $opt), 'show again');
+        is($err, '', 'no errors in env dump');
+        @env = split(/\0/, $out);
+        is(scalar grep(/\AFOO=BAR\z/, @env), 0, 'env unset FOO');
+
+        $out = '';
+        ok(run_script([qw(lei daemon-env -u FOO -u HOME -u XDG_RUNTIME_DIR)],
+                        undef, $opt), 'unset multiple');
+        is($out.$err, '', 'no errors output for unset');
+        ok(run_script([qw(lei daemon-env -0)], undef, $opt), 'show again');
+        is($err, '', 'no errors in env dump');
+        @env = split(/\0/, $out);
+        is(scalar grep(/\A(?:HOME|XDG_RUNTIME_DIR)=\z/, @env), 0, 'env unset@');
+        $out = '';
+        ok(run_script([qw(lei daemon-env -)], undef, $opt), 'clear env');
+        is($out.$err, '', 'no output');
+        ok(run_script([qw(lei daemon-env)], undef, $opt), 'env is empty');
+        is($out, '', 'env cleared');
+
         ok(run_script([qw(lei daemon-stop)], undef, $opt), 'daemon-stop');
         is($out, '', 'no output from daemon-stop');
         is($err, '', 'no error from daemon-stop');