| 1 |
#!/usr/bin/env perl |
| 2 |
# ============================================================================= |
| 3 |
# |
| 4 |
# This file is part of BibTool. |
| 5 |
# It is distributed under the GNU General Public License. |
| 6 |
# See the file COPYING for details. |
| 7 |
# |
| 8 |
# (c) 2011-2020 Gerd Neugebauer |
| 9 |
# |
| 10 |
# Net: [email protected] |
| 11 |
# |
| 12 |
# This program is free software; you can redistribute it and/or modify |
| 13 |
# it under the terms of the GNU General Public License as published by |
| 14 |
# the Free Software Foundation; either version 2, or (at your option) |
| 15 |
# any later version. |
| 16 |
# |
| 17 |
# This program is distributed in the hope that it will be useful, |
| 18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 |
# GNU General Public License for more details. |
| 21 |
# |
| 22 |
# You should have received a copy of the GNU General Public License |
| 23 |
# along with this program; if not, write to the Free Software |
| 24 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 |
# |
| 26 |
#*============================================================================= |
| 27 |
|
| 28 |
=head1 NAME |
| 29 |
|
| 30 |
extract_file.t - Test suite for BibTool extract.file. |
| 31 |
|
| 32 |
=head1 SYNOPSIS |
| 33 |
|
| 34 |
extract_file.t |
| 35 |
|
| 36 |
=head1 DESCRIPTION |
| 37 |
|
| 38 |
This module contains some test cases. Running this module as program |
| 39 |
will run all test cases and print a summary for each. Optionally files |
| 40 |
*.out and *.err are left if the expected result does not match the |
| 41 |
actual result. |
| 42 |
|
| 43 |
=head1 OPTIONS |
| 44 |
|
| 45 |
none |
| 46 |
|
| 47 |
=head1 AUTHOR |
| 48 |
|
| 49 |
Gerd Neugebauer |
| 50 |
|
| 51 |
=cut |
| 52 |
|
| 53 |
use strict; |
| 54 |
use BUnit;use warnings; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
#------------------------------------------------------------------------------ |
| 59 |
BUnit::run(name => '_x_1', |
| 60 |
args => '-x xyzzy', |
| 61 |
expected_out => '', |
| 62 |
expected_err => <<__EOF__, |
| 63 |
|
| 64 |
*** BibTool ERROR: aux file xyzzy not found. |
| 65 |
__EOF__ |
| 66 |
); |
| 67 |
|
| 68 |
#------------------------------------------------------------------------------ |
| 69 |
BUnit::run(name => '_x_2', |
| 70 |
args => '-x _xyzzy.aux', |
| 71 |
prepare => sub { |
| 72 |
my $fd = new FileHandle("_xyzzy.aux",'w') || die "_xyzzy.aux: $!\n"; |
| 73 |
print $fd <<__EOF__; |
| 74 |
\\citation{whole-collection} |
| 75 |
\\bibstyle{alpha} |
| 76 |
\\bibdata{bib/xampl_s.bib} |
| 77 |
__EOF__ |
| 78 |
$fd->close(); |
| 79 |
}, |
| 80 |
post => sub { |
| 81 |
unlink('_xyzzy.aux'); |
| 82 |
}, |
| 83 |
expected_err => '', |
| 84 |
expected_out => <<__EOF__, |
| 85 |
|
| 86 |
\@Book{ whole-collection, |
| 87 |
title = "" |
| 88 |
} |
| 89 |
__EOF__ |
| 90 |
); |
| 91 |
|
| 92 |
#------------------------------------------------------------------------------ |
| 93 |
BUnit::run(name => '_x_3', |
| 94 |
args => '-x _xyzzy.aux', |
| 95 |
prepare => sub { |
| 96 |
my $fd = new FileHandle("_xyzzy.aux",'w') || die "_xyzzy.aux: $!\n"; |
| 97 |
print $fd <<__EOF__; |
| 98 |
\\citation{whole-collection} |
| 99 |
\\bibstyle{alpha} |
| 100 |
\\bibdata{bib/xampl_s.bib} |
| 101 |
\\relax |
| 102 |
__EOF__ |
| 103 |
$fd->close(); |
| 104 |
}, |
| 105 |
post => sub { |
| 106 |
unlink('_xyzzy.aux'); |
| 107 |
}, |
| 108 |
expected_err => '', |
| 109 |
expected_out => <<__EOF__, |
| 110 |
|
| 111 |
\@Book{ whole-collection, |
| 112 |
title = "" |
| 113 |
} |
| 114 |
__EOF__ |
| 115 |
); |
| 116 |
|
| 117 |
#------------------------------------------------------------------------------ |
| 118 |
BUnit::run(name => 'extract_file_1', |
| 119 |
args => '-- \'extract.file={xyzzy}\'', |
| 120 |
expected_out => '', |
| 121 |
expected_err => <<__EOF__, |
| 122 |
|
| 123 |
*** BibTool ERROR: aux file xyzzy not found. |
| 124 |
__EOF__ |
| 125 |
); |
| 126 |
|
| 127 |
#------------------------------------------------------------------------------ |
| 128 |
BUnit::run(name => 'extract_file_2', |
| 129 |
args => '-- \'extract.file={_xyzzy.aux}\'', |
| 130 |
prepare => sub { |
| 131 |
my $fd = new FileHandle("_xyzzy.aux",'w') || die "_xyzzy.aux: $!\n"; |
| 132 |
print $fd <<__EOF__; |
| 133 |
\\citation{whole-collection} |
| 134 |
\\bibstyle{alpha} |
| 135 |
\\bibdata{bib/xampl_s.bib} |
| 136 |
__EOF__ |
| 137 |
$fd->close(); |
| 138 |
}, |
| 139 |
post => sub { |
| 140 |
unlink('_xyzzy.aux'); |
| 141 |
}, |
| 142 |
expected_err => '', |
| 143 |
expected_out => <<__EOF__, |
| 144 |
\@STRING{acm = "The OX Association for Computing Machinery" } |
| 145 |
\@STRING{stoc = " Symposium on the Theory of Computing" } |
| 146 |
\@STRING{stoc-key= "OX" } |
| 147 |
|
| 148 |
\@Book{ whole-collection, |
| 149 |
title = "" |
| 150 |
} |
| 151 |
__EOF__ |
| 152 |
); |
| 153 |
|
| 154 |
#------------------------------------------------------------------------------ |
| 155 |
BUnit::run(name => 'extract_file_3', |
| 156 |
args => '-- \'extract.file={xyzzy}\'', |
| 157 |
expected_out => '', |
| 158 |
expected_err => <<__EOF__, |
| 159 |
|
| 160 |
*** BibTool ERROR: aux file xyzzy not found. |
| 161 |
__EOF__ |
| 162 |
); |
| 163 |
|
| 164 |
#------------------------------------------------------------------------------ |
| 165 |
BUnit::run(name => 'extract_file_4', |
| 166 |
args => '-- \'extract.file={_xyzzy.aux}\'', |
| 167 |
prepare => sub { |
| 168 |
my $fd = new FileHandle("_xyzzy.aux",'w') || die "_xyzzy.aux: $!\n"; |
| 169 |
print $fd <<__EOF__; |
| 170 |
\\citation{whole-collection} |
| 171 |
\\bibstyle{alpha} |
| 172 |
\\bibdata{bib/xampl_s.bib} |
| 173 |
\\relax |
| 174 |
__EOF__ |
| 175 |
$fd->close(); |
| 176 |
}, |
| 177 |
post => sub { |
| 178 |
unlink('_xyzzy.aux'); |
| 179 |
}, |
| 180 |
expected_err => '', |
| 181 |
expected_out => <<__EOF__, |
| 182 |
\@STRING{acm = "The OX Association for Computing Machinery" } |
| 183 |
\@STRING{stoc = " Symposium on the Theory of Computing" } |
| 184 |
\@STRING{stoc-key= "OX" } |
| 185 |
|
| 186 |
\@Book{ whole-collection, |
| 187 |
title = "" |
| 188 |
} |
| 189 |
__EOF__ |
| 190 |
); |
| 191 |
|
| 192 |
#------------------------------------------------------------------------------ |
| 193 |
BUnit::run(name => 'extract_file_5', |
| 194 |
args => '-- \'extract.file={_xyzzy.aux}\'', |
| 195 |
prepare => sub { |
| 196 |
my $fd = new FileHandle("_xyzzy.aux",'w') || die "_xyzzy.aux: $!\n"; |
| 197 |
print $fd <<__EOF__; |
| 198 |
\\citation{a} |
| 199 |
\\bibstyle{alpha} |
| 200 |
\\bibdata{_test.bib} |
| 201 |
__EOF__ |
| 202 |
$fd->close(); |
| 203 |
$fd = new FileHandle("_test.bib",'w') || die "_test.bib: $!\n"; |
| 204 |
print $fd <<__EOF__; |
| 205 |
\@string{sss="T" # t} |
| 206 |
\@string{t="ttt"#t2} |
| 207 |
\@string{t2="ttt"} |
| 208 |
\@Article{ a, |
| 209 |
author = sss, |
| 210 |
} |
| 211 |
__EOF__ |
| 212 |
$fd->close(); |
| 213 |
}, |
| 214 |
post => sub { |
| 215 |
unlink('_xyzzy.aux'); |
| 216 |
unlink('_test.aux'); |
| 217 |
}, |
| 218 |
expected_err => '', |
| 219 |
expected_out => <<__EOF__, |
| 220 |
\@STRING{t = "ttt" # t2 } |
| 221 |
\@STRING{t2 = "ttt" } |
| 222 |
\@STRING{sss = "T" # t } |
| 223 |
|
| 224 |
\@Article{ a, |
| 225 |
author = sss |
| 226 |
} |
| 227 |
__EOF__ |
| 228 |
); |
| 229 |
|
| 230 |
#------------------------------------------------------------------------------ |
| 231 |
BUnit::run(name => 'extract_file_6', |
| 232 |
args => '-- \'extract.file={_xyzzy.aux}\'', |
| 233 |
prepare => sub { |
| 234 |
my $fd = new FileHandle("_xyzzy.aux",'w') || die "_xyzzy.aux: $!\n"; |
| 235 |
print $fd <<__EOF__; |
| 236 |
\\citation{a} |
| 237 |
\\bibstyle{alpha} |
| 238 |
\\bibdata{_test.bib} |
| 239 |
\\relax |
| 240 |
__EOF__ |
| 241 |
$fd->close(); |
| 242 |
$fd = new FileHandle("_test.bib",'w') || die "_test.bib: $!\n"; |
| 243 |
print $fd <<__EOF__; |
| 244 |
\@string{sss="T" # t} |
| 245 |
\@string{t="ttt"#t2} |
| 246 |
\@string{t2="ttt"} |
| 247 |
\@Article{ a, |
| 248 |
author = sss, |
| 249 |
} |
| 250 |
__EOF__ |
| 251 |
$fd->close(); |
| 252 |
}, |
| 253 |
post => sub { |
| 254 |
unlink('_xyzzy.aux'); |
| 255 |
unlink('_test.aux'); |
| 256 |
}, |
| 257 |
expected_err => '', |
| 258 |
expected_out => <<__EOF__, |
| 259 |
\@STRING{t = "ttt" # t2 } |
| 260 |
\@STRING{t2 = "ttt" } |
| 261 |
\@STRING{sss = "T" # t } |
| 262 |
|
| 263 |
\@Article{ a, |
| 264 |
author = sss |
| 265 |
} |
| 266 |
__EOF__ |
| 267 |
); |
| 268 |
|
| 269 |
1; |
| 270 |
#------------------------------------------------------------------------------ |
| 271 |
# Local Variables: |
| 272 |
# mode: perl |
| 273 |
# End: |