Skip to content

Commit aa872ff

Browse files
committed
Add CDash, refactor code, and fix memory check leaks.
1 parent 12261a6 commit aa872ff

File tree

10 files changed

+74
-39
lines changed

10 files changed

+74
-39
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/Testing/
12
/CMakeUserPresets.json
23
/CMakeLists.txt.user
34
/vcpkg/

CTestConfig.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## This file should be placed in the root directory of your project.
2+
## Then modify the CMakeLists.txt file in the root directory of your
3+
## project to incorporate the testing dashboard.
4+
##
5+
## # The following are required to submit to the CDash dashboard:
6+
## ENABLE_TESTING()
7+
## INCLUDE(CTest)
8+
9+
set(CTEST_PROJECT_NAME "cpp-project-template")
10+
set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
11+
12+
set(CTEST_DROP_METHOD "https")
13+
set(CTEST_DROP_SITE "my.cdash.org")
14+
set(CTEST_DROP_LOCATION "/submit.php?project=cpp-project-template")
15+
set(CTEST_DROP_SITE_CDASH TRUE)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This repository aims to provide a modern C++ cross-platform codebase template, f
88

99
### Status
1010

11-
![CMake](https://img.shields.io/badge/CMake-done-green) ![CTest](https://img.shields.io/badge/CTest-done-green) ![CPack](https://img.shields.io/badge/CPack-done-green)![CDash](https://img.shields.io/badge/CDash-todo-red) ![Code coverage](https://img.shields.io/badge/code%20coverage-todo-red) ![consoleApp](https://img.shields.io/badge/console%20app-done-green) ![staticLib](https://img.shields.io/badge/static%20library-done-green) ![dynamicLib](https://img.shields.io/badge/dynamic%20library-todo-red) ![wxWidgets](https://img.shields.io/badge/wxWidgets-done-green) ![Qt](https://img.shields.io/badge/Qt-todo-red) ![windowsIco](https://img.shields.io/badge/windows%20icon-done-green)
11+
![CMake](https://img.shields.io/badge/CMake-done-green) ![CTest](https://img.shields.io/badge/CTest-done-green) ![CPack](https://img.shields.io/badge/CPack-done-green)![CDash](https://img.shields.io/badge/CDash-done-green) ![Code coverage](https://img.shields.io/badge/code%20coverage-todo-red) ![consoleApp](https://img.shields.io/badge/console%20app-done-green) ![staticLib](https://img.shields.io/badge/static%20library-done-green) ![dynamicLib](https://img.shields.io/badge/dynamic%20library-todo-red) ![wxWidgets](https://img.shields.io/badge/wxWidgets-done-green) ![Qt](https://img.shields.io/badge/Qt-todo-red) ![windowsIco](https://img.shields.io/badge/windows%20icon-done-green)
1212
![windowsVer](https://img.shields.io/badge/windows%20version-done-green) ![i18nL10n](https://img.shields.io/badge/i18n%20and%20L10n-todo-red) ![Boost](https://img.shields.io/badge/boost-todo-red) ![GoogleTest](https://img.shields.io/badge/GoogleTest-done-green) ![BoostTest](https://img.shields.io/badge/Boost.Test-todo-red) ![Catch2](https://img.shields.io/badge/catch2-todo-red) ![Doctest](https://img.shields.io/badge/doctest-todo-red) ![vcpkg](https://img.shields.io/badge/vcpkg-done-green) ![conan](https://img.shields.io/badge/conan-todo-red) ![cppcheck](https://img.shields.io/badge/cppcheck-done-green) ![CSA](https://img.shields.io/badge/clang%20static%20analyzer-done-green) ![clangtidy](https://img.shields.io/badge/clang%20tidy-done-green) ![lcov](https://img.shields.io/badge/lcov-done-green) ![gcovr](https://img.shields.io/badge/gcovr-done-green) ![valgrind](https://img.shields.io/badge/valgrind-done-green) ![sanitizers](https://img.shields.io/badge/sanitizers-done-green) ![gprof](https://img.shields.io/badge/gprof-todo-red) ![IntelVTuneProfiler](https://img.shields.io/badge/Intel%20VTune%20Profiler-todo-red) ![perf](https://img.shields.io/badge/perf-todo-red) ![doxygen](https://img.shields.io/badge/doxygen-done-green) ![sphinx](https://img.shields.io/badge/sphinx-needs%20work-yellow) ![GitHub Actions](https://img.shields.io/badge/GitHub%20Actions-done-green) ![GitLab CI/CD](https://img.shields.io/badge/GitLab%20CI/CD-todo-red) ![nsis](https://img.shields.io/badge/nsis-done-green) ![wix toolset](https://img.shields.io/badge/wix%20toolset-done-green) ![deb](https://img.shields.io/badge/deb-done-green) ![rpm](https://img.shields.io/badge/rpm-done-green) ![DragNDrop](https://img.shields.io/badge/DragNDrop-needs%20work-yellow) ![productbuild](https://img.shields.io/badge/productbuild-todo-red) ![raspbian](https://img.shields.io/badge/raspbian-todo-red) ![SignTool](https://img.shields.io/badge/SignTool-todo-red)
1313

1414
## Download

TODO.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
- [x] CTest
2727
- [x] CPack
2828
- [ ] Sign the executables (see: https://stackoverflow.com/a/252245/3049315)
29-
- [ ] CDash
29+
- [x] CDash
3030
- [x] Package manager
3131
- [x] vcpkg
3232
- [ ] conan
@@ -70,4 +70,7 @@
7070
- [ ] [Install wxWidgets on RPI](https://yasriady.blogspot.com/2015/10/how-to-build-wxwidgets-for-raspberry-pi.html)
7171
- [ ] GitLab CI/CD
7272
- [ ] Travis CI
73-
- [ ] Appveyor
73+
- [ ] Appveyor
74+
- [ ] Azure Pipelines
75+
- [ ] [GitHub Codespaces](https://docs.github.com/en/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers#using-a-predefined-dev-container-configuration)
76+
- [ ] Docker

docs/GUIDE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Dynamic analysis](#dynamic-analysis)
88
- [Valgrind](#valgrind)
99
- [Sanitizers](#sanitizers)
10+
- [CDash](#cdash)
1011
- [CMake tips](#cmake-tips)
1112
- [Doxygen tips](#doxygen-tips)
1213
- [GitHub Actions tips](#github-actions-tips)
@@ -149,6 +150,16 @@ More about sanitizers:
149150
- https://hpc-wiki.info/hpc/Compiler_Sanitizers
150151
- https://developers.redhat.com/blog/2021/05/05/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind
151152

153+
### CDash
154+
155+
CDash Dashboard: https://my.cdash.org/index.php?project=cpp-project-template
156+
157+
```sh
158+
cmake -S . -B build -G "Ninja" -DCMAKE_BUILD_TYPE=Coverage
159+
cmake --build build
160+
ctest --test-dir build -D Experimental -T Test -T Coverage -T memcheck
161+
```
162+
152163
## CMake tips
153164

154165
1. Check the available targets with:
@@ -198,6 +209,7 @@ A release is created when creating and pushing a tag that starts with `v`.
198209

199210
- [GoogleTest User's Guide](https://google.github.io/googletest/)
200211
- [CMake GoogleTest](https://cmake.org/cmake/help/latest/module/GoogleTest.html)
212+
- [CDash](https://cmake.org/cmake/help/book/mastering-cmake/chapter/CDash.html)
201213

202214
### Coverage
203215

src/projectcli/UserOpt.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "UserOpt.hpp"
22

33
#include <iostream>
4+
#include <span>
45
#include <stdexcept> // std::runtime_error
56
#include <string>
67
#include <string_view>
7-
#include <vector>
88

99
#include "config.h"
1010

@@ -40,32 +40,30 @@ void printVersionAndExit()
4040
exit(EXIT_SUCCESS);
4141
}
4242

43-
void parseUserOptions(int argc, char *argv[]) // NOLINT
43+
void parseUserOptions(const std::span<char*>& args)
4444
{
45-
// First argument is the program's name. Next argument *must* be a flag.
46-
if (argc < 2)
45+
if (args.size() == 0)
4746
{
4847
return;
4948
}
5049

51-
std::vector<std::string_view> args(argv + 1, argv + argc);
52-
5350
// May have more than one flag enabled in the future.
5451
// NOLINTNEXTLINE
55-
for (auto i = args.begin(); i != args.end(); ++i)
52+
for (std::string_view arg : args)
5653
{
57-
if (*i == "-h" || *i == "--help")
54+
if (arg == "-h" || arg == "--help")
5855
{
5956
printHelpAndExit();
6057
}
61-
else if (*i == "-v" || *i == "--version")
58+
else if (arg == "-v" || arg == "--version")
6259
{
6360
printVersionAndExit();
6461
}
6562
else
6663
{
67-
throw std::runtime_error(std::string("Option not recognized: ") +
68-
std::string(*i));
64+
using namespace std::string_literals;
65+
throw std::runtime_error("Option not recognized: "s +
66+
std::string(arg));
6967
}
7068
}
7169
}

src/projectcli/UserOpt.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef CPP_PROJ_USEROPT_HPP
88
#define CPP_PROJ_USEROPT_HPP
99

10+
#include <span>
1011
#include <string_view>
1112

1213
/**
@@ -27,13 +28,11 @@ inline std::string_view
2728
/**
2829
* Gets the user options from the command line.
2930
*
30-
* @param argc The command line argument count.
31-
* @param argv An array of C-style strings containing the command line
32-
* arguments.
31+
* @param args The command line arguments.
3332
*
3433
* @return void
3534
*/
36-
void parseUserOptions(int argc, char *argv[]); // NOLINT
35+
void parseUserOptions(const std::span<char*>& args);
3736

3837
/**
3938
* Print the usage of the application.
@@ -44,11 +43,11 @@ void printHelp();
4443
*/
4544
void printVersion();
4645
/**
47-
* Calls DG_Tickingbot::printHelp and exits with success.
46+
* Calls cpp_proj::printHelp and exits with success.
4847
*/
4948
[[noreturn]] void printHelpAndExit();
5049
/**
51-
* Calls DG_Tickingbot::printVersion and exits with success.
50+
* Calls cpp_proj::printVersion and exits with success.
5251
*/
5352
[[noreturn]] void printVersionAndExit();
5453

src/projectcli/main.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
*/
1010

1111
#include <cassert> // std::assert
12+
#include <cstddef> // std::size_t
1213
#include <cstdlib> // std::EXIT_SUCCESS, std::EXIT_FAILURE
1314
#include <iostream>
15+
#include <span>
1416

1517
#include "UserOpt.hpp"
1618
#include "tutorial_1.hpp"
@@ -19,20 +21,25 @@ using namespace cpp_proj;
1921

2022
int main(int argc, char *argv[])
2123
{
22-
assert(argc > 0); // NOLINT https://stackoverflow.com/q/2050961/3049315
24+
assert(argc > 0); // https://stackoverflow.com/q/2050961/3049315
2325
// https://stackoverflow.com/q/68878728/3049315
24-
progName = argv[0]; // NOLINT: Pointer arithmetic is inevitable here.
26+
progName = argv[0]; // NOLINT
27+
auto args = std::span(argv+1, // NOLINT
28+
static_cast<std::size_t>(argc - 1));
2529

2630
constexpr int i = 5;
2731

2832
try
2933
{
30-
parseUserOptions(argc, argv);
34+
parseUserOptions(args);
3135
}
3236
catch (const std::exception &e)
3337
{
3438
std::cerr << e.what() << std::endl;
35-
exit(EXIT_FAILURE);
39+
// Do not call `exit` directly, so that the destructor
40+
// of the exception may be called.
41+
// https://stackoverflow.com/a/28931492/3049315
42+
return EXIT_FAILURE;
3643
}
3744

3845
std::cout << "TESTING TUTORIAL 1:" << std::endl;
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
#include "tutorial_1.hpp"
2-
31
#include <gtest/gtest.h>
42

3+
#include "tutorial_1.hpp"
4+
55
// Demonstrate some basic assertions.
6-
TEST(HelloTest, BasicAssertions) {
7-
// Expect two strings not to be equal.
8-
EXPECT_STRNE("hello", "world");
9-
// Expect equality.
10-
EXPECT_EQ(7 * 6, 42);
6+
TEST(HelloTest, BasicAssertions)
7+
{
8+
// Expect two strings not to be equal.
9+
EXPECT_STRNE("hello", "world");
10+
// Expect equality.
11+
EXPECT_EQ(7 * 6, 42);
1112
}
1213

13-
TEST(Tutorial1, Factorial) {
14-
EXPECT_EQ(tut1::factorial(4), 24);
15-
}
14+
TEST(Tutorial1, Factorial) { EXPECT_EQ(tut1::factorial(4), 24); }
1615

17-
int main(int argc, char **argv) {
18-
testing::InitGoogleTest(&argc, argv);
19-
return RUN_ALL_TESTS();
16+
int main(int argc, char **argv)
17+
{
18+
testing::InitGoogleTest(&argc, argv);
19+
return RUN_ALL_TESTS();
2020
}

src/projectwx/splashscreen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ void showSplashScreen(const wxImage& splashImg, const unsigned long durationMs)
4646

4747
// yield main loop so splash screen can show
4848
wxYield();
49-
// Sleep for `durationMs/1000` seconds before destroying the splash screen and showing
50-
// main frame
49+
// Sleep for `durationMs/1000` seconds before destroying the splash screen
50+
// and showing main frame
5151
wxMilliSleep(durationMs);
5252
}
5353

0 commit comments

Comments
 (0)