diff --git a/bibcop.pl b/bibcop.pl index 08a0a57..bbbb3f2 100755 --- a/bibcop.pl +++ b/bibcop.pl @@ -26,8 +26,8 @@ package bibcop; use warnings; use strict; +use POSIX; use File::Basename; -use Time::Piece; # Hash of incoming command line arguments. my %args = map { $_ => 1 } @ARGV; @@ -543,7 +543,7 @@ sub entry_fix { } my $value = clean_tex($entry{$tag}); if ($tag eq 'url') { - my $today = localtime->strftime('%d-%m-%Y'); + my $today = strftime('%d-%m-%Y', localtime(time)); push(@lines, " howpublished = {\\url{$value}},"); push(@lines, " note = {[Online; accessed $today]},"); next; diff --git a/perl-tests/entry_fixing.pl b/perl-tests/entry_fixing.pl index e81c0c2..bcf935a 100755 --- a/perl-tests/entry_fixing.pl +++ b/perl-tests/entry_fixing.pl @@ -25,14 +25,15 @@ package bibcop; use strict; use warnings; -use Time::Piece; + +use POSIX; require './bibcop.pl'; fixes_entry({':name' => 'knuth78', ':type' => 'book', 'title' => 'The TeX Book'}, "\@book{knuth78,\n title = {{The TeX Book}},\n}\n\n"); fixes_entry({':name' => 'k', ':type' => 'article', 'title' => 'Book', 'pages' => ''}, "\@article{k,\n title = {{Book}},\n}\n\n"); -my $today = localtime->strftime('%d-%m-%Y'); +my $today = strftime('%d-%m-%Y', localtime(time)); fixes_entry({':name' => 'f', ':type' => 'misc', 'url' => 'http://google.com'}, "\@misc{f,\n howpublished = {\\url{http://google.com}},\n note = {[Online; accessed $today]},\n}\n\n"); fixes_entry({':name' => 'f', ':type' => 'article', 'booktitle' => 'ONE'}, "\@article{f,\n journal = {{ONE}},\n}\n\n"); diff --git a/perl-tests/functions.pl b/perl-tests/functions.pl index 10bc8b5..8d8f925 100755 --- a/perl-tests/functions.pl +++ b/perl-tests/functions.pl @@ -26,12 +26,12 @@ package bibcop; use strict; use warnings; -assert(clean_tex('Hello, \LaTeX{}!'), 'Hello, \LaTeX{}!'); -assert(clean_tex("Hello,\n\\TeX{}!"), 'Hello, \TeX{}!'); -assert(clean_tex(" Gamma!"), 'Gamma!'); -assert(clean_tex("Hello! "), 'Hello!'); -assert(clean_tex('{Alpha}'), 'Alpha'); -assert(clean_tex('{{Beta}}'), 'Beta'); -assert(clean_tex('Hello, {world!}'), 'Hello, {world!}'); +assert_eq(clean_tex('Hello, \LaTeX{}!'), 'Hello, \LaTeX{}!'); +assert_eq(clean_tex("Hello,\n\\TeX{}!"), 'Hello, \TeX{}!'); +assert_eq(clean_tex(" Gamma!"), 'Gamma!'); +assert_eq(clean_tex("Hello! "), 'Hello!'); +assert_eq(clean_tex('{Alpha}'), 'Alpha'); +assert_eq(clean_tex('{{Beta}}'), 'Beta'); +assert_eq(clean_tex('Hello, {world!}'), 'Hello, {world!}'); 1; \ No newline at end of file diff --git a/perl-tests/parsing.pl b/perl-tests/parsing.pl index c5e9b13..b61fe4c 100755 --- a/perl-tests/parsing.pl +++ b/perl-tests/parsing.pl @@ -28,56 +28,56 @@ package bibcop; my @i1 = entries('@Misc{knuth-1984:x, author ={Donald Knuth}, Title="The TeX Book "}'); # show(@i1); -assert(@i1+0, 1); -assert($i1[0]{':name'}, 'knuth-1984:x'); -assert($i1[0]{':type'}, 'Misc'); -assert($i1[0]{'author'}, 'Donald Knuth'); -assert($i1[0]{'title'}, 'The TeX Book '); +assert_eq(@i1+0, 1); +assert_eq($i1[0]{':name'}, 'knuth-1984:x'); +assert_eq($i1[0]{':type'}, 'Misc'); +assert_eq($i1[0]{'author'}, 'Donald Knuth'); +assert_eq($i1[0]{'title'}, 'The TeX Book '); my @i2 = entries('@misc{patrick, author={{Patrick S\:{u}skind}},}'); # show(@i2); -assert(@i2+0, 1); -assert($i2[0]{'author'}, '{Patrick S\:{u}skind}'); +assert_eq(@i2+0, 1); +assert_eq($i2[0]{'author'}, '{Patrick S\:{u}skind}'); my @i3 = entries('@misc{p1} @article{p2,author="Jeff"} '); # show(@i3); -assert(@i3+0, 2); -assert($i3[0]{':name'}, 'p1'); -assert($i3[1]{':name'}, 'p2'); -assert($i3[1]{'author'}, 'Jeff'); +assert_eq(@i3+0, 2); +assert_eq($i3[0]{':name'}, 'p1'); +assert_eq($i3[1]{':name'}, 'p2'); +assert_eq($i3[1]{'author'}, 'Jeff'); my @i4 = entries('@misc{x1, year = 1989 }'); # show(@i4); -assert(@i4+0, 1); -assert($i4[0]{'year'}, '1989'); +assert_eq(@i4+0, 1); +assert_eq($i4[0]{'year'}, '1989'); my @i5 = entries('@misc{x2,year=2021,}'); # show(@i5); -assert(@i5+0, 1); -assert($i5[0]{'year'}, '2021'); +assert_eq(@i5+0, 1); +assert_eq($i5[0]{'year'}, '2021'); my @i6 = entries('@misc{x2,year=2021,year=1989}'); # show(@i6); -assert(@i6+0, 1); -assert($i6[0]{'year'}, '2021'); +assert_eq(@i6+0, 1); +assert_eq($i6[0]{'year'}, '2021'); my @i7 = entries("\% a comment\n \@misc{7}\n"); # show(@i7); -assert(@i7+0, 1); +assert_eq(@i7+0, 1); my @i8 = entries("\@misc{foo33, title={It's 100\\% true!}}\n"); # show(@i8); -assert(@i8+0, 1); +assert_eq(@i8+0, 1); # These are all parsing errors -assert(entries('no bibs')+0, 0); -assert(entries('@misc{---}')+0, 0); -assert(entries('@misc{hello, ??}')+0, 0); +assert_eq(entries('no bibs')+0, 0); +assert_eq(entries('@misc{---}')+0, 0); +assert_eq(entries('@misc{hello, ??}')+0, 0); -assert(entries('')+0, 0); -assert(entries('@misc{k1,a={{x}{y}{}},b="{f}{x}",}')+0, 1); -assert(entries('@article{k1_34} @misc{do43ss,Title=,Year=1998}')+0, 2); -assert(entries("\@article{t1}\n\n\n\@misc{ff,year=1998}")+0, 2); -assert(entries('@misc{42i-88/7.7,a=hello}')+0, 1); +assert_eq(entries('')+0, 0); +assert_eq(entries('@misc{k1,a={{x}{y}{}},b="{f}{x}",}')+0, 1); +assert_eq(entries('@article{k1_34} @misc{do43ss,Title=,Year=1998}')+0, 2); +assert_eq(entries("\@article{t1}\n\n\n\@misc{ff,year=1998}")+0, 2); +assert_eq(entries('@misc{42i-88/7.7,a=hello}')+0, 1); 1; \ No newline at end of file diff --git a/tests.pl b/tests.pl index c0e6900..b124f0b 100755 --- a/tests.pl +++ b/tests.pl @@ -27,7 +27,7 @@ package bibcop; use strict; # Assert on the value and exit if error. -sub assert { +sub assert_eq { my ($l, $r) = @_; if ($l ne $r) { print "'$l' ne '$r'\n";