Skip to content

Commit

Permalink
#31 exit code is 1 if bibcop.pl finds bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed May 19, 2023
1 parent cb33468 commit ab871af
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 441 deletions.
21 changes: 17 additions & 4 deletions bibcop.pl
Expand Up @@ -95,7 +95,7 @@ sub check_capitalization {
if ($pos eq 1) {
return "The minor word in the '$tag' must be upper-cased since it is the first one"
}
if (not @words[$pos - 2] =~ /^.*:$/) {
if (not $words[$pos - 2] =~ /^.*:$/) {
next;
}
return "The minor word in the '$tag' must be upper-cased, becuase it follows the colon"
Expand All @@ -104,7 +104,7 @@ sub check_capitalization {
if ($pos eq 1) {
next;
}
if (@words[$pos - 2] =~ /^.*:$/) {
if ($words[$pos - 2] =~ /^.*:$/) {
next;
}
return "All minor words in the '$tag' must be lower-cased, while '$word' (no.$pos) is not"
Expand Down Expand Up @@ -728,11 +728,10 @@ sub error {
my ($txt) = @_;
if (exists $args{'--latex'}) {
print "\\PackageError{bibcop}{$txt}{}\n";
exit 0;
} else {
print STDERR $txt . "\n";
exit 1;
}
fail();
}

# Print DEBUG message to the console.
Expand Down Expand Up @@ -766,6 +765,14 @@ sub warning {
}
}

sub fail {
if (exists $args{'--latex'}) {
exit(0);
} else {
exit(1);
}
}

if (@ARGV+0 eq 0 or exists $args{'--help'} or exists $args{'-?'}) {
info("Bibcop is a Style Checker of BibTeX Files\n\n" .
"Usage:\n" .
Expand Down Expand Up @@ -832,13 +839,19 @@ sub warning {
}
} else {
debug((@entries+0) . ' entries found in ' . $file);
my $found = 0;
for my $i (0..(@entries+0 - 1)) {
my %entry = %{ $entries[$i] };
debug("Checking $entry{':name'} (no.$i)...");
foreach my $err (process_entry(%entry)) {
warning("$err, in the '$entry{':name'}' entry");
$found += 1;
}
}
if ($found gt 0) {
debug("$found problem(s) found");
fail();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion perl-tests/checks.pl
Expand Up @@ -149,7 +149,7 @@ sub check_passes {
my ($f, %entry) = @_;
no strict 'refs';
my $error = $f->(%entry);
if ($error ne '') {
if (defined $error and $error ne '') {
show_entry(%entry);
print "$error\n";
print "$f reported an error here, why?\n";
Expand Down
16 changes: 8 additions & 8 deletions perl-tests/cli.pl
Expand Up @@ -29,26 +29,26 @@ package bibcop;
assert_exec('-v', 0, qr/[0-9]+\.[0-9]+\.[0-9]+/s);
assert_exec('--help', 0, qr/\Q--version \E/s);
assert_exec('-?', 0, qr/\QUsage:\E/s);
assert_exec('./test-files/test.bib', 0, qr/\QThe 'title' must be wrapped\E/s);
assert_exec('./test-files/test.bib', 1, qr/\QThe 'title' must be wrapped\E/s);
assert_exec('--no:wraps ./test-files/test.bib', 0, qr//s);
assert_exec('--verbose ./test-files/test.bib', 0, qr/\QChecking knuth1974\E/s);
assert_exec('--verbose ./test-files/test.bib', 1, qr/\QChecking knuth1974\E/s);
assert_exec('--latex ./test-files/test.bib', 0, qr/\Q\PackageWarningNoLine{bibcop}{The 'title' must be wrapped\E/s);
assert_exec('--fix ./test-files/test.bib', 0, qr/\Q{{The TeX Book}}\E/s);
assert_exec('README.md', 0, qr/\QEach BibTeX entry must start with '@'\E/s);
assert_exec('--verbose README.md', 0, qr/\Q0 entries found in README.md\E/s);

assert_exec('missing-file.bib', 256, qr/\QCannot open file: missing-file.bib\E/s);
assert_exec('missing-file.bib', 1, qr/\QCannot open file: missing-file.bib\E/s);
assert_exec('--latex missing-file.bib', 0, qr/\Q\PackageError{bibcop}{Cannot open file: missing-file.bib}{}\E/s);
assert_exec('--fix', 256, qr/\QFile name must be specified\E/s);
assert_exec('--fix', 1, qr/\QFile name must be specified\E/s);

sub assert_exec {
my ($cmd, $e, $re) = @_;
my $args = "perl ./bibcop.pl ${cmd} 2>&1";
my $stdout = `$args 2>&1`;
my $exit = $?;
if ($exit ne $e) {
print "$stdout\n";
print "Exit code is $exit (not $e)\n";
my $exit = $? >> 8;
if ($exit != $e) {
print "---\n$stdout\n";
print "Exit code is $exit (not $e) for '$cmd'\n";
exit 1;
}
if (not $stdout =~ $re) {
Expand Down
3 changes: 3 additions & 0 deletions testfiles/biblatex.luatex.tlg
@@ -0,0 +1,3 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
LaTeX Warning: Citation 'dijkstra1968letters' on page 1 undefined on input line ....
3 changes: 3 additions & 0 deletions testfiles/biblatex.tlg
@@ -0,0 +1,3 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
LaTeX Warning: Citation 'dijkstra1968letters' on page 1 undefined on input line ....
3 changes: 3 additions & 0 deletions testfiles/biblatex.xetex.tlg
@@ -0,0 +1,3 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
LaTeX Warning: Citation 'dijkstra1968letters' on page 1 undefined on input line ....
165 changes: 3 additions & 162 deletions testfiles/bibtex.luatex.tlg
Expand Up @@ -2,173 +2,14 @@ This is a generated file for the l3build validation system.
Don't change this file in any respect.
LaTeX Warning: Citation `dijkstra1968letters' on page 1 undefined on input line ....
runsystem((perl ./bibcop.pl --verbose --latex 'main.bib') > iexec.tmp 2>&1; /bin/echo -n $?% >iexec.ret)...executed
(iexec.tmp
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <7> on input line ....
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <5> on input line ....
bibcop: 1 entries found in main.bib
(iexec.tmp bibcop: 1 entries found in main.bib
bibcop: Checking dijkstra1968letters (no.0)...
Package bibcop Warning: All minor words in the 'title' must be lower-cased, while 'To' (no.6) is not, in the 'dijkstra1968letters' entry.
Package bibcop Warning: A mandatory 'doi' tag for '@article' is missing among (author, journal, number, pages, publisher, title, volume, year), in the 'dijkstra1968letters' entry.
Package bibcop Warning: The 'title' must be wrapped in double curled brackets, in the 'dijkstra1968letters' entry.
bibcop: 3 problem(s) found
) iexec: The content of 'iexec.tmp' was included into the document
runsystem(rm iexec.tmp)...executed
runsystem(rm iexec.ret)...executed
bibcop: style checking finished for main.bib
(bibtex.bbl
Overfull \hbox (183.92479pt too wide) in paragraph at lines 1--1
[]\TU/lmr/m/n/10 Scalar value @words[...] bet-ter writ-ten as $\OML/cmm/m/it/10 words\OT1/cmr/m/n/10 [\OML/cmm/m/it/10 :::\OT1/cmr/m/n/10 ]\OML/cmm/m/it/10 at:=bibcop:plline\OT1/cmr/m/n/10 98\OML/cmm/m/it/10 :Scalarvalue\OT1/cmr/m/n/10 @\OML/cmm/m/it/10 words\OT1/cmr/m/n/10 [\OML/cmm/m/it/10 :::\OT1/cmr/m/n/10 ]\OML/cmm/m/it/10 betterwrittenas$\TU/lmr/m/n/10 words[...]
\hbox(7.5+2.5)x345.0, glue set - 1.0, direction TLT
.\localpar
..\localinterlinepenalty=0
..\localbrokenpenalty=0
..\localleftbox=null
..\localrightbox=null
.\hbox(0.0+0.0)x15.0, direction TLT
.\TU/lmr/m/n/10 S
.\TU/lmr/m/n/10 c
.\TU/lmr/m/n/10 a
.\TU/lmr/m/n/10 l
.\TU/lmr/m/n/10 a
.\TU/lmr/m/n/10 r
.\glue(\spaceskip) 3.33 plus 1.665 minus 1.11
.\TU/lmr/m/n/10 v
.\kern-0.56 (font)
.\TU/lmr/m/n/10 a
.\TU/lmr/m/n/10 l
.\TU/lmr/m/n/10 u
.\TU/lmr/m/n/10 e
.\glue(\spaceskip) 3.33 plus 1.665 minus 1.11
.\TU/lmr/m/n/10 @
.\TU/lmr/m/n/10 w
.\kern-0.28 (font)
.\TU/lmr/m/n/10 o
.\TU/lmr/m/n/10 r
.\TU/lmr/m/n/10 d
.\TU/lmr/m/n/10 s
.\TU/lmr/m/n/10 [
.\TU/lmr/m/n/10 .
.\TU/lmr/m/n/10 .
.\TU/lmr/m/n/10 .
.\TU/lmr/m/n/10 ]
.\glue(\spaceskip) 4.44 plus 4.99498 minus 0.37
.\TU/lmr/m/n/10 b
.\kern0.28 (font)
.\TU/lmr/m/n/10 e
.\TU/lmr/m/n/10 t
.\discretionary (penalty 50)
..< \TU/lmr/m/n/10 -
.\TU/lmr/m/n/10 t
.\TU/lmr/m/n/10 e
.\TU/lmr/m/n/10 r
.\glue(\spaceskip) 3.33 plus 1.665 minus 1.11
.\TU/lmr/m/n/10 w
.\TU/lmr/m/n/10 r
.\TU/lmr/m/n/10 i
.\TU/lmr/m/n/10 t
.\discretionary (penalty 50)
..< \TU/lmr/m/n/10 -
.\TU/lmr/m/n/10 t
.\TU/lmr/m/n/10 e
.\TU/lmr/m/n/10 n
.\glue(\spaceskip) 3.33 plus 1.665 minus 1.11
.\TU/lmr/m/n/10 a
.\TU/lmr/m/n/10 s
.\glue(\spaceskip) 3.33 plus 1.665 minus 1.11
.\mathon
.\OML/cmm/m/it/10 w
.\kern0.26909 (italic)
.\OML/cmm/m/it/10 o
.\OML/cmm/m/it/10 r
.\kern0.27779 (italic)
.\OML/cmm/m/it/10 d
.\OML/cmm/m/it/10 s
.\OT1/cmr/m/n/10 [
.\OML/cmm/m/it/10 :
.\OML/cmm/m/it/10 :
.\OML/cmm/m/it/10 :
.\OT1/cmr/m/n/10 ]
.\OML/cmm/m/it/10 a
.\OML/cmm/m/it/10 t
.\OML/cmm/m/it/10 :
.\OML/cmm/m/it/10 =
.\OML/cmm/m/it/10 b
.\OML/cmm/m/it/10 i
.\OML/cmm/m/it/10 b
.\OML/cmm/m/it/10 c
.\OML/cmm/m/it/10 o
.\OML/cmm/m/it/10 p
.\OML/cmm/m/it/10 :
.\OML/cmm/m/it/10 p
.\OML/cmm/m/it/10 l
.\kern0.19678 (italic)
.\OML/cmm/m/it/10 l
.\kern0.19678 (italic)
.\OML/cmm/m/it/10 i
.\OML/cmm/m/it/10 n
.\OML/cmm/m/it/10 e
.\OT1/cmr/m/n/10 9
.\OT1/cmr/m/n/10 8
.\OML/cmm/m/it/10 :
.\OML/cmm/m/it/10 S
.\kern0.57637 (italic)
.\OML/cmm/m/it/10 c
.\OML/cmm/m/it/10 a
.\OML/cmm/m/it/10 l
.\kern0.19678 (italic)
.\OML/cmm/m/it/10 a
.\OML/cmm/m/it/10 r
.\kern0.27779 (italic)
.\OML/cmm/m/it/10 v
.\kern0.35878 (italic)
.\OML/cmm/m/it/10 a
.\OML/cmm/m/it/10 l
.\kern0.19678 (italic)
.\OML/cmm/m/it/10 u
.\OML/cmm/m/it/10 e
.\OT1/cmr/m/n/10 @
.\OML/cmm/m/it/10 w
.\kern0.26909 (italic)
.\OML/cmm/m/it/10 o
.\OML/cmm/m/it/10 r
.\kern0.27779 (italic)
.\OML/cmm/m/it/10 d
.\OML/cmm/m/it/10 s
.\OT1/cmr/m/n/10 [
.\OML/cmm/m/it/10 :
.\OML/cmm/m/it/10 :
.\OML/cmm/m/it/10 :
.\OT1/cmr/m/n/10 ]
.\OML/cmm/m/it/10 b
.\OML/cmm/m/it/10 e
.\OML/cmm/m/it/10 t
.\OML/cmm/m/it/10 t
.\OML/cmm/m/it/10 e
.\OML/cmm/m/it/10 r
.\kern0.27779 (italic)
.\OML/cmm/m/it/10 w
.\kern0.26909 (italic)
.\OML/cmm/m/it/10 r
.\kern0.27779 (italic)
.\OML/cmm/m/it/10 i
.\OML/cmm/m/it/10 t
.\OML/cmm/m/it/10 t
.\OML/cmm/m/it/10 e
.\OML/cmm/m/it/10 n
.\OML/cmm/m/it/10 a
.\OML/cmm/m/it/10 s
.\mathoff
.\TU/lmr/m/n/10 w
.\kern-0.28 (font)
.\TU/lmr/m/n/10 o
.\TU/lmr/m/n/10 r
.\TU/lmr/m/n/10 d
.\TU/lmr/m/n/10 s
.\TU/lmr/m/n/10 [
.\TU/lmr/m/n/10 .
.\TU/lmr/m/n/10 .
.\TU/lmr/m/n/10 .
.\TU/lmr/m/n/10 ]
.\glue(\rightskip) 0.0
)
(bibtex.bbl)

0 comments on commit ab871af

Please sign in to comment.