Skip to content

Commit a5d5d5b

Browse files
committed
#30 Fixes compiler warnings for new classes and tests them on more systems
1 parent 8c0a7eb commit a5d5d5b

3 files changed

Lines changed: 25 additions & 15 deletions

File tree

.github/workflows/CI.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
cmake -B build
3838
-S ${{ github.workspace }}
3939
-DCMAKE_BUILD_TYPE=Release
40+
-DEnableMainHelperClasses=ON
4041
${{ steps.strings.outputs.cmake_args }}
4142
4243
- &build-code
@@ -61,6 +62,7 @@ jobs:
6162
${{ steps.strings.outputs.cmake_args }}
6263
-D BuildExamples=ON
6364
-D BuildInternalTests=ON
65+
-DEnableMainHelperClasses=ON
6466
-D CMAKE_PREFIX_PATH=${{ github.workspace }}/installed
6567
6668
- &build-tests

CppUnit2Gtest.hpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ struct Test {
290290
};
291291

292292
namespace to { namespace gtest {
293+
inline size_t ToSize_t(int value) {
294+
if (value < 0) { throw std::runtime_error("Negative value cannot be converted to size_t"); }
295+
return static_cast<size_t>(value);
296+
}
293297
// This is the actual test data (never children)
294298
struct TestAdaptorActualTest : Test
295299
{
@@ -300,7 +304,7 @@ namespace to { namespace gtest {
300304
return 0;
301305
}
302306

303-
Test* getChildTestAt(int index) override { throw std::invalid_argument("No child tests available"); }
307+
Test* getChildTestAt([[maybe_unused]] int index) override { throw std::invalid_argument("No child tests available"); }
304308
Test* findTest(const std::string& testName) override {
305309
return (testInfo->name() == testName) ? this : throw std::invalid_argument("Test not found: " + testName);
306310
}
@@ -310,9 +314,9 @@ namespace to { namespace gtest {
310314

311315
inline std::vector<TestAdaptorActualTest> CreateTests(const testing::TestSuite* testSuite) {
312316
std::vector<TestAdaptorActualTest> tests;
313-
const size_t test_count = testSuite->total_test_count();
314-
tests.reserve(test_count);
315-
for (size_t i = 0; i < test_count; ++i) {
317+
const auto test_count = testSuite->total_test_count();
318+
tests.reserve(ToSize_t(test_count));
319+
for (int i = 0; i < test_count; ++i) {
316320
const testing::TestInfo* test_info = testSuite->GetTestInfo(i);
317321
tests.emplace_back(test_info);
318322
}
@@ -333,8 +337,8 @@ namespace to { namespace gtest {
333337
}
334338
return static_cast<int>(test_count);
335339
}
336-
const Test* getChildTestAt(int index) const { return &tests.at(index); }
337-
Test* getChildTestAt(int index) override { return &tests.at(index); }
340+
const Test* getChildTestAt(int index) const { return &tests.at(ToSize_t(index)); }
341+
Test* getChildTestAt(int index) override { return &tests.at(ToSize_t(index)); }
338342
std::string getName() const override { return testSuite->name(); }
339343
Test* findTest(const std::string& testName) override {
340344
for (auto& test : tests) {
@@ -349,9 +353,10 @@ namespace to { namespace gtest {
349353
inline std::vector<TestAdaptorSuite> CreateSuites() {
350354
std::vector<TestAdaptorSuite> suites;
351355
const testing::UnitTest* unit_test = testing::UnitTest::GetInstance();
352-
const size_t test_suite_count = unit_test->total_test_suite_count();
353-
suites.reserve(test_suite_count);
354-
for (size_t i = 0; i < test_suite_count; ++i) {
356+
// CppUnit uses int as size type so we shall too (bad)
357+
const int test_suite_count = unit_test->total_test_suite_count();
358+
suites.reserve(ToSize_t(test_suite_count));
359+
for (int i = 0; i < test_suite_count; ++i) {
355360
const testing::TestSuite* test_suite = unit_test->GetTestSuite(i);
356361
suites.emplace_back(test_suite);
357362
}
@@ -370,7 +375,7 @@ namespace to { namespace gtest {
370375
return static_cast<int>(test_count);
371376
}
372377

373-
Test* getChildTestAt(int index) override { return &suites.at(index); }
378+
Test* getChildTestAt(int index) override { return &suites.at(ToSize_t(index)); }
374379

375380
std::string getName() const override { return "All Tests"; }
376381

@@ -397,13 +402,12 @@ namespace to { namespace gtest {
397402
struct TestFactoryRegistry {
398403
TestFactoryRegistry() = default;
399404

400-
static TestFactoryRegistry& getRegistry (const std::string& [[maybe_unused]] name="All Tests") {
405+
static TestFactoryRegistry& getRegistry ([[maybe_unused]] const std::string& name="All Tests") {
401406
// return singleton registry
402407
static TestFactoryRegistry registry{};
403408
return registry;
404409
}
405410

406-
407411
Test* makeTest() {
408412
static to::gtest::TestAdaptorRoot root;
409413
return &root;
@@ -452,12 +456,16 @@ struct TextTestRunner {
452456
filter = "--gtest_filter=" + filter;
453457
}
454458

455-
bool run(const std::string& testPath="", bool doWait=false, bool doPrintResult=true, bool doPrintProgress=true) {
459+
bool run(
460+
[[maybe_unused]] const std::string& testPath="",
461+
[[maybe_unused]] bool doWait=false,
462+
[[maybe_unused]] bool doPrintResult=true,
463+
[[maybe_unused]] bool doPrintProgress=true
464+
) {
456465
int argc = filter.empty() ? 1 : 2;
457466
cleanFilter();
458467
std::string fake_exe_name = "executable_name";
459468
char* argv_data[] = { fake_exe_name.data(), filter.data() };
460-
char** argv = argv_data;
461469
testing::InitGoogleTest(&argc, argv_data);
462470
return 0 == RUN_ALL_TESTS();
463471
}

tests/examples/MigratingSharedState.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct /*Imaginary*/ Database final {
2323
auto& operator=(const Database&) = delete;
2424
struct Transaction final {
2525
Transaction() { /*Starts a transaction*/ }
26-
void execute(std::string_view sql_statement) { /*Does Something*/ }
26+
void execute([[maybe_unused]] std::string_view sql_statement) { /*Does Something*/ }
2727
void commit() {}
2828
~Transaction() { /*Aborts the transaction*/ }
2929
};

0 commit comments

Comments
 (0)