Skip to content

Port unit tests to Google Test#3116

Merged
daljit46 merged 21 commits intodevfrom
google_test
Sep 22, 2025
Merged

Port unit tests to Google Test#3116
daljit46 merged 21 commits intodevfrom
google_test

Conversation

@daljit46
Copy link
Copy Markdown
Member

@daljit46 daljit46 commented Jun 25, 2025

This PR ports all of our existing tests in testing/unit_tests to use the Google Test, a widely adopted unit testing framework in the C++ world. All tests have been rewritten to leverage the Google Test API, replacing our previous in-house solution. All tests should provide the same coverage as before. The exception is the tests for our dynamic MR::BitSet class, where the new set of tests should be slightly more comprehensive than the previous ones.
On the CMake side, the only needed change is the addition of Google Test in cmake/Dependencies.cmake and very minimal changes to the CMake logic in unit_tests/CMakeLists.txt.

@daljit46 daljit46 self-assigned this Jun 25, 2025
@daljit46 daljit46 requested a review from a team June 25, 2025 08:01
Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 25 out of 69. Check the log or trigger a new build to see more.

* For more details, see http://www.mrtrix.org/.
*/

#include "gtest/gtest.h"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'gtest/gtest.h' file not found [clang-diagnostic-error]

#include "gtest/gtest.h"
         ^

bool initial_fill_value;
};

TEST_P(BitSetParamTest, ConstructorAndInitialState) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_P(BitSetParamTest, ConstructorAndInitialState) {
TEST_P(BitSetParamTest /*unused*/, ConstructorAndInitialState /*unused*/) {

}
}

TEST_P(BitSetParamTest, CopyConstructorAndEquality) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_P(BitSetParamTest, CopyConstructorAndEquality) {
TEST_P(BitSetParamTest /*unused*/, CopyConstructorAndEquality /*unused*/) {

}
}

TEST_P(BitSetParamTest, AssignmentOperator) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_P(BitSetParamTest, AssignmentOperator) {
TEST_P(BitSetParamTest /*unused*/, AssignmentOperator /*unused*/) {

TEST_P(BitSetParamTest, AssignmentOperator) {
for (size_t num_bits = 0; num_bits < 16; ++num_bits) {
const MR::BitSet source(num_bits, initial_fill_value);
const bool other_fill_value = !initial_fill_value;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'other_fill_value' is not initialized [cppcoreguidelines-init-variables]

Suggested change
const bool other_fill_value = !initial_fill_value;
const bool other_fill_value = false = !initial_fill_value;

TEST_F(OrderedQueueTest, Regular2Stage) {
const MR::Timer timer;

SourceFunctor source;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'source' of type 'SourceFunctor' can be declared 'const' [misc-const-correctness]

Suggested change
SourceFunctor source;
SourceFunctor const source;

const MR::Timer timer;

SourceFunctor source;
SinkFunctor sink;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'sink' of type 'SinkFunctor' can be declared 'const' [misc-const-correctness]

Suggested change
SinkFunctor sink;
SinkFunctor const sink;

PerformChecksAndLog(timer, sink, OrderEnforcement::Enforce);
}

TEST_F(OrderedQueueTest, Batched2Stage) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(OrderedQueueTest, Batched2Stage) {
TEST_F(OrderedQueueTest /*unused*/, Batched2Stage /*unused*/) {

PerformChecksAndLog(timer, sink, OrderEnforcement::Enforce);
}

TEST_F(OrderedQueueTest, Regular3Stage) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(OrderedQueueTest, Regular3Stage) {
TEST_F(OrderedQueueTest /*unused*/, Regular3Stage /*unused*/) {

PerformChecksAndLog(timer, sink, OrderEnforcement::DoNotEnforce);
}

TEST_F(OrderedQueueTest, BatchedUnbatched3Stage) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(OrderedQueueTest, BatchedUnbatched3Stage) {
TEST_F(OrderedQueueTest /*unused*/, BatchedUnbatched3Stage /*unused*/) {

@daljit46 daljit46 removed the request for review from a team June 25, 2025 08:37
Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 25 out of 44. Check the log or trigger a new build to see more.

PerformChecksAndLog(timer, sink, OrderEnforcement::DoNotEnforce);
}

TEST_F(OrderedQueueTest, UnbatchedBatched3Stage) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(OrderedQueueTest, UnbatchedBatched3Stage) {
TEST_F(OrderedQueueTest /*unused*/, UnbatchedBatched3Stage /*unused*/) {

PerformChecksAndLog(timer, sink, OrderEnforcement::DoNotEnforce);
}

TEST_F(OrderedQueueTest, BatchedBatchedRegular3Stage) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(OrderedQueueTest, BatchedBatchedRegular3Stage) {
TEST_F(OrderedQueueTest /*unused*/, BatchedBatchedRegular3Stage /*unused*/) {

PerformChecksAndLog(timer, sink, OrderEnforcement::DoNotEnforce);
}

TEST_F(OrderedQueueTest, Regular4Stage) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(OrderedQueueTest, Regular4Stage) {
TEST_F(OrderedQueueTest /*unused*/, Regular4Stage /*unused*/) {

PerformChecksAndLog(timer, sink, OrderEnforcement::DoNotEnforce);
}

TEST_F(OrderedQueueTest, BatchedUnbatchedUnbatched4Stage) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(OrderedQueueTest, BatchedUnbatchedUnbatched4Stage) {
TEST_F(OrderedQueueTest /*unused*/, BatchedUnbatchedUnbatched4Stage /*unused*/) {

PerformChecksAndLog(timer, sink, OrderEnforcement::DoNotEnforce);
}

TEST_F(OrderedQueueTest, UnbatchedBatchedUnbatched4Stage) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(OrderedQueueTest, UnbatchedBatchedUnbatched4Stage) {
TEST_F(OrderedQueueTest /*unused*/, UnbatchedBatchedUnbatched4Stage /*unused*/) {

}
}

TEST_F(ROITests, ThreeOrderedROIsCorrectOrder) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(ROITests, ThreeOrderedROIsCorrectOrder) {
TEST_F(ROITests /*unused*/, ThreeOrderedROIsCorrectOrder /*unused*/) {

}
}

TEST_F(ROITests, ThreeOrderedROIsIllegalABA) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(ROITests, ThreeOrderedROIsIllegalABA) {
TEST_F(ROITests /*unused*/, ThreeOrderedROIsIllegalABA /*unused*/) {

}
}

TEST_F(ROITests, FourOrderedROIsIllegalABCAD) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(ROITests, FourOrderedROIsIllegalABCAD) {
TEST_F(ROITests /*unused*/, FourOrderedROIsIllegalABCAD /*unused*/) {

}
}

TEST_F(ROITests, CombinationOrderedAndUnorderedROIs) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(ROITests, CombinationOrderedAndUnorderedROIs) {
TEST_F(ROITests /*unused*/, CombinationOrderedAndUnorderedROIs /*unused*/) {


#include <Eigen/Core>
#include <algorithm>
#include <gtest/gtest.h>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'gtest/gtest.h' file not found [clang-diagnostic-error]

#include <gtest/gtest.h>
         ^

daljit46 added 2 commits June 25, 2025 12:33
Using CTAD runs into deep fold expressions and exceed's template nesting
limits on both Clang and GCC.
Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

void PrintTo(const ShufflerParams &params, ::std::ostream *os) { *os << "{" << params.name << "}"; }

std::vector<ShufflerParams> GetShufflerTestParams() {
std::vector<ShufflerParams> all_params;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'all_params' is not initialized [cppcoreguidelines-init-variables]

Suggested change
std::vector<ShufflerParams> all_params;
std::vector<ShufflerParams> all_params = 0;

}
} // namespace

class ShufflerTest : public ::testing::Test {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: constructor does not initialize these fields: blocks [cppcoreguidelines-pro-type-member-init]

testing/unit_tests/shuffle_tests.cpp:208:

-   std::vector<std::set<size_t>> blocks;
+   std::vector<std::set<size_t>> blocks{};

blocks[block_indices[i]].insert(i);
}

void TestPermutationWithin(Shuffler &in, const std::string &fail_msg) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'TestPermutationWithin' can be made static [readability-convert-member-functions-to-static]

Suggested change
void TestPermutationWithin(Shuffler &in, const std::string &fail_msg) {
static void TestPermutationWithin(Shuffler &in, const std::string &fail_msg) {

void TestPermutationWithin(Shuffler &in, const std::string &fail_msg) {
in.reset();
Shuffle shuffle;
Eigen::Array<int, Eigen::Dynamic, 1> shuffled_data;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'shuffled_data' is not initialized [cppcoreguidelines-init-variables]

Suggested change
Eigen::Array<int, Eigen::Dynamic, 1> shuffled_data;
Eigen::Array<int, Eigen::Dynamic, 1> shuffled_data = 0;

}
}

void TestSignflipWhole(Shuffler &in, const std::string &fail_msg) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'TestSignflipWhole' can be made static [readability-convert-member-functions-to-static]

Suggested change
void TestSignflipWhole(Shuffler &in, const std::string &fail_msg) {
static void TestSignflipWhole(Shuffler &in, const std::string &fail_msg) {

* For more details, see http://www.mrtrix.org/.
*/

#include "gtest/gtest.h"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'gtest/gtest.h' file not found [clang-diagnostic-error]

#include "gtest/gtest.h"
         ^


class ToBoolTest : public ::testing::Test {};

TEST_F(ToBoolTest, StringToBoolConversion) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(ToBoolTest, StringToBoolConversion) {
TEST_F(ToBoolTest /*unused*/, StringToBoolConversion /*unused*/) {


class ToIntTest : public ::testing::Test {};

TEST_F(ToIntTest, StringToIntConversion) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(ToIntTest, StringToIntConversion) {
TEST_F(ToIntTest /*unused*/, StringToIntConversion /*unused*/) {


class ToFloatTest : public ::testing::Test {};

TEST_F(ToFloatTest, StringToFloatConversion) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(ToFloatTest, StringToFloatConversion) {
TEST_F(ToFloatTest /*unused*/, StringToFloatConversion /*unused*/) {


class ToComplexFloatTest : public ::testing::Test {};

TEST_F(ToComplexFloatTest, StringToComplexFloatConversion) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_F(ToComplexFloatTest, StringToComplexFloatConversion) {
TEST_F(ToComplexFloatTest /*unused*/, StringToComplexFloatConversion /*unused*/) {

@daljit46 daljit46 requested a review from a team June 25, 2025 15:02
@Lestropie Lestropie force-pushed the dev branch 3 times, most recently from 70031c3 to 6bf4cec Compare August 26, 2025 08:11
@daljit46 daljit46 merged commit 052ed0c into dev Sep 22, 2025
15 of 17 checks passed
@daljit46 daljit46 deleted the google_test branch September 22, 2025 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant