Skip to content

Commit

Permalink
fix: add new test library for static analysis(#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
abeimler committed Jul 3, 2022
1 parent 2d680c9 commit 9305474
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ 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
PRIVATE
fmt::fmt
Eigen3::Eigen)

add_subdirectory(libs)

## tests
enable_testing()
add_test(NAME main COMMAND main)
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions test/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include(GenerateExportHeader)

add_subdirectory(mythirdpartylib)
target_disable_static_analysis(mythirdpartylib)
11 changes: 11 additions & 0 deletions test/libs/mythirdpartylib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

add_library(mythirdpartylib STATIC src/Foo.cpp)
generate_export_header(mythirdpartylib)

target_include_directories(mythirdpartylib
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_include_directories(mythirdpartylib
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
)
25 changes: 25 additions & 0 deletions test/libs/mythirdpartylib/include/Foo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <vector>
#include <string>

#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<std::string>& v);

private:
int m_a;
};

}
24 changes: 24 additions & 0 deletions test/libs/mythirdpartylib/src/Foo.cpp
Original file line number Diff line number Diff line change
@@ -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<std::string>& 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;

}

0 comments on commit 9305474

Please sign in to comment.