| 498 | // directory_iterator_tests --------------------------------------------------------// |
| 499 | |
| 500 | void directory_iterator_tests() |
| 501 | { |
| 502 | cout << "directory_iterator_tests..." << endl; |
| 503 | |
| 504 | bool dir_itr_exception(false); |
| 505 | try |
| 506 | { |
| 507 | fs::directory_iterator it(""); |
| 508 | } |
| 509 | catch (const fs::filesystem_error&) |
| 510 | { |
| 511 | dir_itr_exception = true; |
| 512 | } |
| 513 | BOOST_TEST(dir_itr_exception); |
| 514 | |
| 515 | error_code ec; |
| 516 | |
| 517 | BOOST_TEST(!ec); |
| 518 | fs::directory_iterator it("", ec); |
| 519 | BOOST_TEST(ec); |
| 520 | |
| 521 | dir_itr_exception = false; |
| 522 | try |
| 523 | { |
| 524 | fs::directory_iterator itx("nosuchdirectory"); |
| 525 | } |
| 526 | catch (const fs::filesystem_error&) |
| 527 | { |
| 528 | dir_itr_exception = true; |
| 529 | } |
| 530 | BOOST_TEST(dir_itr_exception); |
| 531 | |
| 532 | ec.clear(); |
| 533 | fs::directory_iterator it2x("nosuchdirectory", ec); |
| 534 | BOOST_TEST(ec); |
| 535 | |
| 536 | dir_itr_exception = false; |
| 537 | try |
| 538 | { |
| 539 | error_code ecx; |
| 540 | fs::directory_iterator itx("nosuchdirectory", ecx); |
| 541 | BOOST_TEST(ecx); |
| 542 | BOOST_TEST(ecx == boost::system::errc::no_such_file_or_directory); |
| 543 | } |
| 544 | catch (const fs::filesystem_error&) |
| 545 | { |
| 546 | dir_itr_exception = true; |
| 547 | } |
| 548 | BOOST_TEST(!dir_itr_exception); |
| 549 | |
| 550 | // create a second directory named d2 |
| 551 | d2 = dir / "d2"; |
| 552 | fs::create_directory(d2); |
| 553 | BOOST_TEST(fs::exists(d2)); |
| 554 | BOOST_TEST(fs::is_directory(d2)); |
| 555 | |
| 556 | // test the basic operation of directory_iterators, and test that |
| 557 | // stepping one iterator doesn't affect a different iterator. |
no test coverage detected