-my $test_external = sub {
- $setup_publicinboxes->();
- $cleanup->();
- $lei->('ls-external');
- is($out.$err, '', 'ls-external no output, yet');
- ok(!-e $config_file && !-e $store_dir,
- 'nothing created by ls-external');
-
- my $cfg = PublicInbox::Config->new;
- $cfg->each_inbox(sub {
- my ($ibx) = @_;
- ok($lei->(qw(add-external -q), $ibx->{inboxdir}),
- 'added external');
- is($out.$err, '', 'no output');
- });
- ok(-s $config_file && -e $store_dir,
- 'add-external created config + store');
- my $lcfg = PublicInbox::Config->new($config_file);
- $cfg->each_inbox(sub {
- my ($ibx) = @_;
- is($lcfg->{"external.$ibx->{inboxdir}.boost"}, 0,
- "configured boost on $ibx->{name}");
- });
- $lei->('ls-external');
- like($out, qr/boost=0\n/s, 'ls-external has output');
-
- ok(!$lei->(qw(q s:prefix -o /dev/null -f maildir)), 'bad maildir');
- like($err, qr!/dev/null exists and is not a directory!,
- 'error shown');
- is($? >> 8, 1, 'errored out with exit 1');
-
- ok(!$lei->(qw(q s:prefix -f mboxcl2 -o), $home), 'bad mbox');
- like($err, qr!\Q$home\E exists and is not a writable file!,
- 'error shown');
- is($? >> 8, 1, 'errored out with exit 1');
-
- ok(!$lei->(qw(q s:prefix -o /dev/stdout -f Mbox2)), 'bad format');
- like($err, qr/bad mbox --format=mbox2/, 'error shown');
- is($? >> 8, 1, 'errored out with exit 1');
-
- # note, on a Bourne shell users should be able to use either:
- # s:"use boolean prefix"
- # "s:use boolean prefix"
- # or use single quotes, it should not matter. Users only need
- # to know shell quoting rules, not Xapian quoting rules.
- # No double-quoting should be imposed on users on the CLI
- $lei->('q', 's:use boolean prefix');
- like($out, qr/search: use boolean prefix/, 'phrase search got result');
- require IO::Uncompress::Gunzip;
- for my $sfx ('', '.gz') {
- my $f = "$home/mbox$sfx";
- $lei->('q', '-o', "mboxcl2:$f", 's:use boolean prefix');
- my $cat = $sfx eq '' ? sub {
- open my $mb, '<', $f or fail "no mbox: $!";
- <$mb>
- } : sub {
- my $z = IO::Uncompress::Gunzip->new($f, MultiStream=>1);
- <$z>;
- };
- my @s = grep(/^Subject:/, $cat->());
- is(scalar(@s), 1, "1 result in mbox$sfx");
- $lei->('q', '-a', '-o', "mboxcl2:$f", 's:see attachment');
- is($err, '', 'no errors from augment');
- @s = grep(/^Subject:/, my @wtf = $cat->());
- is(scalar(@s), 2, "2 results in mbox$sfx");
-
- $lei->('q', '-a', '-o', "mboxcl2:$f", 's:nonexistent');
- is($err, '', "no errors on no results ($sfx)");
-
- my @s2 = grep(/^Subject:/, $cat->());
- is_deeply(\@s2, \@s,
- "same 2 old results w/ --augment and bad search $sfx");
-
- $lei->('q', '-o', "mboxcl2:$f", 's:nonexistent');
- my @res = $cat->();
- is_deeply(\@res, [], "clobber w/o --augment $sfx");
+my $test_fail = sub {
+ lei('q', 'whatever', '-C', '/dev/null');
+ is($? >> 8, 1, 'chdir at end fails to /dev/null');
+ lei('-C', '/dev/null', 'q', 'whatever');
+ is($? >> 8, 1, 'chdir at beginning fails to /dev/null');
+
+ lei_ok('q', "foo\n");
+ like($lei_err, qr/trailing `\\n' removed/s, "noted `\\n' removal");
+
+ for my $lk (qw(ei inbox)) {
+ my $d = "$home/newline\n$lk";
+ mkdir $d;
+ open my $fh, '>', "$d/$lk.lock" or BAIL_OUT "open $d/$lk.lock";
+ for my $fl (qw(-I --only)) {
+ ok(!lei('q', $fl, $d, 'whatever'),
+ "newline $lk.lock fails with q $fl");
+ like($lei_err, qr/`\\n' not allowed/,
+ "error noted with q $fl");
+ }