about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-12-17 05:47:57 +0000
committerEric Wong <e@80x24.org>2020-12-19 09:32:08 +0000
commit553cb0506c798bc27494294107a0d9e45d5011f5 (patch)
tree0f7bed44592a3d7eea362c740537ad91a15cd199 /t
parent6fd9985615542a4d39569956c9de0b9e99b76ab8 (diff)
downloadpublic-inbox-553cb0506c798bc27494294107a0d9e45d5011f5.tar.gz
This allows us to respect XDG_* environment variables
to override HOME.

We'll also make the $lei wrapper easier-to-use by auto-clearing
$out/$err and reducing [] needed for common cases.
Diffstat (limited to 't')
-rw-r--r--t/lei.t27
1 files changed, 22 insertions, 5 deletions
diff --git a/t/lei.t b/t/lei.t
index b0943962..bdf6cc1c 100644
--- a/t/lei.t
+++ b/t/lei.t
@@ -9,13 +9,18 @@ use PublicInbox::Config;
 use File::Path qw(rmtree);
 require_mods(qw(json DBD::SQLite Search::Xapian));
 my $LEI = 'lei';
+my $opt = { 1 => \(my $out = ''), 2 => \(my $err = '') };
 my $lei = sub {
         my ($cmd, $env, $opt) = @_;
+        $out = $err = '';
+        if (!ref($cmd)) {
+                ($env, $opt) = grep { (!defined) || ref } @_;
+                $cmd = [ grep { defined } @_ ];
+        }
         run_script([$LEI, @$cmd], $env, $opt);
 };
 
 my ($home, $for_destroy) = tmpdir();
-my $opt = { 1 => \(my $out = ''), 2 => \(my $err = '') };
 delete local $ENV{XDG_DATA_HOME};
 delete local $ENV{XDG_CONFIG_HOME};
 local $ENV{XDG_RUNTIME_DIR} = "$home/xdg_run";
@@ -23,10 +28,7 @@ local $ENV{HOME} = $home;
 local $ENV{FOO} = 'BAR';
 mkdir "$home/xdg_run", 0700 or BAIL_OUT "mkdir: $!";
 my $home_trash = [ "$home/.local", "$home/.config" ];
-my $cleanup = sub {
-        rmtree([@$home_trash, @_]);
-        $out = $err = '';
-};
+my $cleanup = sub { rmtree([@$home_trash, @_]) };
 
 my $test_help = sub {
         ok(!$lei->([], undef, $opt), 'no args fails');
@@ -48,6 +50,21 @@ my $test_help = sub {
                 isnt($err, '', 'something in stderr');
                 is($out, '', 'nothing in stdout');
         }
+        ok($lei->(qw(init -h), undef, $opt), 'init -h');
+        like($out, qr! \Q$home\E/\.local/share/lei/store\b!,
+                'actual path shown in init -h');
+        ok($lei->(qw(init -h), { XDG_DATA_HOME => '/XDH' }, $opt),
+                'init with XDG_DATA_HOME');
+        like($out, qr! /XDH/lei/store\b!, 'XDG_DATA_HOME in init -h');
+        is($err, '', 'no errors from init -h');
+
+        ok($lei->(qw(config -h), undef, $opt), 'config-h');
+        like($out, qr! \Q$home\E/\.config/lei/config\b!,
+                'actual path shown in config -h');
+        ok($lei->(qw(config -h), { XDG_CONFIG_HOME => '/XDC' }, $opt),
+                'config with XDG_CONFIG_HOME');
+        like($out, qr! /XDC/lei/config\b!, 'XDG_CONFIG_HOME in config -h');
+        is($err, '', 'no errors from config -h');
 };
 
 my $ok_err_info = sub {