-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fangshuai03
committed
Jan 19, 2024
1 parent
92f0b16
commit a9bf5fe
Showing
10 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# CMake generated files | ||
CMakeCache.txt | ||
CMakeFiles | ||
cmake_install.cmake | ||
Makefile | ||
*.make | ||
*.cmake | ||
|
||
# Build artifacts | ||
build/ | ||
Release/ | ||
Debug/ | ||
*.o | ||
*.a | ||
*.so | ||
*.dylib | ||
*.lib | ||
*.dll | ||
*.exe | ||
*.out | ||
|
||
# Dependency directories (comment out if dependencies are tracked) | ||
# libs/ | ||
|
||
# Editor backups and temporary files | ||
*~ | ||
*.swp | ||
*.tmp | ||
|
||
# IDE specific files | ||
.vs/ | ||
.vscode/ | ||
*.code-workspace | ||
*.user | ||
*.suo | ||
*.userosscache | ||
*.sln | ||
*.opensdf | ||
*.ipch | ||
*.db | ||
*.opendb | ||
*.VC.db | ||
*.VC.VC.opendb | ||
_deps/ | ||
|
||
|
||
# Other files to ignore | ||
.DS_Store | ||
Thumbs.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
project(your_project) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
|
||
# 添加src目录 | ||
add_subdirectory(src) | ||
|
||
# 启用测试 | ||
enable_testing() | ||
add_subdirectory(tests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# CMake generated Testfile for | ||
# Source directory: /Users/fangshuai03/mini_project/c++/gtest_mini_project | ||
# Build directory: /Users/fangshuai03/mini_project/c++/gtest_mini_project | ||
# | ||
# This file includes the relevant testing commands required for | ||
# testing this directory and lists subdirectories to be tested as well. | ||
subdirs("src") | ||
subdirs("tests") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# 创建一个库 | ||
add_library(my_even my_even.cpp) | ||
|
||
# 指定这个库的头文件路径 | ||
target_include_directories(my_even PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "my_even.h" | ||
|
||
bool is_even(int num) { | ||
return (num & 1) == 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef MY_EVEN_HPP | ||
#define MY_EVEN_HPP | ||
|
||
bool is_even(int number); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# 下载和解压 Google Test | ||
include(FetchContent) | ||
FetchContent_Declare( | ||
googletest | ||
URL https://github.com/google/googletest/archive/release-1.10.0.zip | ||
) | ||
FetchContent_MakeAvailable(googletest) | ||
|
||
# 添加 Google Test 测试可执行文件 | ||
add_executable(test_demo test_demo.cpp) | ||
|
||
# 链接测试执行文件与库 | ||
target_link_libraries(test_demo gtest_main my_even) | ||
|
||
# 包含测试 | ||
include(GoogleTest) | ||
gtest_discover_tests(test_demo) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
#include "../src/my_even.h" | ||
#include <gtest/gtest.h> | ||
|
||
TEST(YourTest, IsEven) { | ||
EXPECT_TRUE(is_even(2)); | ||
EXPECT_FALSE(is_even(3)); | ||
} |