summaryrefslogtreecommitdiffstats
path: root/libcxx/test/support/filesystem_test_helper.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/test/support/filesystem_test_helper.hpp')
-rw-r--r--libcxx/test/support/filesystem_test_helper.hpp60
1 files changed, 58 insertions, 2 deletions
diff --git a/libcxx/test/support/filesystem_test_helper.hpp b/libcxx/test/support/filesystem_test_helper.hpp
index 5a8a32a406c..e3f46a16af3 100644
--- a/libcxx/test/support/filesystem_test_helper.hpp
+++ b/libcxx/test/support/filesystem_test_helper.hpp
@@ -8,6 +8,9 @@
#include <fstream>
#include <random>
#include <chrono>
+#include <vector>
+
+#include "rapid-cxx-test.hpp"
// static test helpers
@@ -381,8 +384,39 @@ bool checkCollectionsEqualBackwards(
// We often need to test that the error_code was cleared if no error occurs
// this function returns an error_code which is set to an error that will
// never be returned by the filesystem functions.
-inline std::error_code GetTestEC() {
- return std::make_error_code(std::errc::address_family_not_supported);
+inline std::error_code GetTestEC(unsigned Idx = 0) {
+ using std::errc;
+ auto GetErrc = [&]() {
+ switch (Idx) {
+ case 0:
+ return errc::address_family_not_supported;
+ case 1:
+ return errc::address_not_available;
+ case 2:
+ return errc::address_in_use;
+ case 3:
+ return errc::argument_list_too_long;
+ default:
+ assert(false && "Idx out of range");
+ std::abort();
+ }
+ };
+ return std::make_error_code(GetErrc());
+}
+
+inline bool ErrorIsImp(const std::error_code& ec,
+ std::vector<std::errc> const& errors) {
+ for (auto errc : errors) {
+ if (ec == std::make_error_code(errc))
+ return true;
+ }
+ return false;
+}
+
+template <class... ErrcT>
+inline bool ErrorIs(const std::error_code& ec, std::errc First, ErrcT... Rest) {
+ std::vector<std::errc> errors = {First, Rest...};
+ return ErrorIsImp(ec, errors);
}
// Provide our own Sleep routine since std::this_thread::sleep_for is not
@@ -403,4 +437,26 @@ inline bool PathEq(fs::path const& LHS, fs::path const& RHS) {
return LHS.native() == RHS.native();
}
+struct ExceptionChecker {
+ std::vector<std::errc> expected_err_list;
+ fs::path expected_path1;
+ fs::path expected_path2;
+
+ template <class... ErrcT>
+ explicit ExceptionChecker(fs::path p, std::errc first_err, ErrcT... rest_err)
+ : expected_err_list({first_err, rest_err...}), expected_path1(p) {}
+
+ template <class... ErrcT>
+ explicit ExceptionChecker(fs::path p1, fs::path p2, std::errc first_err,
+ ErrcT... rest_err)
+ : expected_err_list({first_err, rest_err...}), expected_path1(p1),
+ expected_path2(p2) {}
+
+ void operator()(fs::filesystem_error const& Err) const {
+ TEST_CHECK(ErrorIsImp(Err.code(), expected_err_list));
+ TEST_CHECK(Err.path1() == expected_path1);
+ TEST_CHECK(Err.path2() == expected_path2);
+ }
+};
+
#endif /* FILESYSTEM_TEST_HELPER_HPP */
OpenPOWER on IntegriCloud