]> Sergey Matveev's repositories - public-inbox.git/commitdiff
t/init.t: don't modify ~/.public-inbox/
authorEric Wong <e@yhbt.net>
Sun, 26 Jul 2020 09:03:15 +0000 (09:03 +0000)
committerEric Wong <e@yhbt.net>
Sun, 26 Jul 2020 23:46:37 +0000 (23:46 +0000)
Tests for failures should not leave junk temporary files lying
around in a users' ~/.public-inbox/.

On a side note, I'm not sure if PI_DIR is or was ever
necessary.  It's never been documented, so perhaps
using $HOME for this is better...

script/public-inbox-init
t/init.t

index 951338af019524cd1c4ce75a35aa78a468fd2803..b8d71f3512d2997736274a23921fe8f1ec91c04d 100755 (executable)
@@ -53,6 +53,7 @@ PublicInbox::Lock::lock_acquire($lock_obj);
 
 # git-config will operate on this (and rename on success):
 my ($fh, $pi_config_tmp) = tempfile('pi-init-XXXXXXXX', DIR => $dir);
+my $cfg_tmp = UnlinkMe->new($pi_config_tmp);
 
 # Now, we grab another lock to use git-config(1) locking, so it won't
 # wait on the lock, unlike some of our internal flock()-based locks.
@@ -176,6 +177,7 @@ if (defined $perm) {
 
 rename $pi_config_tmp, $pi_config or
        die "failed to rename `$pi_config_tmp' to `$pi_config': $!\n";
+delete $cfg_tmp->{file};
 $auto_unlink->DESTROY;
 
 package UnlinkMe;
index b8f17b5c4805c3338b4fe8476ac64757ed5b41ad..16581955435888ae3e5f7f80e7b1bf6e62a1568d 100644 (file)
--- a/t/init.t
+++ b/t/init.t
@@ -50,12 +50,15 @@ sub quiet_fail {
                '-init did not unlink lock on failure');
 }
 {
+       my $env = { PI_DIR => "$tmpdir/.public-inbox/" };
        my $rdr = { 2 => \(my $err = '') };
        my $cmd = [ '-init', 'alist', "$tmpdir/a\nlist",
                   qw(http://example.com/alist alist@example.com) ];
-       ok(!run_script($cmd, undef, $rdr),
+       ok(!run_script($cmd, $env, $rdr),
                'public-inbox-init rejects LF in inboxdir');
        like($err, qr/`\\n' not allowed in `/s, 'reported \\n');
+       is_deeply([glob("$tmpdir/.public-inbox/pi-init-*")], [],
+               'no junk files left behind');
 }
 
 SKIP: {