From: Daniel Karbach Date: Mon, 18 Dec 2017 10:01:27 +0000 (+0100) Subject: extended filesystem test X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=23f1f41fbff03520bb291e42b0407e0ca0bd4cc9;p=blobs.git extended filesystem test --- diff --git a/src/io/filesystem.cpp b/src/io/filesystem.cpp index feb1cac..c916e15 100644 --- a/src/io/filesystem.cpp +++ b/src/io/filesystem.cpp @@ -186,6 +186,9 @@ bool remove_dir(const std::string &path) { #else DIR *dir = opendir(path.c_str()); + if (!dir) { + return errno == ENOENT; + } for (dirent *entry = readdir(dir); entry != nullptr; entry = readdir(dir)) { if ( strncmp(entry->d_name, ".", 2) == 0 || diff --git a/tst/io/FilesystemTest.cpp b/tst/io/FilesystemTest.cpp index a098c2b..d19cfd1 100644 --- a/tst/io/FilesystemTest.cpp +++ b/tst/io/FilesystemTest.cpp @@ -82,8 +82,8 @@ void FilesystemTest::testDirectory() { const string test_file = test_subsubdir + "\\c.txt"; #else const string test_subdir = test_dir + "/a"; - const string test_subsubdir = test_subdir + "/b"; - const string test_file = test_subsubdir + "/c"; + const string test_subsubdir = test_subdir + "/b/"; + const string test_file = test_subsubdir + "c"; #endif CPPUNIT_ASSERT_MESSAGE( @@ -116,6 +116,9 @@ void FilesystemTest::testDirectory() { CPPUNIT_ASSERT_MESSAGE( "failed to create test subdirs", make_dirs(test_subsubdir)); + CPPUNIT_ASSERT_MESSAGE( + "creating an existing dir should silently succeed", + make_dirs(test_subsubdir)); CPPUNIT_ASSERT_MESSAGE( "created directory is a file", !is_file(test_subdir)); @@ -136,10 +139,13 @@ void FilesystemTest::testDirectory() { CPPUNIT_ASSERT_MESSAGE( "failed to create test file", is_file(test_file)); + CPPUNIT_ASSERT_MESSAGE( + "creating a dir where a regular file is should fail", + !make_dirs(test_file)); CPPUNIT_ASSERT_MESSAGE( - "failed to remove test subdir", - remove_dir(test_subdir)); + "failed to remove test dir", + remove_dir(test_dir)); CPPUNIT_ASSERT_MESSAGE( "removed directory became a file", !is_file(test_subdir));