diff options
author | Eric Wong <e@80x24.org> | 2023-09-24 05:42:14 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-09-24 18:56:18 +0000 |
commit | 21146412fdc32f8e6707b4e290ad715b35f20845 (patch) | |
tree | 53f4f32d1858ccae2ad8d24694da02cdc16ad9b4 /lib/PublicInbox | |
parent | f170d220f8765e952c9a102dd35eb694810739df (diff) | |
download | public-inbox-21146412fdc32f8e6707b4e290ad715b35f20845.tar.gz |
It's a needless branch to maintain exclusively for our tests. The `git config -l' output isn't pleasant to write in tests, anyways. So just use heredocs to write git configs in their native format rather than emulate the output of `git config -l'. This does make the test suite do more work with temporary files and process invocations, but it doesn't seem very measurable when testing on tmpfs (TMPDIR=/dev/shm). We'll make a minor improvement to TestCommon::tmpdir by allowing it to return a single value (which I suspect we can rely on in more places since File::Temp::Dir overloads stringification).
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r-- | lib/PublicInbox/Config.pm | 23 | ||||
-rw-r--r-- | lib/PublicInbox/TestCommon.pm | 20 |
2 files changed, 23 insertions, 20 deletions
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index 533f4a52..9f764c32 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -24,21 +24,14 @@ sub _array ($) { ref($_[0]) eq 'ARRAY' ? $_[0] : [ $_[0] ] } sub new { my ($class, $file, $lei) = @_; $file //= default_file(); - my $self; - my $set_dedupe; - if (ref($file) eq 'SCALAR') { # used by some tests - open my $fh, '<', $file or die; # PerlIO::scalar - $self = config_fh_parse($fh, "\n", '='); - bless $self, $class; - } else { - if (-f $file && $DEDUPE) { - $file = rel2abs_collapsed($file); - $self = $DEDUPE->{$file} and return $self; - $set_dedupe = 1; - } - $self = git_config_dump($class, $file, $lei); - $self->{'-f'} = $file; - } + my ($self, $set_dedupe); + if (-f $file && $DEDUPE) { + $file = rel2abs_collapsed($file); + $self = $DEDUPE->{$file} and return $self; + $set_dedupe = 1; + } + $self = git_config_dump($class, $file, $lei); + $self->{-f} = $file; # caches $self->{-by_addr} = {}; $self->{-by_list_id} = {}; diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index ae67a0ae..9ad181e2 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -26,7 +26,7 @@ BEGIN { create_coderepo no_scm_rights tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt test_httpd xbail require_cmd is_xdeeply tail_f - ignore_inline_c_missing no_pollerfd no_coredump); + ignore_inline_c_missing no_pollerfd no_coredump cfg_new); require Test::More; my @methods = grep(!/\W/, @Test::More::EXPORT); eval(join('', map { "*$_=\\&Test::More::$_;" } @methods)); @@ -46,11 +46,9 @@ sub eml_load ($) { sub tmpdir (;$) { my ($base) = @_; require File::Temp; - unless (defined $base) { - ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!); - } + ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!) unless defined $base; my $tmpdir = File::Temp->newdir("pi-$base-$$-XXXX", TMPDIR => 1); - ($tmpdir->dirname, $tmpdir); + wantarray ? ($tmpdir->dirname, $tmpdir) : $tmpdir; } sub tcp_server () { @@ -894,6 +892,18 @@ sub no_pollerfd ($) { is(grep(/$re/, @of), 0, "no $re FDs") or diag explain(\@of); } } + +sub cfg_new ($;@) { + my ($tmpdir, @body) = @_; + use autodie; + require PublicInbox::Config; + my $f = "$tmpdir/tmp_cfg"; + open my $fh, '>', $f; + print $fh @body; + close $fh; + PublicInbox::Config->new($f); +} + package PublicInbox::TestCommon::InboxWakeup; use strict; sub on_inbox_unlock { ${$_[0]}->($_[1]) } |