Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorMartin Jeřábek2024-03-01 11:15:27 +0100
committerMartin Hořeňovský2024-03-01 21:24:45 +0100
commitcde35096641d55b4aa0f743bb03e04703fbb5e9c (patch)
tree7072371d7a380dcac9142a4ef8e701756e3fbcd2 /examples
parent7677c1658eb4417ec60649589610bf4e3d731bc9 (diff)
downloadcatch3-cde35096641d55b4aa0f743bb03e04703fbb5e9c.tar.gz
Fix various useful clang-tidy warnings
* bugprone-branch-clone * bugprone-copy-constructor-init * bugprone-empty-catch * bugprone-sizeof-expression * bugprone-switch-missing-default-case * bugprone-unused-local-non-trivial-variable * clang-analyzer-core.uninitialized.Assign * clang-analyzer-cplusplus.Move * clang-analyzer-optin.cplusplus.VirtualCall * modernize-loop-convert * modernize-raw-string-literal * modernize-use-equals-default * modernize-use-override * modernize-use-using * performance-avoid-endl * performance-inefficient-string-concatenation * performance-inefficient-vector-operation * performance-noexcept-move-constructor * performance-unnecessary-value-param (and improve generator example) * readability-duplicate-include * readability-inconsistent-declaration-parameter-name * readability-non-const-parameter * readability-redundant-casting * readability-redundant-member-init * readability-redundant-smartptr-get * readability-static-accessed-through-instance * unused variable in amalgamted tests
Diffstat (limited to 'examples')
-rw-r--r--examples/210-Evt-EventListeners.cpp3
-rw-r--r--examples/231-Cfg-OutputStreams.cpp2
-rw-r--r--examples/232-Cfg-CustomMain.cpp2
-rw-r--r--examples/300-Gen-OwnGenerator.cpp2
-rw-r--r--examples/301-Gen-MapTypeConversion.cpp17
5 files changed, 13 insertions, 13 deletions
diff --git a/examples/210-Evt-EventListeners.cpp b/examples/210-Evt-EventListeners.cpp
index 56b050d4..d05dfaaa 100644
--- a/examples/210-Evt-EventListeners.cpp
+++ b/examples/210-Evt-EventListeners.cpp
@@ -385,8 +385,7 @@ struct MyListener : Catch::EventListenerBase {
CATCH_REGISTER_LISTENER( MyListener )
// Get rid of Wweak-tables
-MyListener::~MyListener() {}
-
+MyListener::~MyListener() = default;
// -----------------------------------------------------------------------
// 3. Test cases:
diff --git a/examples/231-Cfg-OutputStreams.cpp b/examples/231-Cfg-OutputStreams.cpp
index da1713cf..5aee38bc 100644
--- a/examples/231-Cfg-OutputStreams.cpp
+++ b/examples/231-Cfg-OutputStreams.cpp
@@ -22,7 +22,7 @@ class out_buff : public std::stringbuf {
std::FILE* m_stream;
public:
out_buff(std::FILE* stream):m_stream(stream) {}
- ~out_buff();
+ ~out_buff() override;
int sync() override {
int ret = 0;
for (unsigned char c : str()) {
diff --git a/examples/232-Cfg-CustomMain.cpp b/examples/232-Cfg-CustomMain.cpp
index 69fba7f1..27040993 100644
--- a/examples/232-Cfg-CustomMain.cpp
+++ b/examples/232-Cfg-CustomMain.cpp
@@ -35,7 +35,7 @@ int main(int argc, char** argv) {
return returnCode;
// if set on the command line then 'height' is now set at this point
- std::cout << "height: " << height << std::endl;
+ std::cout << "height: " << height << '\n';
return session.run();
}
diff --git a/examples/300-Gen-OwnGenerator.cpp b/examples/300-Gen-OwnGenerator.cpp
index b5d951ac..9cb02e39 100644
--- a/examples/300-Gen-OwnGenerator.cpp
+++ b/examples/300-Gen-OwnGenerator.cpp
@@ -21,7 +21,7 @@
namespace {
// This class shows how to implement a simple generator for Catch tests
-class RandomIntGenerator : public Catch::Generators::IGenerator<int> {
+class RandomIntGenerator final : public Catch::Generators::IGenerator<int> {
std::minstd_rand m_rand;
std::uniform_int_distribution<> m_dist;
int current_number;
diff --git a/examples/301-Gen-MapTypeConversion.cpp b/examples/301-Gen-MapTypeConversion.cpp
index a065d87a..0a284483 100644
--- a/examples/301-Gen-MapTypeConversion.cpp
+++ b/examples/301-Gen-MapTypeConversion.cpp
@@ -24,12 +24,12 @@ namespace {
// Returns a line from a stream. You could have it e.g. read lines from
// a file, but to avoid problems with paths in examples, we will use
// a fixed stringstream.
-class LineGenerator : public Catch::Generators::IGenerator<std::string> {
+class LineGenerator final : public Catch::Generators::IGenerator<std::string> {
std::string m_line;
std::stringstream m_stream;
public:
- LineGenerator() {
- m_stream.str("1\n2\n3\n4\n");
+ explicit LineGenerator( std::string const& lines ) {
+ m_stream.str( lines );
if (!next()) {
Catch::Generators::Detail::throw_generator_exception("Couldn't read a single line");
}
@@ -49,18 +49,19 @@ std::string const& LineGenerator::get() const {
// This helper function provides a nicer UX when instantiating the generator
// Notice that it returns an instance of GeneratorWrapper<std::string>, which
// is a value-wrapper around std::unique_ptr<IGenerator<std::string>>.
-Catch::Generators::GeneratorWrapper<std::string> lines(std::string /* ignored for example */) {
+Catch::Generators::GeneratorWrapper<std::string>
+lines( std::string const& lines ) {
return Catch::Generators::GeneratorWrapper<std::string>(
- new LineGenerator()
- );
+ new LineGenerator( lines ) );
}
} // end anonymous namespace
TEST_CASE("filter can convert types inside the generator expression", "[example][generator]") {
- auto num = GENERATE(map<int>([](std::string const& line) { return std::stoi(line); },
- lines("fake-file")));
+ auto num = GENERATE(
+ map<int>( []( std::string const& line ) { return std::stoi( line ); },
+ lines( "1\n2\n3\n4\n" ) ) );
REQUIRE(num > 0);
}