]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/solver_git.t
solver: check one git coderepo and inbox at a time
[public-inbox.git] / t / solver_git.t
index 92c073345a5e70926227d38b729932db2d0f60c9..6b0ed8d27677dcaecbf1ed5070f05ef481e43695 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2019 all contributors <meta@public-inbox.org>
+# Copyright (C) 2019-2020 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use warnings;
@@ -8,13 +8,14 @@ use PublicInbox::TestCommon;
 require_git(2.6);
 use PublicInbox::Spawn qw(popen_rd);
 require_mods(qw(DBD::SQLite Search::Xapian Plack::Util));
-chomp(my $git_dir = `git rev-parse --git-dir 2>/dev/null`);
-plan skip_all => "$0 must be run from a git working tree" if $?;
+my $git_dir = xqx([qw(git rev-parse --git-dir)], undef, {2 => \(my $null)});
+$? == 0 or plan skip_all => "$0 must be run from a git working tree";
+chomp $git_dir;
 
 # needed for alternates, and --absolute-git-dir is only in git 2.13+
 $git_dir = abs_path($git_dir);
 
-use_ok "PublicInbox::$_" for (qw(Inbox V2Writable MIME Git SolverGit WWW));
+use_ok "PublicInbox::$_" for (qw(Inbox V2Writable Git SolverGit WWW));
 
 my ($inboxdir, $for_destroy) = tmpdir();
 my $opts = {
@@ -28,21 +29,20 @@ my $im = PublicInbox::V2Writable->new($ibx, 1);
 $im->{parallel} = 0;
 
 my $deliver_patch = sub ($) {
-       open my $fh, '<', $_[0] or die "open: $!";
-       my $mime = PublicInbox::MIME->new(do { local $/; <$fh> });
-       $im->add($mime);
+       $im->add(eml_load($_[0]));
        $im->done;
 };
 
 $deliver_patch->('t/solve/0001-simple-mod.patch');
 my $v1_0_0_tag = 'cb7c42b1e15577ed2215356a2bf925aef59cdd8d';
+my $v1_0_0_tag_short = substr($v1_0_0_tag, 0, 16);
 
 my $git = PublicInbox::Git->new($git_dir);
 $ibx->{-repo_objs} = [ $git ];
 my $res;
 my $solver = PublicInbox::SolverGit->new($ibx, sub { $res = $_[0] });
 open my $log, '+>>', "$inboxdir/solve.log" or die "open: $!";
-my $psgi_env = { 'psgi.errors' => *STDERR, 'psgi.url_scheme' => 'http',
+my $psgi_env = { 'psgi.errors' => \*STDERR, 'psgi.url_scheme' => 'http',
                'HTTP_HOST' => 'example.com' };
 $solver->solve($psgi_env, $log, '69df7d5', {});
 ok($res, 'solved a blob!');
@@ -109,7 +109,8 @@ SKIP: {
        require_mods(@psgi, 7 + scalar(@psgi));
        use_ok($_) for @psgi;
        my $binfoo = "$inboxdir/binfoo.git";
-       system(qw(git init --bare -q), $binfoo) == 0 or die "git init: $?";
+       require PublicInbox::Import;
+       PublicInbox::Import::init_bare($binfoo);
        require_ok 'PublicInbox::ViewVCS';
        my $big_size = do {
                no warnings 'once';
@@ -173,7 +174,9 @@ EOF
                is($res->code, 404, 'failure with null OID');
 
                $res = $cb->(GET("/$name/$v1_0_0_tag/s/"));
-               is($res->code, 200, 'shows commit');
+               is($res->code, 200, 'shows commit (unabbreviated)');
+               $res = $cb->(GET("/$name/$v1_0_0_tag_short/s/"));
+               is($res->code, 200, 'shows commit (abbreviated)');
                while (my ($label, $size) = each %bin) {
                        $res = $cb->(GET("/$name/$oid{$label}/s/"));
                        is($res->code, 200, "$label binary file");