[libcxx-commits] [PATCH] D73487: [libcxx] [test] Coverage improvement for std::future_error::what().

Andrey Maksimov via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 27 08:15:04 PST 2020


amakc11 created this revision.
Herald added a reviewer: EricWF.
Herald added subscribers: libcxx-commits, ldionne, christof.
Herald added a project: libc++.

The call of this method is inside the `LIBCPP_ASSERT` macro that removes the call when running tests against other libraries. This patch moves the call out of the macro to achieve correct coverage. Also, the path adds the following library-independent checks:

1. each string returned by this method is not empty;
2. all returned strings are distinct.




Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73487

Files:
  libcxx/test/std/thread/futures/futures.future_error/what.pass.cpp


Index: libcxx/test/std/thread/futures/futures.future_error/what.pass.cpp
===================================================================
--- libcxx/test/std/thread/futures/futures.future_error/what.pass.cpp
+++ libcxx/test/std/thread/futures/futures.future_error/what.pass.cpp
@@ -24,31 +24,46 @@
 // const char* what() const throw();
 
 #include <future>
-#include <cstring>
+#include <string>
 #include <cassert>
 
 #include "test_macros.h"
 
 int main(int, char**)
 {
+    std::string s[4];
+
     {
         std::future_error f(std::make_error_code(std::future_errc::broken_promise));
-        LIBCPP_ASSERT(std::strcmp(f.what(), "The associated promise has been destructed prior "
-                      "to the associated state becoming ready.") == 0);
+        s[0] = std::string(f.what());
+        LIBCPP_ASSERT(s[0] == "The associated promise has been destructed prior "
+                      "to the associated state becoming ready.");
     }
     {
         std::future_error f(std::make_error_code(std::future_errc::future_already_retrieved));
-        LIBCPP_ASSERT(std::strcmp(f.what(), "The future has already been retrieved from "
-                      "the promise or packaged_task.") == 0);
+        s[1] = std::string(f.what());
+        LIBCPP_ASSERT(s[1] == "The future has already been retrieved from "
+                      "the promise or packaged_task.");
     }
     {
         std::future_error f(std::make_error_code(std::future_errc::promise_already_satisfied));
-        LIBCPP_ASSERT(std::strcmp(f.what(), "The state of the promise has already been set.") == 0);
+        s[2] = std::string(f.what());
+        LIBCPP_ASSERT(s[2] == "The state of the promise has already been set.");
     }
     {
         std::future_error f(std::make_error_code(std::future_errc::no_state));
-        LIBCPP_ASSERT(std::strcmp(f.what(), "Operation not permitted on an object without "
-                      "an associated state.") == 0);
+        s[3] = std::string(f.what());
+        LIBCPP_ASSERT(s[3] == "Operation not permitted on an object without "
+                      "an associated state.");
+    }
+
+    for ( int i = 0; i < 4; i++ )
+    {
+        assert(s[i].length() != 0);
+        for ( int j = i+1; j < 4; j++ )
+        {
+            assert(s[i].compare(s[j]) != 0);
+        }
     }
 
   return 0;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73487.240592.patch
Type: text/x-patch
Size: 2349 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200127/99ab046b/attachment-0001.bin>


More information about the libcxx-commits mailing list