[libcxx-commits] [libcxx] e557b6a - [libc++] Remove uses of verbose_assert.h in Filesystem tests

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 20 13:57:13 PDT 2020


Author: Louis Dionne
Date: 2020-10-20T16:57:00-04:00
New Revision: e557b6a66d5476dd5b9905934099f5f7357310b8

URL: https://github.com/llvm/llvm-project/commit/e557b6a66d5476dd5b9905934099f5f7357310b8
DIFF: https://github.com/llvm/llvm-project/commit/e557b6a66d5476dd5b9905934099f5f7357310b8.diff

LOG: [libc++] Remove uses of verbose_assert.h in Filesystem tests

For a modest loss of debugability in the tests, this allows more tests
to run on platforms that do not have support for <iostream>.

Added: 
    

Modified: 
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.append.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.compare.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.modifiers/remove_filename.pass.cpp
    libcxx/test/std/input.output/filesystems/class.path/path.member/path.modifiers/replace_filename.pass.cpp

Removed: 
    libcxx/test/support/verbose_assert.h


################################################################################
diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.append.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.append.pass.cpp
index 5ce2d662f2be..465959ba87e3 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.append.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.append.pass.cpp
@@ -30,7 +30,6 @@
 #include "test_iterators.h"
 #include "count_new.h"
 #include "filesystem_test_helper.h"
-#include "verbose_assert.h"
 
 
 struct AppendOperatorTestcase {
@@ -108,7 +107,7 @@ void doAppendSourceAllocTest(AppendOperatorTestcase const& TC)
       DisableAllocationGuard g;
       LHS /= RHS;
     }
-    ASSERT_PRED(PathEq, LHS , E);
+    assert(PathEq(LHS, E));
   }
   // basic_string_view
   {
@@ -184,8 +183,7 @@ void doAppendSourceTest(AppendOperatorTestcase const& TC)
     path Result(L);
     Str RHS(R);
     path& Ref = (Result /= RHS);
-    ASSERT_EQ(Result, E)
-        << DISPLAY(L) << DISPLAY(R);
+    assert(Result == E);
     assert(&Ref == &Result);
   }
   {
@@ -229,8 +227,7 @@ void doAppendSourceTest(AppendOperatorTestcase const& TC)
     path LHS(L);
     Ptr RHS(R);
     path& Ref = LHS.append(RHS, StrEnd(RHS));
-    ASSERT_PRED(PathEq, LHS, E)
-        << DISPLAY(L) << DISPLAY(R);
+    assert(PathEq(LHS, E));
     assert(&Ref == &LHS);
   }
   // iterators
@@ -321,8 +318,7 @@ int main(int, char**)
       path LHS(LHS_In);
       path RHS(RHS_In);
       path& Res = (LHS /= RHS);
-      ASSERT_PRED(PathEq, Res, (const char*)TC.expect)
-          << DISPLAY(LHS_In) << DISPLAY(RHS_In);
+      assert(PathEq(Res, (const char*)TC.expect));
       assert(&Res == &LHS);
     }
     doAppendSourceTest<char>    (TC);

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.compare.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.compare.pass.cpp
index 80f563b4fb3b..cb579637a27b 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.compare.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.compare.pass.cpp
@@ -35,7 +35,6 @@
 #include "test_iterators.h"
 #include "count_new.h"
 #include "filesystem_test_helper.h"
-#include "verbose_assert.h"
 
 struct PathCompareTest {
   const char* LHS;
@@ -99,11 +98,10 @@ void test_compare_basic()
       int ret4 = normalize_ret(p1.compare(RV));
 
       g.release();
-      ASSERT_EQ(ret1, ret2);
-      ASSERT_EQ(ret1, ret3);
-      ASSERT_EQ(ret1, ret4);
-      ASSERT_EQ(ret1, E)
-          << DISPLAY(TC.LHS) << DISPLAY(TC.RHS);
+      assert(ret1 == ret2);
+      assert(ret1 == ret3);
+      assert(ret1 == ret4);
+      assert(ret1 == E);
 
       // check signatures
       ASSERT_NOEXCEPT(p1.compare(p2));

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp
index ff3a2d531a26..af58d4e70e9e 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.decompose/path.decompose.pass.cpp
@@ -44,15 +44,17 @@
 
 
 #include "filesystem_include.h"
+#include <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <iterator>
 #include <type_traits>
 #include <vector>
-#include <cassert>
 
 #include "test_macros.h"
 #include "test_iterators.h"
 #include "count_new.h"
 #include "filesystem_test_helper.h"
-#include "verbose_assert.h"
 
 struct ComparePathExact {
   bool operator()(fs::path const& LHS, std::string const& RHS) const {
@@ -120,46 +122,41 @@ void decompPathTest()
   using namespace fs;
   for (auto const & TC : PathTestCases) {
     fs::path p(TC.raw);
-    ASSERT(p == TC.raw);
+    assert(p == TC.raw);
 
-    ASSERT_EQ(p.root_path(), TC.root_path);
-    ASSERT_NEQ(p.has_root_path(), TC.root_path.empty());
+    assert(p.root_path() == TC.root_path);
+    assert(p.has_root_path() != TC.root_path.empty());
 
-    ASSERT(p.root_name().native().empty())
-        << DISPLAY(p.root_name());
-    ASSERT_EQ(p.root_name(),TC.root_name);
-    ASSERT_NEQ(p.has_root_name(), TC.root_name.empty());
+    assert(p.root_name().native().empty());
+    assert(p.root_name() == TC.root_name);
+    assert(p.has_root_name() != TC.root_name.empty());
 
-    ASSERT_EQ(p.root_directory(), TC.root_directory);
-    ASSERT_NEQ(p.has_root_directory(), TC.root_directory.empty());
+    assert(p.root_directory() == TC.root_directory);
+    assert(p.has_root_directory() != TC.root_directory.empty());
 
-    ASSERT_EQ(p.relative_path(), TC.relative_path);
-    ASSERT_NEQ(p.has_relative_path(), TC.relative_path.empty());
+    assert(p.relative_path() == TC.relative_path);
+    assert(p.has_relative_path() != TC.relative_path.empty());
 
-    ASSERT_EQ(p.parent_path(), TC.parent_path);
-    ASSERT_NEQ(p.has_parent_path(), TC.parent_path.empty());
+    assert(p.parent_path() == TC.parent_path);
+    assert(p.has_parent_path() != TC.parent_path.empty());
 
-    ASSERT_EQ(p.filename(), TC.filename);
-    ASSERT_NEQ(p.has_filename(), TC.filename.empty());
+    assert(p.filename() == TC.filename);
+    assert(p.has_filename() != TC.filename.empty());
 
-    ASSERT_EQ(p.is_absolute(), p.has_root_directory());
-    ASSERT_NEQ(p.is_relative(), p.is_absolute());
+    assert(p.is_absolute() == p.has_root_directory());
+    assert(p.is_relative() != p.is_absolute());
     if (p.empty())
-      ASSERT(p.is_relative());
+      assert(p.is_relative());
 
-    ASSERT_COLLECTION_EQ_COMP(
-        p.begin(), p.end(),
-        TC.elements.begin(), TC.elements.end(),
-        ComparePathExact()
-    );
-    // check backwards
+    assert(static_cast<std::size_t>(std::distance(p.begin(), p.end())) == TC.elements.size());
+    assert(std::equal(p.begin(), p.end(), TC.elements.begin(), ComparePathExact()));
 
+    // check backwards
     std::vector<fs::path> Parts;
     for (auto it = p.end(); it != p.begin(); )
       Parts.push_back(*--it);
-    ASSERT_COLLECTION_EQ_COMP(Parts.begin(), Parts.end(),
-                                 TC.elements.rbegin(), TC.elements.rend(),
-                              ComparePathExact());
+    assert(static_cast<std::size_t>(std::distance(Parts.begin(), Parts.end())) == TC.elements.size());
+    assert(std::equal(Parts.begin(), Parts.end(), TC.elements.rbegin(), ComparePathExact()));
   }
 }
 
@@ -191,17 +188,17 @@ void decompFilenameTest()
   using namespace fs;
   for (auto const & TC : FilenameTestCases) {
     fs::path p(TC.raw);
-    ASSERT_EQ(p, TC.raw);
+    assert(p == TC.raw);
     ASSERT_NOEXCEPT(p.empty());
 
-    ASSERT_EQ(p.filename(), TC.filename);
-    ASSERT_NEQ(p.has_filename(), TC.filename.empty());
+    assert(p.filename() == TC.filename);
+    assert(p.has_filename() != TC.filename.empty());
 
-    ASSERT_EQ(p.stem(), TC.stem);
-    ASSERT_NEQ(p.has_stem(), TC.stem.empty());
+    assert(p.stem() == TC.stem);
+    assert(p.has_stem() != TC.stem.empty());
 
-    ASSERT_EQ(p.extension(), TC.extension);
-    ASSERT_NEQ(p.has_extension(), TC.extension.empty());
+    assert(p.extension() == TC.extension);
+    assert(p.has_extension() != TC.extension.empty());
   }
 }
 

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.modifiers/remove_filename.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.modifiers/remove_filename.pass.cpp
index 24df4a867b61..df71bbe0ad5c 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.modifiers/remove_filename.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.modifiers/remove_filename.pass.cpp
@@ -22,7 +22,6 @@
 #include "test_iterators.h"
 #include "count_new.h"
 #include "filesystem_test_helper.h"
-#include "verbose_assert.h"
 
 struct RemoveFilenameTestcase {
   const char* value;
@@ -65,7 +64,7 @@ int main(int, char**)
     path p(p_orig);
     assert(p == TC.value);
     path& Ref = (p.remove_filename());
-    ASSERT_EQ(p, TC.expect) << DISPLAY(p_orig);
+    assert(p == TC.expect);
     assert(&Ref == &p);
     assert(!p.has_filename());
   }

diff  --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.modifiers/replace_filename.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.modifiers/replace_filename.pass.cpp
index e7c95eb14876..d9cdbcce8fdc 100644
--- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.modifiers/replace_filename.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.modifiers/replace_filename.pass.cpp
@@ -22,7 +22,6 @@
 #include "test_iterators.h"
 #include "count_new.h"
 #include "filesystem_test_helper.h"
-#include "verbose_assert.h"
 
 struct ReplaceFilenameTestcase {
   const char* value;
@@ -51,11 +50,9 @@ int main(int, char**)
   using namespace fs;
   for (auto const & TC : TestCases) {
     path p(TC.value);
-    ASSERT_EQ(p, TC.value);
-    path& Ref = (p.replace_filename(TC.filename));
-    ASSERT_EQ(p, TC.expect)
-        << DISPLAY(TC.value)
-        << DISPLAY(TC.filename);
+    assert(p == TC.value);
+    path& Ref = p.replace_filename(TC.filename);
+    assert(p == TC.expect);
     assert(&Ref == &p);
     // Tests Effects "as-if": remove_filename() append(filename)
     {
@@ -63,7 +60,7 @@ int main(int, char**)
       path replace(TC.filename);
       p2.remove_filename();
       p2 /= replace;
-      ASSERT_EQ(p, p2);
+      assert(p == p2);
     }
   }
 

diff  --git a/libcxx/test/support/verbose_assert.h b/libcxx/test/support/verbose_assert.h
deleted file mode 100644
index 353e71cfc67e..000000000000
--- a/libcxx/test/support/verbose_assert.h
+++ /dev/null
@@ -1,222 +0,0 @@
-#ifndef TEST_SUPPORT_VERBOSE_ASSERT
-#define TEST_SUPPORT_VERBOSE_ASSERT
-
-#include <iostream>
-#include <cstdio>
-#include <sstream>
-#include <string>
-#include "test_macros.h"
-
-namespace verbose_assert {
-
-typedef std::basic_ostream<char>&(EndLType)(std::basic_ostream<char>&);
-
-template <class Stream, class Tp,
-    class = decltype(std::declval<Stream&>() << std::declval<Tp const&>())>
-std::true_type IsStreamableImp(int);
-template <class Stream, class Tp> std::false_type IsStreamableImp(long);
-
-template <class Stream, class Tp>
-struct IsStreamable : decltype(IsStreamableImp<Stream, Tp>(0)) {};
-
-template <class Tp, int ST = (IsStreamable<decltype(std::cerr), Tp>::value ? 1
-        : (IsStreamable<decltype(std::wcerr), Tp>::value ? 2 : -1))>
-struct SelectStream {
-  static_assert(ST == -1, "specialization required for ST != -1");
-  static void Print(Tp const&) { std::clog << "Value Not Streamable!\n"; }
-};
-
-template <class Tp>
-struct SelectStream<Tp, 1> {
-  static void Print(Tp const& val) { std::cerr << val; }
-};
-
-template <class Tp>
-struct SelectStream<Tp, 2> {
-  static void Print(Tp const& val) { std::wcerr << val; }
-};
-
-struct AssertData {
-  AssertData(const char* xcheck, const char* xfile, const char* xfunc,
-             unsigned long xline, bool xpassed = true)
-      : passed(xpassed), check(xcheck), file(xfile), func(xfunc), line(xline),
-        msg() {}
-
-  AssertData& SetFailed(std::string xmsg = std::string()) {
-    msg = xmsg;
-    passed = false;
-    return *this;
-  }
-
-  void PrintFailed() const {
-    std::fprintf(stderr, "%s:%lu %s: Assertion '%s' failed.\n", file, line,
-                 func, check);
-    if (!msg.empty())
-      std::fprintf(stderr, "%s\n", msg.data());
-  }
-
-  bool passed;
-  const char* check;
-  const char* file;
-  const char* func;
-  unsigned long line;
-  std::string msg;
-};
-
-// AssertHandler is the class constructed by failing CHECK macros. AssertHandler
-// will log information about the failures and abort when it is destructed.
-class AssertHandler {
-public:
-  AssertHandler(AssertData const& Data)
-      : passed(Data.passed) {
-    if (!passed)
-      Data.PrintFailed();
-  }
-
-  ~AssertHandler() TEST_NOEXCEPT_FALSE {
-    if (!passed) {
-      error_log << std::endl;
-      std::abort();
-    }
-  }
-
-  class LogType {
-    friend class AssertHandler;
-
-    template <class Tp>
-    friend LogType& operator<<(LogType& log, Tp const& value) {
-      if (!log.is_disabled) {
-        SelectStream<Tp>::Print(value);
-      }
-      return log;
-    }
-
-    friend LogType& operator<<(LogType& log, EndLType* m) {
-      if (!log.is_disabled) {
-        SelectStream<EndLType*>::Print(m);
-      }
-      return log;
-    }
-
-  private:
-    LogType(bool disable) : is_disabled(disable) {}
-    bool is_disabled;
-
-    LogType(LogType const&);
-    LogType& operator=(LogType const&);
-  };
-
-  LogType& GetLog() {
-    if (passed)
-      return null_log;
-    return error_log;
-  }
-
-private:
-  static LogType null_log;
-  static LogType error_log;
-
-  AssertHandler& operator=(const AssertHandler&) = delete;
-  AssertHandler(const AssertHandler&) = delete;
-  AssertHandler() = delete;
-
-private:
-  bool passed;
-};
-
-AssertHandler::LogType AssertHandler::null_log(true);
-AssertHandler::LogType AssertHandler::error_log(false);
-
-template <class It1>
-std::string PrintRange(const char* Name, It1 F, It1 E) {
-  std::stringstream ss;
-  ss << "  " << Name << " = [";
-  while (F != E) {
-    ss << *F;
-    ++F;
-    if (F != E)
-      ss << ", ";
-  }
-  ss << "]\n";
-  return ss.str();
-}
-
-template <class Tp, class Up>
-std::string PrintMismatch(Tp const& LHS, Up const& RHS, int Elem) {
-  std::stringstream ss;
-  ss << "  Element " << Elem << " mismatched: `" << LHS << "` != `" << RHS
-     << "`!\n";
-  return ss.str();
-};
-
-struct EqualToComp {
-  template <class Tp, class Up>
-  bool operator()(Tp const& LHS, Up const& RHS) const {
-    return LHS == RHS;
-  }
-};
-
-template <class It1, class It2, class Comp>
-AssertData CheckCollectionsEqual(It1 F1, It1 E1, It2 F2, It2 E2,
-                                 AssertData Data, Comp C = EqualToComp()) {
-  const It1 F1Orig = F1;
-  const It2 F2Orig = F2;
-  bool Failed = false;
-  std::string ErrorMsg;
-  int Idx = 0;
-  while (F1 != E1 && F2 != E2) {
-    if (!(C(*F1, *F2))) {
-      ErrorMsg += PrintMismatch(*F1, *F2, Idx);
-      Failed = true;
-      break;
-    }
-    ++Idx;
-    ++F1;
-    ++F2;
-  }
-  if (!Failed && (F1 != E1 || F2 != E2)) {
-    ErrorMsg += "  Ranges have 
diff erent sizes!\n";
-    Failed = true;
-  }
-  if (Failed) {
-    ErrorMsg += PrintRange("LHS", F1Orig, E1);
-    ErrorMsg += PrintRange("RHS", F2Orig, E2);
-    Data.SetFailed(ErrorMsg);
-  }
-  return Data;
-}
-} // namespace verbose_assert
-
-#ifdef __GNUC__
-#define ASSERT_FN_NAME() __PRETTY_FUNCTION__
-#else
-#define ASSERT_FN_NAME() __func__
-#endif
-
-#define DISPLAY(...) "    " #__VA_ARGS__ " = " << (__VA_ARGS__) << "\n"
-
-#define ASSERT(...)                                                            \
-  ::verbose_assert::AssertHandler(::verbose_assert::AssertData(                \
-    #__VA_ARGS__, __FILE__, ASSERT_FN_NAME(), __LINE__,(__VA_ARGS__))).GetLog()
-
-#define ASSERT_EQ(LHS, RHS) \
-  ASSERT(LHS == RHS) << DISPLAY(LHS) << DISPLAY(RHS)
-#define ASSERT_NEQ(LHS, RHS) \
-  ASSERT(LHS != RHS) << DISPLAY(LHS) << DISPLAY(RHS)
-#define ASSERT_PRED(PRED, LHS, RHS) \
-  ASSERT(PRED(LHS, RHS)) << DISPLAY(LHS) << DISPLAY(RHS)
-
-#define ASSERT_COLLECTION_EQ_COMP(F1, E1, F2, E2, Comp)                        \
-  (::verbose_assert::AssertHandler(                                            \
-       ::verbose_assert::CheckCollectionsEqual(                                \
-           F1, E1, F2, E2,                                                     \
-           ::verbose_assert::AssertData("CheckCollectionsEqual(" #F1 ", " #E1  \
-                                        ", " #F2 ", " #E2 ")",                 \
-                                        __FILE__, ASSERT_FN_NAME(), __LINE__), \
-           Comp))                                                              \
-       .GetLog())
-
-#define ASSERT_COLLECTION_EQ(F1, E1, F2, E2)                                   \
-  ASSERT_COLLECTION_EQ_COMP(F1, E1, F2, E2, ::verbose_assert::EqualToComp())
-
-#endif


        


More information about the libcxx-commits mailing list