]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
test_common: use $cwdfh for every run_script command
authorEric Wong <e@80x24.org>
Tue, 17 Oct 2023 23:38:06 +0000 (23:38 +0000)
committerEric Wong <e@80x24.org>
Wed, 18 Oct 2023 20:50:36 +0000 (20:50 +0000)
It's not lei-specific since we have `-C' to perform chdir
for multiple admin commands.

lib/PublicInbox/TestCommon.pm

index 96663731d0f7329b0365dcb86375ec00670de195..5ad12942f74848b6afca7a50d4f41a859fbe84c4 100644 (file)
@@ -15,7 +15,7 @@ use Carp ();
 our @EXPORT;
 my $lei_loud = $ENV{TEST_LEI_ERR_LOUD};
 my $tail_cmd = $ENV{TAIL};
-our ($lei_opt, $lei_out, $lei_err, $lei_cwdfh);
+our ($lei_opt, $lei_out, $lei_err);
 use autodie qw(chdir close fcntl open opendir seek unlink);
 
 $_ = File::Spec->rel2abs($_) for (grep(!m!^/!, @INC));
@@ -410,15 +410,12 @@ sub run_script ($;$$) {
                local $SIG{FPE} = 'IGNORE'; # Perl default
                local $0 = join(' ', @$cmd);
                my $orig_io = _prepare_redirects($fhref);
-               my $cwdfh = $lei_cwdfh;
-               if (my $d = $opt->{'-C'}) {
-                       $cwdfh or opendir $cwdfh, '.';
-                       chdir $d;
-               }
+               opendir(my $cwdfh, '.');
+               chdir $opt->{-C} if defined $opt->{-C};
                _run_sub($sub, $key, \@argv);
                # n.b. all our uses of PublicInbox::DS should be fine
                # with this and we can't Reset here.
-               chdir($cwdfh) if $cwdfh;
+               chdir($cwdfh);
                _undo_redirects($orig_io);
                select STDOUT;
                umask($umask);
@@ -672,9 +669,7 @@ sub test_lei {
 SKIP: {
        my ($cb) = pop @_;
        my $test_opt = shift // {};
-       local $lei_cwdfh;
        use autodie qw(mkdir);
-       opendir $lei_cwdfh, '.';
        require_git(2.6, 1);
        my $mods = $test_opt->{mods} // [ 'lei' ];
        require_mods(@$mods, 2);