Format first-party source according to .clang-format

This commit is contained in:
Pretty Printer
2020-04-17 09:56:34 -05:00
committed by manojsdoshi
parent 65dfc5d19e
commit 50760c6935
1076 changed files with 86161 additions and 77449 deletions

View File

@@ -21,8 +21,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define TEST_UNIT_TEST_DIRGUARD_H
#include <ripple/basics/contract.h>
#include <test/jtx/TestSuite.h>
#include <boost/filesystem.hpp>
#include <test/jtx/TestSuite.h>
namespace ripple {
namespace test {
@@ -43,62 +43,62 @@ private:
protected:
beast::unit_test::suite& test_;
auto rmDir (path const& toRm)
auto
rmDir(path const& toRm)
{
if (is_directory (toRm) && is_empty (toRm))
remove (toRm);
if (is_directory(toRm) && is_empty(toRm))
remove(toRm);
else
test_.log << "Expected " << toRm.string ()
<< " to be an empty existing directory." << std::endl;
test_.log << "Expected " << toRm.string()
<< " to be an empty existing directory." << std::endl;
}
public:
DirGuard (beast::unit_test::suite& test, path subDir,
bool useCounter = true)
: subDir_ (std::move (subDir))
, test_ (test)
DirGuard(beast::unit_test::suite& test, path subDir, bool useCounter = true)
: subDir_(std::move(subDir)), test_(test)
{
using namespace boost::filesystem;
static auto subDirCounter = 0;
if (useCounter)
subDir_ += std::to_string(++subDirCounter);
if (!exists (subDir_))
if (!exists(subDir_))
{
create_directory (subDir_);
create_directory(subDir_);
rmSubDir_ = true;
}
else if (is_directory (subDir_))
else if (is_directory(subDir_))
rmSubDir_ = false;
else
{
// Cannot run the test. Someone created a file where we want to
// put our directory
Throw<std::runtime_error> (
"Cannot create directory: " + subDir_.string ());
Throw<std::runtime_error>(
"Cannot create directory: " + subDir_.string());
}
}
~DirGuard ()
~DirGuard()
{
try
{
using namespace boost::filesystem;
if (rmSubDir_)
rmDir (subDir_);
rmDir(subDir_);
else
test_.log << "Skipping rm dir: "
<< subDir_.string () << std::endl;
test_.log << "Skipping rm dir: " << subDir_.string()
<< std::endl;
}
catch (std::exception& e)
{
// if we throw here, just let it die.
test_.log << "Error in ~DirGuard: " << e.what () << std::endl;
test_.log << "Error in ~DirGuard: " << e.what() << std::endl;
};
}
path const& subdir() const
path const&
subdir() const
{
return subDir_;
}
@@ -114,66 +114,70 @@ protected:
bool created_ = false;
public:
FileDirGuard(beast::unit_test::suite& test,
path subDir, path file, std::string const& contents,
bool useCounter = true, bool create = true)
FileDirGuard(
beast::unit_test::suite& test,
path subDir,
path file,
std::string const& contents,
bool useCounter = true,
bool create = true)
: DirGuard(test, subDir, useCounter)
, file_(file.is_absolute() ? file : subdir() / file)
, file_(file.is_absolute() ? file : subdir() / file)
{
if (!exists (file_))
if (!exists(file_))
{
if (create)
{
std::ofstream o (file_.string ());
std::ofstream o(file_.string());
o << contents;
created_ = true;
}
}
else
{
Throw<std::runtime_error> (
"Refusing to overwrite existing file: " +
file_.string ());
Throw<std::runtime_error>(
"Refusing to overwrite existing file: " + file_.string());
}
}
~FileDirGuard ()
~FileDirGuard()
{
try
{
using namespace boost::filesystem;
if (exists (file_))
if (exists(file_))
{
remove (file_);
remove(file_);
}
else
{
if (created_)
test_.log << "Expected " << file_.string ()
<< " to be an existing file." << std::endl;
test_.log << "Expected " << file_.string()
<< " to be an existing file." << std::endl;
}
}
catch (std::exception& e)
{
// if we throw here, just let it die.
test_.log << "Error in ~FileGuard: "
<< e.what () << std::endl;
test_.log << "Error in ~FileGuard: " << e.what() << std::endl;
};
}
path const& file() const
path const&
file() const
{
return file_;
}
bool fileExists () const
bool
fileExists() const
{
return boost::filesystem::exists (file_);
return boost::filesystem::exists(file_);
}
};
}
}
}
} // namespace detail
} // namespace test
} // namespace ripple
#endif // TEST_UNIT_TEST_DIRGUARD_H
#endif // TEST_UNIT_TEST_DIRGUARD_H

View File

@@ -33,17 +33,17 @@ class SuiteJournalSink : public beast::Journal::Sink
beast::unit_test::suite& suite_;
public:
SuiteJournalSink(std::string const& partition,
beast::severities::Severity threshold,
beast::unit_test::suite& suite)
: Sink (threshold, false)
, partition_(partition + " ")
, suite_ (suite)
SuiteJournalSink(
std::string const& partition,
beast::severities::Severity threshold,
beast::unit_test::suite& suite)
: Sink(threshold, false), partition_(partition + " "), suite_(suite)
{
}
// For unit testing, always generate logging text.
inline bool active(beast::severities::Severity level) const override
inline bool
active(beast::severities::Severity level) const override
{
return true;
}
@@ -53,22 +53,29 @@ public:
};
inline void
SuiteJournalSink::write (
beast::severities::Severity level, std::string const& text)
SuiteJournalSink::write(
beast::severities::Severity level,
std::string const& text)
{
using namespace beast::severities;
char const* const s = [level]()
{
switch(level)
char const* const s = [level]() {
switch (level)
{
case kTrace: return "TRC:";
case kDebug: return "DBG:";
case kInfo: return "INF:";
case kWarning: return "WRN:";
case kError: return "ERR:";
default: break;
case kFatal: break;
case kTrace:
return "TRC:";
case kDebug:
return "DBG:";
case kInfo:
return "INF:";
case kWarning:
return "WRN:";
case kError:
return "ERR:";
default:
break;
case kFatal:
break;
}
return "FTL:";
}();
@@ -84,14 +91,17 @@ class SuiteJournal
beast::Journal journal_;
public:
SuiteJournal(std::string const& partition,
beast::unit_test::suite& suite,
beast::severities::Severity threshold = beast::severities::kFatal)
: sink_ (partition, threshold, suite)
, journal_ (sink_)
SuiteJournal(
std::string const& partition,
beast::unit_test::suite& suite,
beast::severities::Severity threshold = beast::severities::kFatal)
: sink_(partition, threshold, suite), journal_(sink_)
{
}
operator beast::Journal&() { return journal_; }
operator beast::Journal &()
{
return journal_;
}
};
// this sink can be used to create a custom journal
@@ -100,24 +110,30 @@ public:
class StreamSink : public beast::Journal::Sink
{
std::stringstream strm_;
public:
StreamSink (
StreamSink(
beast::severities::Severity threshold = beast::severities::kDebug)
: Sink (threshold, false) { }
: Sink(threshold, false)
{
}
void
write (beast::severities::Severity level,
std::string const& text) override
write(beast::severities::Severity level, std::string const& text) override
{
if (level < threshold())
return;
strm_ << text << std::endl;
}
std::stringstream const& messages() const { return strm_ ; }
std::stringstream const&
messages() const
{
return strm_;
}
};
} // test
} // ripple
} // namespace test
} // namespace ripple
#endif

View File

@@ -338,7 +338,9 @@ multi_runner_base<IsParent>::print_results(S& s)
template <bool IsParent>
void
multi_runner_base<IsParent>::message_queue_send(MessageType mt, std::string const& s)
multi_runner_base<IsParent>::message_queue_send(
MessageType mt,
std::string const& s)
{
// must use a mutex since the two "sends" must happen in order
std::lock_guard l{inner_->m_};
@@ -351,12 +353,11 @@ constexpr const char* multi_runner_base<IsParent>::shared_mem_name_;
template <bool IsParent>
constexpr const char* multi_runner_base<IsParent>::message_queue_name_;
} // detail
} // namespace detail
//------------------------------------------------------------------------------
multi_runner_parent::multi_runner_parent()
: os_(std::cout)
multi_runner_parent::multi_runner_parent() : os_(std::cout)
{
message_queue_thread_ = std::thread([this] {
std::vector<char> buf(1 << 20);
@@ -382,7 +383,7 @@ multi_runner_parent::multi_runner_parent()
buf.data(), buf.size(), recvd_size, priority);
if (!recvd_size)
continue;
assert (recvd_size == 1);
assert(recvd_size == 1);
MessageType mt{*reinterpret_cast<MessageType*>(buf.data())};
this->message_queue_->receive(
@@ -571,7 +572,7 @@ multi_runner_child::on_log(std::string const& msg)
namespace detail {
template class multi_runner_base<true>;
template class multi_runner_base<false>;
}
} // namespace detail
} // unit_test
} // beast
} // namespace test
} // namespace ripple

View File

@@ -51,9 +51,7 @@ struct case_results
std::size_t total = 0;
std::size_t failed = 0;
explicit
case_results(std::string name_ = "")
: name(std::move(name_))
explicit case_results(std::string name_ = "") : name(std::move(name_))
{
}
};
@@ -66,9 +64,7 @@ struct suite_results
std::size_t failed = 0;
typename clock_type::time_point start = clock_type::now();
explicit
suite_results(std::string name_ = "")
: name(std::move(name_))
explicit suite_results(std::string name_ = "") : name(std::move(name_))
{
}
@@ -116,8 +112,8 @@ class multi_runner_base
std::atomic<bool> any_failed_{false};
// A parent process will periodically increment `keep_alive_`. The child
// processes will check if `keep_alive_` is being incremented. If it is
// not incremented for a sufficiently long time, the child will assume the
// parent process has died.
// not incremented for a sufficiently long time, the child will assume
// the parent process has died.
std::atomic<std::size_t> keep_alive_{0};
mutable boost::interprocess::interprocess_mutex m_;
@@ -150,9 +146,10 @@ class multi_runner_base
};
static constexpr const char* shared_mem_name_ = "RippledUnitTestSharedMem";
// name of the message queue a multi_runner_child will use to communicate with
// multi_runner_parent
static constexpr const char* message_queue_name_ = "RippledUnitTestMessageQueue";
// name of the message queue a multi_runner_child will use to communicate
// with multi_runner_parent
static constexpr const char* message_queue_name_ =
"RippledUnitTestMessageQueue";
// `inner_` will be created in shared memory
inner* inner_;
@@ -163,8 +160,9 @@ class multi_runner_base
protected:
std::unique_ptr<boost::interprocess::message_queue> message_queue_;
enum class MessageType : std::uint8_t {test_start, test_end, log};
void message_queue_send(MessageType mt, std::string const& s);
enum class MessageType : std::uint8_t { test_start, test_end, log };
void
message_queue_send(MessageType mt, std::string const& s);
public:
multi_runner_base();
@@ -196,13 +194,13 @@ public:
any_failed() const;
};
} // detail
} // namespace detail
//------------------------------------------------------------------------------
/** Manager for children running unit tests
*/
class multi_runner_parent : private detail::multi_runner_base</*IsParent*/true>
class multi_runner_parent : private detail::multi_runner_base</*IsParent*/ true>
{
private:
// message_queue_ is used to collect log messages from the children
@@ -211,6 +209,7 @@ private:
std::thread message_queue_thread_;
// track running suites so if a child crashes the culprit can be flagged
std::set<std::string> running_suites_;
public:
multi_runner_parent(multi_runner_parent const&) = delete;
multi_runner_parent&
@@ -319,8 +318,7 @@ multi_runner_child::run_multi(Pred pred)
return failed;
}
} // unit_test
} // beast
} // namespace test
} // namespace ripple
#endif