From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 8F72F1F5D7 for ; Mon, 30 Sep 2024 21:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1727731811; bh=rImPyQ2IVveoso74bUyMrLEmuncN0xmrj4Lw5dre240=; h=From:To:Subject:Date:In-Reply-To:References:From; b=z+11F2ybU3ufo3YACP1MsBT+NTAaIne4N4phutJaQC6VvVAQdtf5B8VcW1bbaTlmp 5OMhR2gHQvVZysJraHS68ln1KOZevsQjWElsat2tbdCuAG15wr3KiOT24pXMKcqRyp +9HQnApZZndLSbB1KRJm/ZdoUCbqQdeYywUiUlVE= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 6/6] t/{config,solver_git}: simplify error handling Date: Mon, 30 Sep 2024 21:30:08 +0000 Message-ID: <20240930213008.4014512-7-e@80x24.org> In-Reply-To: <20240930213008.4014512-1-e@80x24.org> References: <20240930213008.4014512-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: autodie and the newish PublicInbox::IO::write_file make error handling more consistent and less noisy to people reading the code. We'll also avoid testing `git config' set behavior of git(1) and instead bail out via `xsys_e()' if it fails unexpectedly due to hardware problems or bugs in git. --- t/config.t | 13 ++++++------- t/solver_git.t | 34 +++++++++++++++------------------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/t/config.t b/t/config.t index 956ad35c..85005df9 100644 --- a/t/config.t +++ b/t/config.t @@ -3,6 +3,7 @@ use v5.12; use PublicInbox::TestCommon; use PublicInbox::Import; +use PublicInbox::IO qw(write_file); use_ok 'PublicInbox'; ok(defined(eval('$PublicInbox::VERSION')), 'VERSION defined'); use_ok 'PublicInbox::Config'; @@ -12,13 +13,11 @@ my $validate_git_behavior = $ENV{TEST_VALIDATE_GIT_BEHAVIOR}; { my $f = "$tmpdir/bool_config"; - open my $fh, '>', $f; - print $fh <', $f, <git_config_dump($f); $validate_git_behavior and is(xqx([qw(git config -f), $f, qw(--bool imap.debug)]), @@ -32,7 +31,7 @@ EOM my $inboxdir = "$tmpdir/new\nline"; my @cmd = ('git', "--git-dir=$tmpdir", qw(config publicinbox.foo.inboxdir), $inboxdir); - is(xsys(@cmd), 0, "set config"); + xsys_e(@cmd); my $tmp = PublicInbox::Config->new("$tmpdir/config"); @@ -212,17 +211,17 @@ for my $s (@valid) { { my $f = "$tmpdir/ordered"; - open my $fh, '>', $f or die "open: $!"; + open my $fh, '>', $f; my @expect; foreach my $i (0..3) { push @expect, "$i"; - print $fh <<"" or die "print: $!"; + print $fh <<""; [publicinbox "$i"] inboxdir = /path/to/$i.git address = $i\@example.com } - close $fh or die "close: $!"; + close $fh; my $cfg = PublicInbox::Config->new($f); my @result; $cfg->each_inbox(sub { push @result, $_[0]->{name} }); diff --git a/t/solver_git.t b/t/solver_git.t index 6cc5eeba..cebcf47f 100644 --- a/t/solver_git.t +++ b/t/solver_git.t @@ -9,7 +9,7 @@ use PublicInbox::ContentHash qw(git_sha); use PublicInbox::Spawn qw(run_qx which); use File::Path qw(remove_tree); use PublicInbox::IO qw(write_file); -use autodie qw(symlink unlink); +use autodie qw(close mkdir open rename symlink unlink); require_mods qw(DBD::SQLite Xapian); require PublicInbox::SolverGit; my $rdr = { 2 => \(my $null) }; @@ -35,8 +35,7 @@ my $ibx = create_inbox 'v2', version => 2, }; my $md = "$tmpdir/md"; File::Path::make_path(map { $md.$_ } (qw(/cur /new /tmp))); -symlink(abs_path('t/solve/0001-simple-mod.patch'), "$md/cur/foo:2,") or - xbail "symlink: $!"; +symlink abs_path('t/solve/0001-simple-mod.patch'), "$md/cur/foo:2,"; my $v1_0_0_rev = '8a918a8523bc9904123460f85999d75f6d604916'; my $v1_0_0_tag = 'cb7c42b1e15577ed2215356a2bf925aef59cdd8d'; @@ -45,7 +44,7 @@ my $expect = '69df7d565d49fbaaeb0a067910f03dc22cd52bd0'; my $non_existent = 'ee5e32211bf62ab6531bdf39b84b6920d0b6775a'; my $stderr_empty = sub { my ($msg) = @_; - open my $efh, '<', "$tmpdir/stderr.log" or xbail $!; + open my $efh, '<', "$tmpdir/stderr.log"; my @l = <$efh>; @l = grep(!/reverse ?proxy/i, @l); is_xdeeply(\@l, [], $msg // 'stderr.log is empty'); @@ -158,7 +157,7 @@ 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, '+>>', "$tmpdir/solve.log" or die "open: $!"; +open my $log, '+>>', "$tmpdir/solve.log"; my $psgi_env = { 'psgi.errors' => \*STDERR, 'psgi.url_scheme' => 'http', 'HTTP_HOST' => 'example.com' }; $solver->solve($psgi_env, $log, '69df7d5', {}); @@ -230,7 +229,7 @@ SKIP: { my $lk = PublicInbox::Lock->new($l); my $acq = $lk->lock_for_scope; my $stamp = "$binfoo/stamp-"; - if (open my $fh, '<', $stamp) { + if (CORE::open my $fh, '<', $stamp) { %oid = map { chomp; split(/=/, $_) } (<$fh>); } else { PublicInbox::Import::init_bare($binfoo); @@ -243,7 +242,7 @@ SKIP: { $oid{$label} = $x; } - open my $null, '<', '/dev/null' or xbail "open /dev/null: $!"; + open my $null, '<', '/dev/null'; my $t = xqx([qw(git mktree)], $env, { 0 => $null }); xbail "mktree: $?" if $?; chomp($t); @@ -264,20 +263,19 @@ SKIP: { chomp($c); $oid{'8859-parent'} = $c; - open my $fh, '>', "$stamp.$$" or BAIL_OUT; + open my $fh, '>', "$stamp.$$"; while (my ($k, $v) = each %oid) { - print $fh "$k=$v\n" or xbail "print: $!"; + print $fh "$k=$v\n"; } - close $fh or BAIL_OUT; - rename("$stamp.$$", $stamp) or BAIL_OUT; + close $fh; + rename "$stamp.$$", $stamp; } undef $acq; # ensure the PSGI frontend (ViewVCS) works: my $name = $ibx->{name}; my $cfgpfx = "publicinbox.$name"; my $cfgpath = "$tmpdir/httpd-config"; - open my $cfgfh, '>', $cfgpath or die; - print $cfgfh <', $cfgpath, <('nothing in stderr.log, yet'); } else { - open $olderr, '>&', \*STDERR or xbail "open: $!"; - open STDERR, '+>>', "$tmpdir/stderr.log" or - xbail "open: $!"; + open $olderr, '>&', \*STDERR; + open STDERR, '+>>', "$tmpdir/stderr.log"; } $res = $cb->(GET('/binfoo/')); defined($ENV{PLACK_TEST_EXTERNALSERVER_URI}) or - open STDERR, '>&', $olderr or xbail "open: $!"; + open STDERR, '>&', $olderr; is($res->code, 200, 'coderepo summary (binfoo)'); $stderr_empty->(); @@ -486,7 +482,7 @@ EOF test_httpd($env, $client, 7, sub { SKIP: { require_cmd('curl', 1) or skip 'no curl', 1; - mkdir "$tmpdir/ext" // xbail "mkdir $!"; + mkdir "$tmpdir/ext"; my $rurl = "$ENV{PLACK_TEST_EXTERNALSERVER_URI}/$name"; test_lei({tmpdir => "$tmpdir/ext"}, sub { lei_ok(qw(blob --no-mail 69df7d5 -I), $rurl);