Skip to content

feat: add unit tests in ci #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Checks:
-modernize-use-trailing-return-type,-bugprone-easily-swappable-parameters,-readability-identifier-length'
WarningsAsErrors: '*'
HeaderFilterRegex: 'include/aws/.*\.h$'
ExcludeHeaderFilter: 'build/_deps/gtest-src.*'
FormatStyle: 'none'
CheckOptions:
- key: modernize-pass-by-value.ValuesOnly
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_CLANG_TIDY=clang-tidy
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_CLANG_TIDY=clang-tidy -DENABLE_UNIT_TESTS=ON

- name: Build It
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test It
run: cd build && make && ctest

build-on-arm-too:
runs-on: ubuntu-latest
steps:
Expand All @@ -43,8 +46,9 @@ jobs:
distro: ubuntu20.04
run: |
apt-get update && apt-get install -y cmake g++ clang-tidy libcurl4-openssl-dev
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_CLANG_TIDY=clang-tidy
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_CLANG_TIDY=clang-tidy -DENABLE_UNIT_TESTS=ON
cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
cd build && make && ctest

build-demo:
runs-on: ubuntu-latest
Expand Down
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ project(aws-lambda-runtime

option(ENABLE_LTO "Enables link-time optimization, requires compiler support." OFF)
option(ENABLE_TESTS "Enables building the test project, requires AWS C++ SDK." OFF)
option(ENABLE_UNIT_TESTS "Enables building the unit test project" OFF)
option(ENABLE_SANITIZERS "Enables ASan and UBSan." OFF)

add_library(${PROJECT_NAME}
Expand Down Expand Up @@ -90,11 +91,18 @@ else ()
target_compile_definitions(${PROJECT_NAME} PRIVATE "AWS_LAMBDA_LOG=0")
endif()


#tests
if (ENABLE_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
if (ENABLE_UNIT_TESTS)
enable_testing()
add_subdirectory(unittests)
endif()



#versioning
configure_file(
Expand Down
31 changes: 31 additions & 0 deletions unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
project(aws-lambda-runtime-tests LANGUAGES CXX)

include(FetchContent)
FetchContent_Declare(gtest
QUIET
URL https://github.com/google/googletest/archive/v1.15.2.tar.gz
)
# configure build of googletest
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF)
FetchContent_MakeAvailable(gtest)

add_executable(
unit_tests
no_op_test.cpp
)

target_link_libraries(unit_tests
PRIVATE
gtest_main
)

# automatic discovery of unit tests
include(GoogleTest)
gtest_discover_tests(unit_tests
PROPERTIES
LABELS "unit"
DISCOVERY_TIMEOUT # how long to wait (in seconds) before crashing
240
)
6 changes: 6 additions & 0 deletions unittests/no_op_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <gtest/gtest.h>

TEST(noop, dummy_test)
{
ASSERT_EQ(0, 0);
}
Loading