1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
|
#!/usr/bin/env bash
test_description='basic command line usage.'
. ./test-lib.sh
################################################################
# FIXME: update with source already in db
# FIXME: add with prompting
################################################################
test_expect_code 1 'fail search without database' \
'xapers search tag:foo'
test_expect_code 1 'fail to add without file or source' \
'xapers add --tags=new'
test_begin_subtest 'add file without source'
xapers add \
--file=$DOC_DIR/1.pdf \
--tags=new,foo >OUTPUT
cat <<EOF >EXPECTED
id:1 [] {} (foo new) ""
EOF
test_expect_equal_file OUTPUT EXPECTED
test_expect_success 'new docdir exists' \
'test -d $XAPERS_ROOT/0000000001'
test_begin_subtest 'tag file exists'
cat <<EOF >EXPECTED
foo
new
EOF
test_expect_equal_file "$XAPERS_ROOT"/0000000001/tags EXPECTED
test_expect_code 1 'fail to add non-bibtex file as source' \
'xapers add \
--source=$DOC_DIR/1.pdf'
test_begin_subtest 'add bib without file'
xapers add \
--source=$DOC_DIR/2.bib \
--tags=new,bar >OUTPUT
cat <<EOF >EXPECTED
id:2 [doi:10.9999/FOO.1] {Good_Bad_Up_Down_Left_Right_et_al._2012} (bar new) "Multicolor cavity sadness"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'bib file exists and is correct'
cat <<EOF >EXPECTED
@article{Good_Bad_Up_Down_Left_Right_et_al._2012,
author = "Good, Bob and Bad, Sam and Up, Steve and Down, Joseph and Left, Aidan and Right, Kate and et al.",
title = "Multicolor cavity sadness",
volume = "29",
url = "http://dx.doi.org/10.9999/FOO.1",
DOI = "10.9999/FOO.1",
number = "10",
journal = "Journal of the Color Feelings",
publisher = "Optical Society of America",
year = "2012",
month = "Sep",
pages = "2092"
}
EOF
test_expect_equal_file "$XAPERS_ROOT"/0000000002/bibtex EXPECTED
test_begin_subtest 'add with file and bib'
xapers add \
--file=$DOC_DIR/3.pdf \
--source=$DOC_DIR/3.bib \
--tags=qux >OUTPUT
cat <<EOF >EXPECTED
id:3 [] {fake:1234} (qux) "When the liver meats the pavement"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_expect_code 1 'fail to add non-existant file' \
'xapers add --file=foo.pdf'
test_expect_code 1 'fail to add non-existant source' \
'xapers add --source=foo.bib'
test_expect_code 1 'fail to add non-bibtex file as source' \
'xapers add --source=$DOC_DIR/3.pdf'
test_expect_code 1 'fail to add source doc already associated with different doc' \
'xapers add --source=doi:10.9999/FOO.1 id:1'
test_begin_subtest 'update doc with bib'
xapers add --source=$DOC_DIR/1.bib id:1
xapers search id:1 >OUTPUT
cat <<EOF >EXPECTED
id:1 [arxiv:1234] {arxiv:1234} (foo new) "Creation of the Universe"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'update with different bib overwrites previous'
xapers add --source=$DOC_DIR/1a.bib id:1
xapers search id:1 >OUTPUT
cat <<EOF >EXPECTED
id:1 [arxiv:1235] {arxiv:1235} (foo new) "Creation of the γ-verses"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'previous source no longer in db'
xapers search arxiv:1234 >OUTPUT
cat <<EOF >EXPECTED
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'update doc with file'
xapers add \
--file=$DOC_DIR/2\ file.pdf \
doi:10.9999/FOO.1 >OUTPUT
cat <<EOF >EXPECTED
id:2 [doi:10.9999/FOO.1] {Good_Bad_Up_Down_Left_Right_et_al._2012} (bar new) "Multicolor cavity sadness"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'add bib without file'
xapers add \
--source=$DOC_DIR/4.bib \
--tags=new
cat <<EOF >EXPECTED
id:2 [doi:10.9999/FOO.1] {Good_Bad_Up_Down_Left_Right_et_al._2012} (bar new) "Multicolor cavity sadness"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'add file without source'
xapers add \
--file=$DOC_DIR/5.pdf \
--tags=new
cat <<EOF >EXPECTED
id:2 [doi:10.9999/FOO.1] {Good_Bad_Up_Down_Left_Right_et_al._2012} (bar new) "Multicolor cavity sadness"
EOF
test_expect_equal_file OUTPUT EXPECTED
################################################################
test_begin_subtest 'count all'
output=`xapers count`
test_expect_equal "$output" 5
test_begin_subtest 'count all (*)'
output=`xapers count '*'`
test_expect_equal "$output" 5
test_begin_subtest 'count search'
output=`xapers count tag:new`
test_expect_equal "$output" 4
test_expect_code 1 'fail search without query' \
'xapers search'
test_begin_subtest 'search all'
xapers search '*' >OUTPUT
cat <<EOF >EXPECTED
id:2 [doi:10.9999/FOO.1] {Good_Bad_Up_Down_Left_Right_et_al._2012} (bar new) "Multicolor cavity sadness"
id:1 [arxiv:1235] {arxiv:1235} (foo new) "Creation of the γ-verses"
id:3 [] {fake:1234} (qux) "When the liver meats the pavement"
id:4 [doi:10.9999/FOO.2] {30929234} (new) "The Circle and the Square: Forbidden Love"
id:5 [] {} (new) ""
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search all pipe'
xapers search '*' | cat >OUTPUT
cat <<EOF >EXPECTED
id:2 [doi:10.9999/FOO.1] {Good_Bad_Up_Down_Left_Right_et_al._2012} (bar new) "Multicolor cavity sadness"
id:1 [arxiv:1235] {arxiv:1235} (foo new) "Creation of the γ-verses"
id:3 [] {fake:1234} (qux) "When the liver meats the pavement"
id:4 [doi:10.9999/FOO.2] {30929234} (new) "The Circle and the Square: Forbidden Love"
id:5 [] {} (new) ""
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search all --limit'
xapers search --limit=3 '*' >OUTPUT
cat <<EOF >EXPECTED
id:2 [doi:10.9999/FOO.1] {Good_Bad_Up_Down_Left_Right_et_al._2012} (bar new) "Multicolor cavity sadness"
id:1 [arxiv:1235] {arxiv:1235} (foo new) "Creation of the γ-verses"
id:3 [] {fake:1234} (qux) "When the liver meats the pavement"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search text'
xapers search --output=summary lorem >OUTPUT
cat <<EOF >EXPECTED
id:5 [] {} (new) ""
id:1 [arxiv:1235] {arxiv:1235} (foo new) "Creation of the γ-verses"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search sort year'
xapers search --output=summary --sort=year lorem >OUTPUT
cat <<EOF >EXPECTED
id:1 [arxiv:1235] {arxiv:1235} (foo new) "Creation of the γ-verses"
id:5 [] {} (new) ""
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search prefix title:'
xapers search title:cavity >OUTPUT
cat <<EOF >EXPECTED
id:2 [doi:10.9999/FOO.1] {Good_Bad_Up_Down_Left_Right_et_al._2012} (bar new) "Multicolor cavity sadness"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search prefix author:'
xapers search author:cruise >OUTPUT
cat <<EOF >EXPECTED
id:1 [arxiv:1235] {arxiv:1235} (foo new) "Creation of the γ-verses"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search year'
xapers search y:1869 >OUTPUT
cat <<EOF >EXPECTED
id:4 [doi:10.9999/FOO.2] {30929234} (new) "The Circle and the Square: Forbidden Love"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search year (none)'
xapers search year:1868 >OUTPUT
cat <<EOF >EXPECTED
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search year range'
xapers search y:1980..2011 >OUTPUT
cat <<EOF >EXPECTED
id:1 [arxiv:1235] {arxiv:1235} (foo new) "Creation of the γ-verses"
id:3 [] {fake:1234} (qux) "When the liver meats the pavement"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search year open start'
xapers search year:..1990 >OUTPUT
cat <<EOF >EXPECTED
id:3 [] {fake:1234} (qux) "When the liver meats the pavement"
id:4 [doi:10.9999/FOO.2] {30929234} (new) "The Circle and the Square: Forbidden Love"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search year open end'
xapers search year:1900.. >OUTPUT
cat <<EOF >EXPECTED
id:2 [doi:10.9999/FOO.1] {Good_Bad_Up_Down_Left_Right_et_al._2012} (bar new) "Multicolor cavity sadness"
id:1 [arxiv:1235] {arxiv:1235} (foo new) "Creation of the γ-verses"
id:3 [] {fake:1234} (qux) "When the liver meats the pavement"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search prefix id:'
xapers search id:3 >OUTPUT
cat <<EOF >EXPECTED
id:3 [] {fake:1234} (qux) "When the liver meats the pavement"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search prefix <source>:'
xapers search doi:10.9999/FOO.1 >OUTPUT
cat <<EOF >EXPECTED
id:2 [doi:10.9999/FOO.1] {Good_Bad_Up_Down_Left_Right_et_al._2012} (bar new) "Multicolor cavity sadness"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search prefix bib:'
test_subtest_known_broken
xapers search key:Good_Bad_Up_Down_Left_Right_et_al._2012 >OUTPUT
cat <<EOF >EXPECTED
id:2 [doi:10.9999/FOO.1] {Good_Bad_Up_Down_Left_Right_et_al._2012} (bar new) "Multicolor cavity sadness"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search different prefix bib:'
xapers search key:fake:1234 >OUTPUT
cat <<EOF >EXPECTED
id:3 [] {fake:1234} (qux) "When the liver meats the pavement"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search prefix tag:'
xapers search tag:new >OUTPUT
cat <<EOF >EXPECTED
id:2 [doi:10.9999/FOO.1] {Good_Bad_Up_Down_Left_Right_et_al._2012} (bar new) "Multicolor cavity sadness"
id:1 [arxiv:1235] {arxiv:1235} (foo new) "Creation of the γ-verses"
id:4 [doi:10.9999/FOO.2] {30929234} (new) "The Circle and the Square: Forbidden Love"
id:5 [] {} (new) ""
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search --output=tags'
xapers search --output=tags tag:foo | sort >OUTPUT
cat <<EOF >EXPECTED
foo
new
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search --output=tags all'
xapers search --output=tags '*' | sort >OUTPUT
cat <<EOF >EXPECTED
bar
foo
new
qux
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search --output=sources'
xapers search --output=sources tag:bar >OUTPUT
cat <<EOF >EXPECTED
doi:10.9999/FOO.1
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search --output=sources all'
xapers search --output=sources '*' >OUTPUT
cat <<EOF >EXPECTED
arxiv:1235
doi:10.9999/FOO.1
doi:10.9999/FOO.2
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search --output=keys'
xapers search --output=keys tag:bar >OUTPUT
cat <<EOF >EXPECTED
Good_Bad_Up_Down_Left_Right_et_al._2012
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search --output=keys all'
xapers search --output=keys '*' >OUTPUT
cat <<EOF >EXPECTED
30929234
Good_Bad_Up_Down_Left_Right_et_al._2012
arxiv:1235
fake:1234
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search --output=files'
xapers search --output=files '*' | sed "s|$XAPERS_ROOT|XAPERS_ROOT|" >OUTPUT
cat <<EOF >EXPECTED
XAPERS_ROOT/0000000002/2 file.pdf
XAPERS_ROOT/0000000001/1.pdf
XAPERS_ROOT/0000000003/3.pdf
XAPERS_ROOT/0000000005/5.pdf
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'search --output=bibtex single'
xapers search --output=bibtex tag:foo | sed 's|\\_|_|g' | sed "s|$XAPERS_ROOT|XAPERS_ROOT|" >OUTPUT
cat <<EOF >EXPECTED
@article{arxiv:1235,
author = "Dole, Bob and Cruise, Tim",
title = "Creation of the γ-verses",
year = "2011",
eprint = "1235",
file = ":XAPERS_ROOT/0000000001/1.pdf:pdf"
}
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'bibtex multiple'
xapers bibtex tag:new | sed 's|\\_|_|g' | sed "s|$XAPERS_ROOT|XAPERS_ROOT|" >OUTPUT
cat <<EOF >EXPECTED
@article{Good_Bad_Up_Down_Left_Right_et_al._2012,
author = "Good, Bob and Bad, Sam and Up, Steve and Down, Joseph and Left, Aidan and Right, Kate and et al.",
title = "Multicolor cavity sadness",
volume = "29",
url = "http://dx.doi.org/10.9999/FOO.1",
DOI = "10.9999/FOO.1",
number = "10",
journal = "Journal of the Color Feelings",
publisher = "Optical Society of America",
year = "2012",
month = "Sep",
pages = "2092",
file = ":XAPERS_ROOT/0000000002/2 file.pdf:pdf"
}
@article{arxiv:1235,
author = "Dole, Bob and Cruise, Tim",
title = "Creation of the γ-verses",
year = "2011",
eprint = "1235",
file = ":XAPERS_ROOT/0000000001/1.pdf:pdf"
}
@article{30929234,
author = "Me and You and We Know, Everyone",
title = "The Circle and the Square: Forbidden Love",
url = "http://dx.doi.org/10.9999/FOO.2",
DOI = "10.9999/FOO.2",
journal = "Shaply Letters",
year = "1869"
}
EOF
test_expect_equal_file OUTPUT EXPECTED
################################################################
test_expect_code 1 'fail tag without operation' \
'xapers tag tag:foo'
test_expect_code 1 'fail tag without search' \
'xapers tag +baz'
test_begin_subtest 'add tag'
xapers tag +baz -- tag:foo
xapers search tag:baz >OUTPUT
cat <<EOF >EXPECTED
id:1 [arxiv:1235] {arxiv:1235} (baz foo new) "Creation of the γ-verses"
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'check tags added to tag file'
cat <<EOF >EXPECTED
baz
foo
new
EOF
test_expect_equal_file "$XAPERS_ROOT"/0000000001/tags EXPECTED
test_begin_subtest 'remove tag'
xapers tag -baz -- tag:baz
xapers search tag:baz >OUTPUT
cat <<EOF >EXPECTED
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'check tags removed from tag file'
cat <<EOF >EXPECTED
foo
new
EOF
test_expect_equal_file "$XAPERS_ROOT"/0000000001/tags EXPECTED
test_begin_subtest 'add and remove tags'
xapers tag -foo +zzz -- tag:foo and tag:zzz
xapers search tag:foo and tag:zzz >OUTPUT
cat <<EOF >EXPECTED
EOF
test_expect_equal_file OUTPUT EXPECTED
################################################################
rm -rf "$TMP_DIRECTORY"/export
test_expect_code 1 'fail export no query' \
'xapers export $TMP_DIRECTORY/export'
test_begin_subtest 'export all'
xapers export "$TMP_DIRECTORY"/export '*'
find "$TMP_DIRECTORY"/export -mindepth 1 | sed "s|$TMP_DIRECTORY|TMP_DIRECTORY|" | sort >OUTPUT
cat <<EOF | sort >EXPECTED
TMP_DIRECTORY/export/5.pdf
TMP_DIRECTORY/export/When_the_liver_meats_the_pavement.pdf
TMP_DIRECTORY/export/Multicolor_cavity_sadness.pdf
TMP_DIRECTORY/export/Creation_of_the_γ-verses.pdf
EOF
test_expect_equal_file OUTPUT EXPECTED
rm -rf "$TMP_DIRECTORY"/export
test_begin_subtest 'export query'
xapers export "$TMP_DIRECTORY"/export lorem
find "$TMP_DIRECTORY"/export -mindepth 1 | sed "s|$TMP_DIRECTORY|TMP_DIRECTORY|" | sort >OUTPUT
cat <<EOF | sort >EXPECTED
TMP_DIRECTORY/export/5.pdf
TMP_DIRECTORY/export/Creation_of_the_γ-verses.pdf
EOF
test_expect_equal_file OUTPUT EXPECTED
test_expect_success 'restore to existing db' \
"xapers restore"
test_begin_subtest 'database intact after restore'
xapers search '*' >OUTPUT
cat <<EOF >EXPECTED
id:2 [doi:10.9999/FOO.1] {Good_Bad_Up_Down_Left_Right_et_al._2012} (bar new) "Multicolor cavity sadness"
id:1 [arxiv:1235] {arxiv:1235} (foo new) "Creation of the γ-verses"
id:3 [] {fake:1234} (qux) "When the liver meats the pavement"
id:4 [doi:10.9999/FOO.2] {30929234} (new) "The Circle and the Square: Forbidden Love"
id:5 [] {} (new) ""
EOF
test_expect_equal_file OUTPUT EXPECTED
test_expect_code 1 'fail delete with no query' \
"xapers delete"
# purge the db from the root
rm -rf $XAPERS_ROOT/.xapers
test_expect_success 'restore purged db' \
"xapers restore"
test_begin_subtest 'database intact after restore'
xapers search '*' >OUTPUT
cat <<EOF >EXPECTED
id:2 [doi:10.9999/FOO.1] {Good_Bad_Up_Down_Left_Right_et_al._2012} (bar new) "Multicolor cavity sadness"
id:1 [arxiv:1235] {arxiv:1235} (foo new) "Creation of the γ-verses"
id:3 [] {fake:1234} (qux) "When the liver meats the pavement"
id:4 [doi:10.9999/FOO.2] {30929234} (new) "The Circle and the Square: Forbidden Love"
id:5 [] {} (new) ""
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'delete single document noprompt'
echo 'yes' | xapers delete id:2
xapers search '*' >OUTPUT
cat <<EOF >EXPECTED
id:1 [arxiv:1235] {arxiv:1235} (foo new) "Creation of the γ-verses"
id:3 [] {fake:1234} (qux) "When the liver meats the pavement"
id:4 [doi:10.9999/FOO.2] {30929234} (new) "The Circle and the Square: Forbidden Love"
id:5 [] {} (new) ""
EOF
test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest 'delete document search w/ prompt'
xapers delete --noprompt lorem
xapers search lorem >OUTPUT
cat <<EOF >EXPECTED
EOF
test_expect_equal_file OUTPUT EXPECTED
test_expect_code 1 'check for deleted docdirs' "
test -d $XAPERS_ROOT/0000000001 \
|| test -d $XAPERS_ROOT/0000000002 \
|| test -d $XAPERS_ROOT/0000000005
"
################################################################
test_done
|