Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9007664

Browse files
authored
Enable BUILDCC_TESTING for MSVC (#195)
1 parent c9c2cd8 commit 9007664

24 files changed

+132
-110
lines changed

.github/workflows/linux_gcc_cmake_build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ jobs:
191191
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}}
192192
run: cmake --build . --target cppcheck_static_analysis
193193

194-
- name: Build Debug for test
194+
- name: Build Debug and test
195195
# Linux has 2 cores
196196
run: |
197197
cmake --build --list-presets

.github/workflows/win_cmake_build.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ jobs:
4444
cmake --list-presets
4545
cmake --preset=${{env.BUILD_MSVC_PRESET}}
4646
47-
- name: Build
47+
- name: Build Debug and test
48+
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}}
49+
run: |
50+
cmake --build . --parallel 2 --config Debug
51+
ctest . --parallel 2 -C Debug
52+
53+
- name: Build Release
4854
# Linux has 2 cores
4955
run: |
5056
cmake --build --list-presets

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ endif()
4242

4343
# Testing
4444
set(BUILD_TESTING OFF CACHE BOOL "Third Party modules use these options")
45-
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" AND ${BUILDCC_TESTING})
45+
if (${BUILDCC_TESTING})
4646
set(TESTING ON)
4747
message("Enabling unit-testing")
4848
message("Compiler identification: ${CMAKE_CXX_COMPILER_ID}")
@@ -85,7 +85,7 @@ endif()
8585

8686
# Coverage
8787

88-
if (${TESTING})
88+
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" AND ${TESTING})
8989
include(cmake/coverage/lcov.cmake)
9090
include(cmake/coverage/gcovr.cmake)
9191
endif()

CMakePresets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"BUILDCC_BOOTSTRAP_THROUGH_CMAKE": true,
122122
"BUILDCC_PRECOMPILE_HEADERS": true,
123123
"BUILDCC_EXAMPLES": true,
124-
"BUILDCC_TESTING": false,
124+
"BUILDCC_TESTING": true,
125125
"BUILDCC_CLANGTIDY": false,
126126
"BUILDCC_CPPCHECK": false,
127127
"BUILDCC_DOCUMENTATION": false,

buildcc/lib/args/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ target_link_libraries(mock_args PUBLIC
2222

2323
CppUTest
2424
CppUTestExt
25-
gcov
25+
${TEST_LINK_LIBS}
2626
)
2727

2828
# Tests

buildcc/lib/args/test/test_args.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,6 @@ TEST(ArgsTestGroup, Args_MultipleCustomTarget) {
258258
}
259259

260260
int main(int ac, char **av) {
261+
MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
261262
return CommandLineTestRunner::RunAllTests(ac, av);
262263
}

buildcc/lib/env/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if (${TESTING})
2020

2121
CppUTest
2222
CppUTestExt
23-
gcov
23+
${TEST_LINK_LIBS}
2424
)
2525
target_compile_options(mock_env PUBLIC ${TEST_COMPILE_FLAGS} ${BUILD_COMPILE_FLAGS})
2626
target_link_options(mock_env PUBLIC ${TEST_LINK_FLAGS} ${BUILD_LINK_FLAGS})

buildcc/lib/env/include/env/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace buildcc::env {
4949
*/
5050
inline bool save_file(const char *name, const char *buf, size_t len,
5151
bool binary) {
52-
if (buf == nullptr) {
52+
if (name == nullptr || buf == nullptr) {
5353
return false;
5454
}
5555
std::ofstream ofs(name, binary ? std::ofstream::binary : std::ofstream::out);

buildcc/lib/env/test/test_env_util.cpp

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,13 @@ TEST(EnvUtilTestGroup, Util_SaveFile_NullptrName) {
3333
CHECK_FALSE(save);
3434
}
3535

36-
TEST(EnvUtilTestGroup, Util_SaveFile_BadWrite) {
37-
constexpr const char *const FILENAME = "BadWrite.txt";
38-
fs::remove(FILENAME);
39-
bool save = buildcc::env::save_file(FILENAME, "Hello", -1, false);
40-
CHECK_FALSE(save);
41-
}
42-
4336
TEST(EnvUtilTestGroup, Util_SaveFile_GoodWrite) {
4437
constexpr const char *const FILENAME = "GoodWrite.txt";
4538
fs::remove(FILENAME);
4639
bool save = buildcc::env::save_file(FILENAME, "Hello", false);
4740
CHECK_TRUE(save);
4841
}
4942

50-
TEST(EnvUtilTestGroup, Util_SaveFile_BadWrite_Binary) {
51-
constexpr const char *const FILENAME = "BadWrite_Binary.txt";
52-
fs::remove(FILENAME);
53-
bool save = buildcc::env::save_file(FILENAME, "Hello", -1, true);
54-
CHECK_FALSE(save);
55-
}
56-
5743
TEST(EnvUtilTestGroup, Util_SaveFile_GoodWrite_Binary) {
5844
constexpr const char *const FILENAME = "GoodWrite_Binary.txt";
5945
fs::remove(FILENAME);
@@ -69,22 +55,6 @@ TEST(EnvUtilTestGroup, Util_SaveFile_CheckDirectory) {
6955
CHECK_FALSE(save);
7056
}
7157

72-
TEST(EnvUtilTestGroup, Util_SaveFile_CannotWrite) {
73-
constexpr const char *const FILENAME = "CannotWrite.txt";
74-
fs::remove(FILENAME);
75-
bool save = buildcc::env::save_file(FILENAME, "Hello", false);
76-
CHECK_TRUE(save);
77-
78-
std::error_code err;
79-
fs::permissions(FILENAME, fs::perms::none, err);
80-
if (err) {
81-
FAIL("Cannot disable file permissions");
82-
}
83-
84-
save = buildcc::env::save_file(FILENAME, "Hello", false);
85-
CHECK_FALSE(save);
86-
}
87-
8858
// Load File
8959
TEST(EnvUtilTestGroup, Util_LoadFile_CheckDirectory) {
9060
// NOTE, This is a directory
@@ -143,6 +113,8 @@ TEST(EnvUtilTestGroup, Util_LoadFile_ReadTxt) {
143113
CHECK_TRUE(load);
144114
}
145115

116+
#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__MINGW64__)
117+
146118
TEST(EnvUtilTestGroup, Util_LoadFile_CannotOpen) {
147119
constexpr const char *const FILENAME = "CannotOpen.txt";
148120
buildcc::env::save_file(FILENAME, "Random Data", false);
@@ -159,6 +131,38 @@ TEST(EnvUtilTestGroup, Util_LoadFile_CannotOpen) {
159131
CHECK_FALSE(load);
160132
}
161133

134+
TEST(EnvUtilTestGroup, Util_SaveFile_BadWrite_Binary) {
135+
constexpr const char *const FILENAME = "BadWrite_Binary.txt";
136+
fs::remove(FILENAME);
137+
bool save = buildcc::env::save_file(FILENAME, "Hello", -1, true);
138+
CHECK_FALSE(save);
139+
}
140+
141+
TEST(EnvUtilTestGroup, Util_SaveFile_BadWrite) {
142+
constexpr const char *const FILENAME = "BadWrite.txt";
143+
fs::remove(FILENAME);
144+
bool save = buildcc::env::save_file(FILENAME, "Hello", -1, false);
145+
CHECK_FALSE(save);
146+
}
147+
148+
TEST(EnvUtilTestGroup, Util_SaveFile_CannotWrite) {
149+
constexpr const char *const FILENAME = "CannotWrite.txt";
150+
fs::remove(FILENAME);
151+
bool save = buildcc::env::save_file(FILENAME, "Hello", false);
152+
CHECK_TRUE(save);
153+
154+
std::error_code err;
155+
fs::permissions(FILENAME, fs::perms::none, err);
156+
if (err) {
157+
FAIL("Cannot disable file permissions");
158+
}
159+
160+
save = buildcc::env::save_file(FILENAME, "Hello", false);
161+
CHECK_FALSE(save);
162+
}
163+
164+
#endif
165+
162166
TEST(EnvUtilTestGroup, Util_Split) {
163167
{
164168
std::vector<std::string> paths = buildcc::env::split("", ':');

buildcc/lib/target/cmake/mock_target.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ target_link_libraries(mock_target PUBLIC
2525

2626
CppUTest
2727
CppUTestExt
28-
gcov
28+
${TEST_LINK_LIBS}
2929
)
3030

3131
# https://github.com/msys2/MINGW-packages/issues/2303

0 commit comments

Comments
 (0)