File tree Expand file tree Collapse file tree
include/github_actions_gtest_example Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ cmake_minimum_required (VERSION 3.10.2 )
2+ project (github_actions_gtest_example)
3+
4+ set (CMAKE_CXX_STANDARD 17)
5+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -g" )
6+
7+
8+ set (tool_dest "bin" )
9+ set (lib_dest "lib" )
10+ set (include_dest "include/${PROJECT_NAME} " )
11+
12+ add_subdirectory (src )
13+ add_subdirectory (test )
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #include < iostream>
4+
5+
6+ namespace githubActionsGtestExample {
7+
8+ std::string sayHello ();
9+ int add (int _first, int _second);
10+
11+ } // namespace githubActionsGtestExample
Original file line number Diff line number Diff line change 1+ set (header_path "${${PROJECT_NAME} _SOURCE_DIR}/include/${PROJECT_NAME} " )
2+ set (header ${header_path} /${PROJECT_NAME} .h)
3+ set (src ${PROJECT_NAME} .cpp)
4+
5+
6+ add_library (${PROJECT_NAME} SHARED
7+ ${header}
8+ ${src} )
9+ target_include_directories (${PROJECT_NAME}
10+ PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
11+ ${${PROJECT_NAME}_SOURCE_DIR}/include )
12+ target_link_libraries (${PROJECT_NAME}
13+ pthread )
14+
15+
16+ add_executable (${PROJECT_NAME} .info info.cpp )
17+ target_include_directories (${PROJECT_NAME} .info
18+ PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
19+ ${${PROJECT_NAME}_SOURCE_DIR}/include )
20+ target_link_libraries (${PROJECT_NAME} .info
21+ ${PROJECT_NAME} )
22+
23+
24+ install (TARGETS ${PROJECT_NAME}
25+ LIBRARY DESTINATION "${lib_dest} "
26+ ARCHIVE DESTINATION "${lib_dest} "
27+ COMPONENT library )
28+ install (TARGETS ${PROJECT_NAME} .info
29+ RUNTIME DESTINATION "${tool_dest} "
30+ COMPONENT library )
31+ install (FILES ${header} DESTINATION "${include_dest} " )
Original file line number Diff line number Diff line change 1+ #include < github_actions_gtest_example/github_actions_gtest_example.h>
2+
3+ namespace githubActionsGtestExample {
4+
5+ std::string sayHello () {
6+ return " Hello world from 'github-actions-gtest-example' project" ;
7+ }
8+
9+
10+ int add (int _first, int _second) {
11+ return _first + _second;
12+ }
13+
14+ } // namespace githubActionsGtestExample
Original file line number Diff line number Diff line change 1+ #include < github_actions_gtest_example/github_actions_gtest_example.h>
2+
3+ #include < iostream>
4+
5+ int main (int argc, char ** argv) {
6+
7+ std::cout << githubActionsGtestExample::sayHello () << std::endl;
8+
9+ return 0 ;
10+ }
Original file line number Diff line number Diff line change 1+ #include < gtest/gtest.h>
2+
3+ int main (int argc, char **argv) {
4+ ::testing::InitGoogleTest (&argc, argv);
5+
6+ std::cout << " TEST_DIR '" << TEST_DIR << " '" << std::endl;
7+ for (int i = 1 ; i < argc; ++i) {
8+ std::cout << " Input[" << i << " ]: " << argv[i] << std::endl;
9+ }
10+
11+ return RUN_ALL_TESTS ();
12+ }
Original file line number Diff line number Diff line change 1+ add_executable (${PROJECT_NAME} .test
2+ AllTests.cpp
3+ ${PROJECT_NAME} Test .cpp )
4+ target_link_libraries (${PROJECT_NAME} .test
5+ ${PROJECT_NAME} gtest pthread )
6+ target_compile_definitions (${PROJECT_NAME} .test
7+ PRIVATE TEST_DIR= "${CMAKE_CURRENT_LIST_DIR} /test" )
8+
9+ install (TARGETS ${PROJECT_NAME} .test
10+ DESTINATION "${tool_dest} " )
Original file line number Diff line number Diff line change 1+ #include < github_actions_gtest_example/github_actions_gtest_example.h>
2+
3+ #include < gtest/gtest.h>
4+
5+ TEST (githubActionsGtestExampleTest, firstTest) {
6+ EXPECT_TRUE ( 1 == 1 );
7+ }
8+
9+ TEST (githubActionsGtestExampleTest, addTest) {
10+ const int a = 1 ;
11+ const int b = 3 ;
12+ const int result = githubActionsGtestExample::add (a, b);
13+
14+ EXPECT_EQ ( result, a + b );
15+ }
You can’t perform that action at this time.
0 commit comments