Skip to content

Enable BUILDCC_TESTING for MSVC #195

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

Merged
merged 11 commits into from
Feb 21, 2022
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/linux_gcc_cmake_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ jobs:
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_DEV_SINGLE}}
run: cmake --build . --target cppcheck_static_analysis

- name: Build Debug for test
- name: Build Debug and test
# Linux has 2 cores
run: |
cmake --build --list-presets
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/win_cmake_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ jobs:
cmake --list-presets
cmake --preset=${{env.BUILD_MSVC_PRESET}}

- name: Build
- name: Build Debug and test
working-directory: ${{github.workspace}}/${{env.BUILD_FOLDER_MSVC_DEV_ALL}}
run: |
cmake --build . --parallel 2 --config Debug
ctest . --parallel 2 -C Debug

- name: Build Release
# Linux has 2 cores
run: |
cmake --build --list-presets
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ endif()

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

# Coverage

if (${TESTING})
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" AND ${TESTING})
include(cmake/coverage/lcov.cmake)
include(cmake/coverage/gcovr.cmake)
endif()
Expand Down
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"BUILDCC_BOOTSTRAP_THROUGH_CMAKE": true,
"BUILDCC_PRECOMPILE_HEADERS": true,
"BUILDCC_EXAMPLES": true,
"BUILDCC_TESTING": false,
"BUILDCC_TESTING": true,
"BUILDCC_CLANGTIDY": false,
"BUILDCC_CPPCHECK": false,
"BUILDCC_DOCUMENTATION": false,
Expand Down
2 changes: 1 addition & 1 deletion buildcc/lib/args/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ target_link_libraries(mock_args PUBLIC

CppUTest
CppUTestExt
gcov
${TEST_LINK_LIBS}
)

# Tests
Expand Down
1 change: 1 addition & 0 deletions buildcc/lib/args/test/test_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,5 +258,6 @@ TEST(ArgsTestGroup, Args_MultipleCustomTarget) {
}

int main(int ac, char **av) {
MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
return CommandLineTestRunner::RunAllTests(ac, av);
}
2 changes: 1 addition & 1 deletion buildcc/lib/env/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (${TESTING})

CppUTest
CppUTestExt
gcov
${TEST_LINK_LIBS}
)
target_compile_options(mock_env PUBLIC ${TEST_COMPILE_FLAGS} ${BUILD_COMPILE_FLAGS})
target_link_options(mock_env PUBLIC ${TEST_LINK_FLAGS} ${BUILD_LINK_FLAGS})
Expand Down
2 changes: 1 addition & 1 deletion buildcc/lib/env/include/env/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace buildcc::env {
*/
inline bool save_file(const char *name, const char *buf, size_t len,
bool binary) {
if (buf == nullptr) {
if (name == nullptr || buf == nullptr) {
return false;
}
std::ofstream ofs(name, binary ? std::ofstream::binary : std::ofstream::out);
Expand Down
64 changes: 34 additions & 30 deletions buildcc/lib/env/test/test_env_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,13 @@ TEST(EnvUtilTestGroup, Util_SaveFile_NullptrName) {
CHECK_FALSE(save);
}

TEST(EnvUtilTestGroup, Util_SaveFile_BadWrite) {
constexpr const char *const FILENAME = "BadWrite.txt";
fs::remove(FILENAME);
bool save = buildcc::env::save_file(FILENAME, "Hello", -1, false);
CHECK_FALSE(save);
}

TEST(EnvUtilTestGroup, Util_SaveFile_GoodWrite) {
constexpr const char *const FILENAME = "GoodWrite.txt";
fs::remove(FILENAME);
bool save = buildcc::env::save_file(FILENAME, "Hello", false);
CHECK_TRUE(save);
}

TEST(EnvUtilTestGroup, Util_SaveFile_BadWrite_Binary) {
constexpr const char *const FILENAME = "BadWrite_Binary.txt";
fs::remove(FILENAME);
bool save = buildcc::env::save_file(FILENAME, "Hello", -1, true);
CHECK_FALSE(save);
}

TEST(EnvUtilTestGroup, Util_SaveFile_GoodWrite_Binary) {
constexpr const char *const FILENAME = "GoodWrite_Binary.txt";
fs::remove(FILENAME);
Expand All @@ -69,22 +55,6 @@ TEST(EnvUtilTestGroup, Util_SaveFile_CheckDirectory) {
CHECK_FALSE(save);
}

TEST(EnvUtilTestGroup, Util_SaveFile_CannotWrite) {
constexpr const char *const FILENAME = "CannotWrite.txt";
fs::remove(FILENAME);
bool save = buildcc::env::save_file(FILENAME, "Hello", false);
CHECK_TRUE(save);

std::error_code err;
fs::permissions(FILENAME, fs::perms::none, err);
if (err) {
FAIL("Cannot disable file permissions");
}

save = buildcc::env::save_file(FILENAME, "Hello", false);
CHECK_FALSE(save);
}

// Load File
TEST(EnvUtilTestGroup, Util_LoadFile_CheckDirectory) {
// NOTE, This is a directory
Expand Down Expand Up @@ -143,6 +113,8 @@ TEST(EnvUtilTestGroup, Util_LoadFile_ReadTxt) {
CHECK_TRUE(load);
}

#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__MINGW64__)

TEST(EnvUtilTestGroup, Util_LoadFile_CannotOpen) {
constexpr const char *const FILENAME = "CannotOpen.txt";
buildcc::env::save_file(FILENAME, "Random Data", false);
Expand All @@ -159,6 +131,38 @@ TEST(EnvUtilTestGroup, Util_LoadFile_CannotOpen) {
CHECK_FALSE(load);
}

TEST(EnvUtilTestGroup, Util_SaveFile_BadWrite_Binary) {
constexpr const char *const FILENAME = "BadWrite_Binary.txt";
fs::remove(FILENAME);
bool save = buildcc::env::save_file(FILENAME, "Hello", -1, true);
CHECK_FALSE(save);
}

TEST(EnvUtilTestGroup, Util_SaveFile_BadWrite) {
constexpr const char *const FILENAME = "BadWrite.txt";
fs::remove(FILENAME);
bool save = buildcc::env::save_file(FILENAME, "Hello", -1, false);
CHECK_FALSE(save);
}

TEST(EnvUtilTestGroup, Util_SaveFile_CannotWrite) {
constexpr const char *const FILENAME = "CannotWrite.txt";
fs::remove(FILENAME);
bool save = buildcc::env::save_file(FILENAME, "Hello", false);
CHECK_TRUE(save);

std::error_code err;
fs::permissions(FILENAME, fs::perms::none, err);
if (err) {
FAIL("Cannot disable file permissions");
}

save = buildcc::env::save_file(FILENAME, "Hello", false);
CHECK_FALSE(save);
}

#endif

TEST(EnvUtilTestGroup, Util_Split) {
{
std::vector<std::string> paths = buildcc::env::split("", ':');
Expand Down
2 changes: 1 addition & 1 deletion buildcc/lib/target/cmake/mock_target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ target_link_libraries(mock_target PUBLIC

CppUTest
CppUTestExt
gcov
${TEST_LINK_LIBS}
)

# https://github.com/msys2/MINGW-packages/issues/2303
Expand Down
22 changes: 22 additions & 0 deletions buildcc/lib/target/mock/test_target_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef TARGET_MOCK_TEST_TARGET_UTIL_H_
#define TARGET_MOCK_TEST_TARGET_UTIL_H_

#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif

namespace buildcc::m {

inline void blocking_sleep(int seconds) {
#ifdef _WIN32
Sleep(seconds * 1000);
#else
sleep(seconds);
#endif
}

} // namespace buildcc::m

#endif
2 changes: 1 addition & 1 deletion buildcc/lib/target/test/path/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ target_link_libraries(${TEST_NAME} PRIVATE

CppUTest
CppUTestExt
gcov
${TEST_LINK_LIBS}
)
target_compile_options(${TEST_NAME} PRIVATE ${TEST_COMPILE_FLAGS})
target_link_options(${TEST_NAME} PRIVATE ${TEST_LINK_FLAGS})
Expand Down
5 changes: 2 additions & 3 deletions buildcc/lib/target/test/target/test_generator.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "target/generator.h"

#include <unistd.h>

#include "expect_command.h"
#include "expect_generator.h"
#include "test_target_util.h"

#include "taskflow/taskflow.hpp"

Expand Down Expand Up @@ -162,7 +161,7 @@ TEST(GeneratorTestGroup, Generator_Rebuild_Inputs) {
buildcc::m::GeneratorRunner(generator);
}

sleep(1);
buildcc::m::blocking_sleep(1);
bool saved = buildcc::env::save_file(
(buildcc::env::get_project_root_dir() / "new_source.cpp")
.string()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "schema/target_serialization.h"

#include <iostream>
#include <unistd.h>

// NOTE, Make sure all these includes are AFTER the system and header includes
#include "CppUTest/CommandLineTestRunner.h"
Expand Down
4 changes: 2 additions & 2 deletions buildcc/lib/target/test/target/test_target_lib_dep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

#include "expect_command.h"
#include "expect_target.h"
#include "test_target_util.h"

#include "target/target.h"

//
#include "schema/target_serialization.h"

#include <iostream>
#include <unistd.h>

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

// * To make sure that save_file is newer
sleep(1);
buildcc::m::blocking_sleep(1);
bool saved = buildcc::env::save_file(
foolib.GetTargetPath().string().c_str(), std::string{""}, false);
CHECK_TRUE(saved);
Expand Down
7 changes: 3 additions & 4 deletions buildcc/lib/target/test/target/test_target_pch.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include <filesystem>

#include <unistd.h>

#include "constants.h"

#include "expect_command.h"
#include "expect_target.h"
#include "test_target_util.h"

#include "target/target.h"

Expand Down Expand Up @@ -128,7 +127,7 @@ TEST(TargetPchTestGroup, Target_AddPch_Rebuild) {

// Rebuild: Updated
{
sleep(1);
buildcc::m::blocking_sleep(1);
fs::path filename =
fs::path(BUILD_SCRIPT_SOURCE) / "data" / "pch/pch_header_1.h";
bool save = buildcc::env::save_file(filename.string().c_str(), "", false);
Expand Down Expand Up @@ -221,7 +220,7 @@ TEST(TargetPchTestGroup, Target_AddPch_CppRebuild) {

// Rebuild: Updated
{
sleep(1);
buildcc::m::blocking_sleep(1);
fs::path filename =
fs::path(BUILD_SCRIPT_SOURCE) / "data" / "pch/pch_header_1.h";
bool save = buildcc::env::save_file(filename.string().c_str(), "", false);
Expand Down
5 changes: 2 additions & 3 deletions buildcc/lib/target/test/target/test_target_source.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "constants.h"

#include <unistd.h>

#include "expect_command.h"
#include "expect_target.h"
#include "test_target_util.h"

#include "target/target.h"

Expand Down Expand Up @@ -193,7 +192,7 @@ TEST(TargetTestSourceGroup, Target_Build_SourceRecompile) {
CHECK_FALSE(loaded_sources.find(new_source_file) == loaded_sources.end());
}
{
sleep(1);
buildcc::m::blocking_sleep(1);

// * Force copy to trigger recompile for NEW_SOURCE
// *2 Current file is updated
Expand Down
7 changes: 3 additions & 4 deletions buildcc/lib/target/test/target/test_target_user_deps.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include <unistd.h>

#include "constants.h"

#include "expect_command.h"
#include "expect_target.h"
#include "test_target_util.h"

#include "target/target.h"

Expand Down Expand Up @@ -80,7 +79,7 @@ TEST(TargetTestUserDepsGroup, Target_Build_CompileDeps_Rebuild) {

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

{
// * To make sure that save_file is newer
sleep(1);
buildcc::m::blocking_sleep(1);
const fs::path new_source =
buildcc::env::get_project_root_dir() / "data" / "new_source.cpp";
std::string buf{""};
Expand Down
2 changes: 1 addition & 1 deletion buildcc/lib/toolchain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (${TESTING})

CppUTest
CppUTestExt
gcov
${TEST_LINK_LIBS}
)

add_executable(test_toolchain_verify
Expand Down
Loading