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
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef TARGET_MOCK_TEST_TARGET_UTIL_H_
2+
#define TARGET_MOCK_TEST_TARGET_UTIL_H_
3+
4+
#ifdef _WIN32
5+
#include <windows.h>
6+
#else
7+
#include <unistd.h>
8+
#endif
9+
10+
namespace buildcc::m {
11+
12+
inline void blocking_sleep(int seconds) {
13+
#ifdef _WIN32
14+
Sleep(seconds * 1000);
15+
#else
16+
sleep(seconds);
17+
#endif
18+
}
19+
20+
} // namespace buildcc::m
21+
22+
#endif

buildcc/lib/target/test/path/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ target_link_libraries(${TEST_NAME} PRIVATE
1515

1616
CppUTest
1717
CppUTestExt
18-
gcov
18+
${TEST_LINK_LIBS}
1919
)
2020
target_compile_options(${TEST_NAME} PRIVATE ${TEST_COMPILE_FLAGS})
2121
target_link_options(${TEST_NAME} PRIVATE ${TEST_LINK_FLAGS})

buildcc/lib/target/test/target/test_generator.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#include "target/generator.h"
22

3-
#include <unistd.h>
4-
53
#include "expect_command.h"
64
#include "expect_generator.h"
5+
#include "test_target_util.h"
76

87
#include "taskflow/taskflow.hpp"
98

@@ -162,7 +161,7 @@ TEST(GeneratorTestGroup, Generator_Rebuild_Inputs) {
162161
buildcc::m::GeneratorRunner(generator);
163162
}
164163

165-
sleep(1);
164+
buildcc::m::blocking_sleep(1);
166165
bool saved = buildcc::env::save_file(
167166
(buildcc::env::get_project_root_dir() / "new_source.cpp")
168167
.string()

buildcc/lib/target/test/target/test_target_external_lib.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "schema/target_serialization.h"
1111

1212
#include <iostream>
13-
#include <unistd.h>
1413

1514
// NOTE, Make sure all these includes are AFTER the system and header includes
1615
#include "CppUTest/CommandLineTestRunner.h"

buildcc/lib/target/test/target/test_target_lib_dep.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
#include "expect_command.h"
77
#include "expect_target.h"
8+
#include "test_target_util.h"
89

910
#include "target/target.h"
1011

1112
//
1213
#include "schema/target_serialization.h"
1314

1415
#include <iostream>
15-
#include <unistd.h>
1616

1717
// NOTE, Make sure all these includes are AFTER the system and header includes
1818
#include "CppUTest/CommandLineTestRunner.h"
@@ -234,7 +234,7 @@ TEST(TargetTestLibDep, TargetDep_UpdateExistingLibraryTest) {
234234
buildcc::m::TargetRunner(foolib);
235235

236236
// * To make sure that save_file is newer
237-
sleep(1);
237+
buildcc::m::blocking_sleep(1);
238238
bool saved = buildcc::env::save_file(
239239
foolib.GetTargetPath().string().c_str(), std::string{""}, false);
240240
CHECK_TRUE(saved);

buildcc/lib/target/test/target/test_target_pch.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#include <filesystem>
22

3-
#include <unistd.h>
4-
53
#include "constants.h"
64

75
#include "expect_command.h"
86
#include "expect_target.h"
7+
#include "test_target_util.h"
98

109
#include "target/target.h"
1110

@@ -128,7 +127,7 @@ TEST(TargetPchTestGroup, Target_AddPch_Rebuild) {
128127

129128
// Rebuild: Updated
130129
{
131-
sleep(1);
130+
buildcc::m::blocking_sleep(1);
132131
fs::path filename =
133132
fs::path(BUILD_SCRIPT_SOURCE) / "data" / "pch/pch_header_1.h";
134133
bool save = buildcc::env::save_file(filename.string().c_str(), "", false);
@@ -221,7 +220,7 @@ TEST(TargetPchTestGroup, Target_AddPch_CppRebuild) {
221220

222221
// Rebuild: Updated
223222
{
224-
sleep(1);
223+
buildcc::m::blocking_sleep(1);
225224
fs::path filename =
226225
fs::path(BUILD_SCRIPT_SOURCE) / "data" / "pch/pch_header_1.h";
227226
bool save = buildcc::env::save_file(filename.string().c_str(), "", false);

buildcc/lib/target/test/target/test_target_source.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#include "constants.h"
22

3-
#include <unistd.h>
4-
53
#include "expect_command.h"
64
#include "expect_target.h"
5+
#include "test_target_util.h"
76

87
#include "target/target.h"
98

@@ -193,7 +192,7 @@ TEST(TargetTestSourceGroup, Target_Build_SourceRecompile) {
193192
CHECK_FALSE(loaded_sources.find(new_source_file) == loaded_sources.end());
194193
}
195194
{
196-
sleep(1);
195+
buildcc::m::blocking_sleep(1);
197196

198197
// * Force copy to trigger recompile for NEW_SOURCE
199198
// *2 Current file is updated

buildcc/lib/target/test/target/test_target_user_deps.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#include <unistd.h>
2-
31
#include "constants.h"
42

53
#include "expect_command.h"
64
#include "expect_target.h"
5+
#include "test_target_util.h"
76

87
#include "target/target.h"
98

@@ -80,7 +79,7 @@ TEST(TargetTestUserDepsGroup, Target_Build_CompileDeps_Rebuild) {
8079

8180
{
8281
// * To make sure that save_file is newer
83-
sleep(1);
82+
buildcc::m::blocking_sleep(1);
8483
const fs::path new_source =
8584
buildcc::env::get_project_root_dir() / "data" / "new_source.cpp";
8685
std::string buf{""};
@@ -119,7 +118,7 @@ TEST(TargetTestUserDepsGroup, Target_Build_LinkDeps_Rebuild) {
119118

120119
{
121120
// * To make sure that save_file is newer
122-
sleep(1);
121+
buildcc::m::blocking_sleep(1);
123122
const fs::path new_source =
124123
buildcc::env::get_project_root_dir() / "data" / "new_source.cpp";
125124
std::string buf{""};

buildcc/lib/toolchain/CMakeLists.txt

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

2525
CppUTest
2626
CppUTestExt
27-
gcov
27+
${TEST_LINK_LIBS}
2828
)
2929

3030
add_executable(test_toolchain_verify

0 commit comments

Comments
 (0)