From 9305474df6db280d34e77ba66154b957b7e19ee2 Mon Sep 17 00:00:00 2001 From: abeimler Date: Sun, 3 Jul 2022 23:50:28 +0200 Subject: [PATCH] fix: add new test library for static analysis(#133) --- test/CMakeLists.txt | 7 ++++++- test/libs/CMakeLists.txt | 4 ++++ test/libs/mythirdpartylib/CMakeLists.txt | 11 ++++++++++ test/libs/mythirdpartylib/include/Foo.hpp | 25 +++++++++++++++++++++++ test/libs/mythirdpartylib/src/Foo.cpp | 24 ++++++++++++++++++++++ 5 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 test/libs/CMakeLists.txt create mode 100644 test/libs/mythirdpartylib/CMakeLists.txt create mode 100644 test/libs/mythirdpartylib/include/Foo.hpp create mode 100644 test/libs/mythirdpartylib/src/Foo.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 124368e3..c43767dc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -81,7 +81,6 @@ set(DEPENDENCIES_CONFIGURED fmt Eigen3 docopt) foreach(DEPENDENCY ${DEPENDENCIES_CONFIGURED}) find_package(${DEPENDENCY} CONFIG REQUIRED) endforeach() -target_disable_static_analysis(Eigen3::Eigen) target_link_system_libraries( main @@ -89,6 +88,8 @@ target_link_system_libraries( fmt::fmt Eigen3::Eigen) +add_subdirectory(libs) + ## tests enable_testing() add_test(NAME main COMMAND main) @@ -116,6 +117,10 @@ target_link_system_libraries( PRIVATE fmt::fmt Eigen3::Eigen) +target_link_system_libraries( + lib2 + PRIVATE + mythirdpartylib) # package everything automatically package_project( diff --git a/test/libs/CMakeLists.txt b/test/libs/CMakeLists.txt new file mode 100644 index 00000000..26b66ab0 --- /dev/null +++ b/test/libs/CMakeLists.txt @@ -0,0 +1,4 @@ +include(GenerateExportHeader) + +add_subdirectory(mythirdpartylib) +target_disable_static_analysis(mythirdpartylib) diff --git a/test/libs/mythirdpartylib/CMakeLists.txt b/test/libs/mythirdpartylib/CMakeLists.txt new file mode 100644 index 00000000..ddc7e17b --- /dev/null +++ b/test/libs/mythirdpartylib/CMakeLists.txt @@ -0,0 +1,11 @@ + +add_library(mythirdpartylib STATIC src/Foo.cpp) +generate_export_header(mythirdpartylib) + +target_include_directories(mythirdpartylib + PUBLIC $ + $ +) +target_include_directories(mythirdpartylib + PUBLIC $ +) \ No newline at end of file diff --git a/test/libs/mythirdpartylib/include/Foo.hpp b/test/libs/mythirdpartylib/include/Foo.hpp new file mode 100644 index 00000000..24621a36 --- /dev/null +++ b/test/libs/mythirdpartylib/include/Foo.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include +#include + +#include "mythirdpartylib_export.h" + +namespace mythirdpartylib { + +class MYTHIRDPARTYLIB_EXPORT Foo { +public: + Foo() = default; + + /*implicit*/ Foo(int a) : m_a(a) {} + + int a() const { return m_a; } + + void update(bool b, bool c, bool d); + void bad(std::vector& v); + +private: + int m_a; +}; + +} \ No newline at end of file diff --git a/test/libs/mythirdpartylib/src/Foo.cpp b/test/libs/mythirdpartylib/src/Foo.cpp new file mode 100644 index 00000000..f83ced37 --- /dev/null +++ b/test/libs/mythirdpartylib/src/Foo.cpp @@ -0,0 +1,24 @@ +#include "Foo.hpp" + +namespace mythirdpartylib { + +void Foo::update(bool b, bool c, bool d) { + int e = b + d; + m_a = e; +} + +void Foo::bad(std::vector& v) { + std::string val = "hello"; + int index = -1; // bad, plus should use gsl::index + for (int i = 0; i < v.size(); ++i) { + if (v[i] == val) { + index = i; + break; + } + } +} + +static Foo foo (5); +static Foo bar = 42; + +} \ No newline at end of file