]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/TestCommon.pm
clone|--mirror: fix and test against pre-manifest WWW
[public-inbox.git] / lib / PublicInbox / TestCommon.pm
index d8346673b34e5c0fe6c155de8ee90df99ef97c7c..cd706e0eae2dafeedcc310d52e0e52b4b4d8e0dc 100644 (file)
@@ -18,7 +18,7 @@ BEGIN {
                run_script start_script key2sub xsys xsys_e xqx eml_load tick
                have_xapian_compact json_utf8 setup_public_inboxes create_inbox
                tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt
-               test_httpd xbail require_cmd);
+               test_httpd xbail require_cmd is_xdeeply);
        require Test::More;
        my @methods = grep(!/\W/, @Test::More::EXPORT);
        eval(join('', map { "*$_=\\&Test::More::$_;" } @methods));
@@ -316,8 +316,10 @@ sub run_script ($;$$) {
        } else { # localize and run everything in the same process:
                # note: "local *STDIN = *STDIN;" and so forth did not work in
                # old versions of perl
+               my $umask = umask;
                local %ENV = $env ? (%ENV, %$env) : %ENV;
-               local %SIG = %SIG;
+               local @SIG{keys %SIG} = map { undef } values %SIG;
+               local $SIG{FPE} = 'IGNORE'; # Perl default
                local $0 = join(' ', @$cmd);
                my $orig_io = _prepare_redirects($fhref);
                my $cwdfh = $lei_cwdfh;
@@ -332,6 +334,7 @@ sub run_script ($;$$) {
                die "fchdir(restore): $!" if $cwdfh && !chdir($cwdfh);
                _undo_redirects($orig_io);
                select STDOUT;
+               umask($umask);
        }
 
        # slurp the redirects back into user-supplied strings
@@ -466,6 +469,7 @@ sub start_script {
                        $ENV{LISTEN_PID} = $$;
                        $ENV{LISTEN_FDS} = $fds;
                }
+               if ($opt->{-C}) { chdir($opt->{-C}) or die "chdir: $!" }
                $0 = join(' ', @$cmd);
                if ($sub) {
                        eval { PublicInbox::DS->Reset };
@@ -520,6 +524,13 @@ sub json_utf8 () {
        state $x = ref(PublicInbox::Config->json)->new->utf8->canonical;
 }
 
+sub is_xdeeply ($$$) {
+       my ($x, $y, $desc) = @_;
+       my $ok = is_deeply($x, $y, $desc);
+       diag explain([$x, '!=', $y]) if !$ok;
+       $ok;
+}
+
 sub test_lei {
 SKIP: {
        my ($cb) = pop @_;
@@ -567,7 +578,10 @@ SKIP: {
                }
                local $ENV{XDG_RUNTIME_DIR} = $daemon_xrd;
                $cb->();
-               unless ($persist) {
+               if ($persist) { # remove before ~/.local gets removed
+                       File::Path::rmtree([glob("$home/*")]);
+                       File::Path::rmtree("$home/.config");
+               } else {
                        lei_ok(qw(daemon-pid), \"daemon-pid after $t");
                        chomp($daemon_pid = $lei_out);
                        if (!$daemon_pid) {
@@ -587,7 +601,7 @@ SKIP: {
                my $f = "$daemon_xrd/lei/errors.log";
                open my $fh, '<', $f or BAIL_OUT "$f: $!";
                my @l = <$fh>;
-               is_deeply(\@l, [],
+               is_xdeeply(\@l, [],
                        "$t daemon XDG_RUNTIME_DIR/lei/errors.log empty");
        }
 }; # SKIP if missing git 2.6+ || Xapian || SQLite || json