Skip to content

Commit

Permalink
reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
AdhocMan committed Jul 30, 2023
1 parent 0f6bdcb commit d42a909
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 54 deletions.
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BasedOnStyle: Google
ColumnLimit: 100
AccessModifierOffset: -2
67 changes: 33 additions & 34 deletions include/gtest_mpi/gtest_mpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class MPITestEnvironment : public ::testing::Environment {
public:
MPITestEnvironment() : ::testing::Environment() {}

MPITestEnvironment(const MPITestEnvironment&) = delete;
MPITestEnvironment(const MPITestEnvironment &) = delete;

MPITestEnvironment(MPITestEnvironment&&) = default;
MPITestEnvironment(MPITestEnvironment &&) = default;

static MPI_Comm GetComm() { return global_test_comm; }

Expand Down Expand Up @@ -122,20 +122,20 @@ class PrettyMPIUnitTestResultPrinter : public ::testing::TestEventListener {
}

// The following methods override what's in the TestEventListener class.
void OnTestIterationStart(const ::testing::UnitTest& unit_test, int iteration) override;
void OnEnvironmentsSetUpStart(const ::testing::UnitTest& unit_test) override;
void OnTestCaseStart(const ::testing::TestCase& test_case) override;
void OnTestStart(const ::testing::TestInfo& test_info) override;
void OnTestPartResult(const ::testing::TestPartResult& result) override;
void OnTestEnd(const ::testing::TestInfo& test_info) override;
void OnTestCaseEnd(const ::testing::TestCase& test_case) override;
void OnEnvironmentsTearDownStart(const ::testing::UnitTest& unit_test) override;
void OnTestIterationEnd(const ::testing::UnitTest& unit_test, int iteration) override;

void OnEnvironmentsSetUpEnd(const ::testing::UnitTest& /*unit_test*/) override {}
void OnEnvironmentsTearDownEnd(const ::testing::UnitTest& /*unit_test*/) override {}
void OnTestProgramStart(const ::testing::UnitTest& /*unit_test*/) override {}
void OnTestProgramEnd(const ::testing::UnitTest& /*unit_test*/) override {}
void OnTestIterationStart(const ::testing::UnitTest &unit_test, int iteration) override;
void OnEnvironmentsSetUpStart(const ::testing::UnitTest &unit_test) override;
void OnTestCaseStart(const ::testing::TestCase &test_case) override;
void OnTestStart(const ::testing::TestInfo &test_info) override;
void OnTestPartResult(const ::testing::TestPartResult &result) override;
void OnTestEnd(const ::testing::TestInfo &test_info) override;
void OnTestCaseEnd(const ::testing::TestCase &test_case) override;
void OnEnvironmentsTearDownStart(const ::testing::UnitTest &unit_test) override;
void OnTestIterationEnd(const ::testing::UnitTest &unit_test, int iteration) override;

void OnEnvironmentsSetUpEnd(const ::testing::UnitTest & /*unit_test*/) override {}
void OnEnvironmentsTearDownEnd(const ::testing::UnitTest & /*unit_test*/) override {}
void OnTestProgramStart(const ::testing::UnitTest & /*unit_test*/) override {}
void OnTestProgramEnd(const ::testing::UnitTest & /*unit_test*/) override {}

private:
int rank_;
Expand All @@ -149,15 +149,15 @@ class PrettyMPIUnitTestResultPrinter : public ::testing::TestEventListener {
};

// Taken / modified from Googletest
void PrettyMPIUnitTestResultPrinter::OnTestIterationStart(const ::testing::UnitTest& unit_test,
void PrettyMPIUnitTestResultPrinter::OnTestIterationStart(const ::testing::UnitTest &unit_test,
int iteration) {
using namespace ::testing;
if (rank_ != 0) return;

if (GTEST_FLAG(repeat) != 1)
printf("\nRepeating all tests (iteration %d) . . .\n\n", iteration + 1);

const char* const filter = GTEST_FLAG(filter).c_str();
const char *const filter = GTEST_FLAG(filter).c_str();

// Prints the filter if it's not *. This reminds the user that some
// tests may be skipped.
Expand Down Expand Up @@ -185,7 +185,7 @@ void PrettyMPIUnitTestResultPrinter::OnTestIterationStart(const ::testing::UnitT
// Taken / modified from Googletest
// Formats a source file path and a line number as they would appear
// in an error message from the compiler used to compile this code.
GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) {
GTEST_API_ ::std::string FormatFileLocation(const char *file, int line) {
const std::string file_name(file == nullptr ? "unkown file" : file);

if (line < 0) {
Expand All @@ -200,15 +200,15 @@ GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) {

// Taken / modified from Googletest
void PrettyMPIUnitTestResultPrinter::OnEnvironmentsSetUpStart(
const ::testing::UnitTest& /*unit_test*/) {
const ::testing::UnitTest & /*unit_test*/) {
if (rank_ != 0) return;
ColoredPrintf(COLOR_GREEN, "[----------] ");
printf("Global test environment set-up.\n");
fflush(stdout);
}

// Taken / modified from Googletest
void PrettyMPIUnitTestResultPrinter::OnTestCaseStart(const ::testing::TestCase& test_case) {
void PrettyMPIUnitTestResultPrinter::OnTestCaseStart(const ::testing::TestCase &test_case) {
using namespace ::testing;
if (rank_ != 0) return;
const std::string counts = FormatCountableNoun(test_case.test_to_run_count(), "test", "tests");
Expand All @@ -223,7 +223,7 @@ void PrettyMPIUnitTestResultPrinter::OnTestCaseStart(const ::testing::TestCase&
}

// Taken / modified from Googletest
void PrettyMPIUnitTestResultPrinter::OnTestStart(const ::testing::TestInfo& test_info) {
void PrettyMPIUnitTestResultPrinter::OnTestStart(const ::testing::TestInfo &test_info) {
if (rank_ != 0) return;
ColoredPrintf(COLOR_GREEN, "[ RUN ] ");
printf("%s.%s", test_info.test_case_name(), test_info.name());
Expand All @@ -233,15 +233,15 @@ void PrettyMPIUnitTestResultPrinter::OnTestStart(const ::testing::TestInfo& test
}

// Taken / modified from Googletest
void PrettyMPIUnitTestResultPrinter::OnTestPartResult(const ::testing::TestPartResult& result) {
void PrettyMPIUnitTestResultPrinter::OnTestPartResult(const ::testing::TestPartResult &result) {
using namespace ::testing;
// If the test part succeeded, we don't need to do anything.
if (result.type() == TestPartResult::kSuccess) return;
failed_results_.Add(result);
}

// Taken / modified from Googletest
void PrintFailedTestResultCollection(const TestPartResultCollection& collection, int rank) {
void PrintFailedTestResultCollection(const TestPartResultCollection &collection, int rank) {
for (std::size_t i = 0; i < collection.Size(); ++i) {
std::string m =
(::testing::Message()
Expand All @@ -256,7 +256,7 @@ void PrintFailedTestResultCollection(const TestPartResultCollection& collection,
}

// Taken / modified from Googletest
void PrettyMPIUnitTestResultPrinter::OnTestEnd(const ::testing::TestInfo& test_info) {
void PrettyMPIUnitTestResultPrinter::OnTestEnd(const ::testing::TestInfo &test_info) {
using namespace ::testing;

// check if any ranks failed
Expand All @@ -275,7 +275,7 @@ void PrettyMPIUnitTestResultPrinter::OnTestEnd(const ::testing::TestInfo& test_i
}

int failed_globally = failed_locally;
for (const auto& f : failed_flags_per_rank) {
for (const auto &f : failed_flags_per_rank) {
if (f) failed_globally = 1;
}

Expand Down Expand Up @@ -329,7 +329,7 @@ void PrettyMPIUnitTestResultPrinter::OnTestEnd(const ::testing::TestInfo& test_i
}

// Taken / modified from Googletest
void PrettyMPIUnitTestResultPrinter::OnTestCaseEnd(const ::testing::TestCase& test_case) {
void PrettyMPIUnitTestResultPrinter::OnTestCaseEnd(const ::testing::TestCase &test_case) {
using namespace ::testing;
if (!GTEST_FLAG(print_time) || rank_ != 0) return;

Expand All @@ -340,9 +340,9 @@ void PrettyMPIUnitTestResultPrinter::OnTestCaseEnd(const ::testing::TestCase& te
fflush(stdout);
}

static std::string FormatSet(const std::set<int>& s) {
std::string FormatSet(const std::set<int> &s) {
std::string res;
for (const auto& val : s) {
for (const auto &val : s) {
res += std::to_string(val);
if (val != *(--s.end())) {
res += ", ";
Expand All @@ -353,8 +353,7 @@ static std::string FormatSet(const std::set<int>& s) {
}

// Taken / modified from Googletest
static void PrintFullTestCommentIfPresent(const std::string& type_param,
const std::string& value_param) {
void PrintFullTestCommentIfPresent(const std::string &type_param, const std::string &value_param) {
if (!type_param.empty() || !value_param.empty()) {
printf(", where ");
if (!type_param.empty()) {
Expand All @@ -369,7 +368,7 @@ static void PrintFullTestCommentIfPresent(const std::string& type_param,
}

// Taken / modified from Googletest
void PrettyMPIUnitTestResultPrinter::OnTestIterationEnd(const ::testing::UnitTest& unit_test,
void PrettyMPIUnitTestResultPrinter::OnTestIterationEnd(const ::testing::UnitTest &unit_test,
int /*iteration*/) {
using namespace ::testing;
failed_results_.Reset();
Expand All @@ -390,7 +389,7 @@ void PrettyMPIUnitTestResultPrinter::OnTestIterationEnd(const ::testing::UnitTes
if (num_failed_tests_) {
ColoredPrintf(COLOR_RED, "[ FAILED ] ");
printf("%s, listed below:\n", FormatTestCount(num_failed_tests_).c_str());
for (const auto& prop : failed_test_properties_) {
for (const auto &prop : failed_test_properties_) {
if (!prop.should_run) continue;
ColoredPrintf(COLOR_RED, "[ FAILED ] ");
printf("%s.%s", prop.case_name.c_str(), prop.name.c_str());
Expand All @@ -414,7 +413,7 @@ void PrettyMPIUnitTestResultPrinter::OnTestIterationEnd(const ::testing::UnitTes

// Taken / modified from Googletest
void PrettyMPIUnitTestResultPrinter::OnEnvironmentsTearDownStart(
const ::testing::UnitTest& /*unit_test*/) {
const ::testing::UnitTest & /*unit_test*/) {
if (rank_ != 0) return;
ColoredPrintf(COLOR_GREEN, "[----------] ");
printf("Global MPI test environment tear-down\n");
Expand Down
39 changes: 19 additions & 20 deletions include/gtest_mpi/gtest_mpi_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ static const char kValueParamLabel[] = "GetParam()";
enum GTestColor { COLOR_DEFAULT, COLOR_RED, COLOR_GREEN, COLOR_YELLOW };

// Taken / modified from Googletest
static void PrintFullTestCommentIfPresent(const ::testing::TestInfo& test_info) {
const char* const type_param = test_info.type_param();
const char* const value_param = test_info.value_param();
void PrintFullTestCommentIfPresent(const ::testing::TestInfo &test_info) {
const char *const type_param = test_info.type_param();
const char *const value_param = test_info.value_param();

if (type_param != NULL || value_param != NULL) {
printf(", where ");
Expand All @@ -112,9 +112,9 @@ static void PrintFullTestCommentIfPresent(const ::testing::TestInfo& test_info)
}
}

bool CStringEquals(const char* l, const char* r) { return std::strcmp(l, r) == 0; }
bool CStringEquals(const char *l, const char *r) { return std::strcmp(l, r) == 0; }

bool CaseInsensitiveCStringEquals(const char* l, const char* r) {
bool CaseInsensitiveCStringEquals(const char *l, const char *r) {
bool equal = true;

for (; equal && *l && *r; ++l, ++r) {
Expand All @@ -128,11 +128,11 @@ bool CaseInsensitiveCStringEquals(const char* l, const char* r) {
// Taken / modified from Googletest
bool ShouldUseColor(bool stdout_is_tty) {
using namespace ::testing;
const char* const gtest_color = GTEST_FLAG(color).c_str();
const char *const gtest_color = GTEST_FLAG(color).c_str();

if (CaseInsensitiveCStringEquals(gtest_color, "auto")) {
// On non-Windows platforms, we rely on the TERM variable.
const char* const term = getenv("TERM");
const char *const term = getenv("TERM");
const bool term_supports_color =
CStringEquals(term, "xterm") || CStringEquals(term, "xterm-color") ||
CStringEquals(term, "xterm-256color") || CStringEquals(term, "screen") ||
Expand All @@ -152,7 +152,7 @@ bool ShouldUseColor(bool stdout_is_tty) {
}

// Taken / modified from Googletest
static const char* GetAnsiColorCode(GTestColor color) {
const char *GetAnsiColorCode(GTestColor color) {
switch (color) {
case COLOR_RED:
return "1";
Expand All @@ -166,7 +166,7 @@ static const char* GetAnsiColorCode(GTestColor color) {
}

// Taken / modified from Googletest
static void ColoredPrintf(GTestColor color, const char* fmt, ...) {
void ColoredPrintf(GTestColor color, const char *fmt, ...) {
va_list args;
va_start(args, fmt);

Expand All @@ -186,10 +186,10 @@ static void ColoredPrintf(GTestColor color, const char* fmt, ...) {
}

// Taken / modified from Googletest
Int32 Int32FromEnvOrDie(const char* var, Int32 default_val) {
Int32 Int32FromEnvOrDie(const char *var, Int32 default_val) {
using namespace ::testing;
using namespace ::testing::internal;
const char* str_val = getenv(var);
const char *str_val = getenv(var);
if (str_val == NULL) {
return default_val;
}
Expand All @@ -202,24 +202,23 @@ Int32 Int32FromEnvOrDie(const char* var, Int32 default_val) {
}

// Taken / modified from Googletest
static std::string FormatCountableNoun(int count, const char* singular_form,
const char* plural_form) {
std::string FormatCountableNoun(int count, const char *singular_form, const char *plural_form) {
using namespace ::testing;
return std::to_string(count) + " " + (count == 1 ? singular_form : plural_form);
}

// Taken / modified from Googletest
static std::string FormatTestCount(int test_count) {
std::string FormatTestCount(int test_count) {
return FormatCountableNoun(test_count, "test", "tests");
}

// Taken / modified from Googletest
static std::string FormatTestCaseCount(int test_case_count) {
std::string FormatTestCaseCount(int test_case_count) {
return FormatCountableNoun(test_case_count, "test case", "test cases");
}

// Taken / modified from Googletest
static const char* TestPartResultTypeToString(::testing::TestPartResult::Type type) {
const char *TestPartResultTypeToString(::testing::TestPartResult::Type type) {
switch (type) {
case ::testing::TestPartResult::kSuccess:
return "Success";
Expand All @@ -237,7 +236,7 @@ static const char* TestPartResultTypeToString(::testing::TestPartResult::Type ty
}

// Taken / modified from Googletest
bool ShouldShard(const char* total_shards_env, const char* shard_index_env,
bool ShouldShard(const char *total_shards_env, const char *shard_index_env,
bool in_subprocess_for_death_test) {
using namespace ::testing;
using namespace ::testing::internal;
Expand Down Expand Up @@ -291,7 +290,7 @@ struct TestInfoProperties {
// which can be exchanged in a single MPI call
class StringCollection {
public:
void Add(const char* s) {
void Add(const char *s) {
int size = 0;
for (; *s != '\0'; ++s, ++size) {
text.push_back(*s);
Expand Down Expand Up @@ -331,7 +330,7 @@ class StringCollection {
prev_size = 0;
}

const char* get_str(const int id) const { return text.data() + start_indices[id]; }
const char *get_str(const int id) const { return text.data() + start_indices[id]; }

const std::size_t Size() const { return start_indices.size(); }

Expand Down Expand Up @@ -375,7 +374,7 @@ struct TestPartResultCollection {
file_names.Recv(comm, rank);
}

void Add(const ::testing::TestPartResult& result) {
void Add(const ::testing::TestPartResult &result) {
types.push_back(result.type());
line_numbers.push_back(result.line_number());
summaries.Add(result.summary());
Expand Down

0 comments on commit d42a909

Please sign in to comment.