diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c3ed3b..23ded48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ set(CMAKE_CXX_STANDARD 11) option(RUNCPP2_UPDATE_DEFAULT_YAMLS "Update default yaml files" OFF) +set(RUNCPP2_CONFIG_VERSION "1" CACHE STRING "Default Config Version") + if (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) option(RUNCPP2_WARNINGS_AS_ERRORS "Treat warnings as errors" ON) option(RUNCPP2_BUILD_TESTS "Build runcpp2 tests" ON) @@ -55,17 +57,18 @@ function(get_version_from_git OUTPUT_VARIABLE) ) if(TAG_ON_COMMIT EQUAL 0) - set(VERSION ${GIT_TAG}) + set(VERSION "${GIT_TAG}") else() set(VERSION "${GIT_TAG}-${GIT_COMMIT_HASH}") endif() else() # No tags found, use v0.0.0 with commit hash # set(VERSION "v0.0.0-${GIT_COMMIT_HASH}") + message(FATAL_ERROR "Failed to get tag: ${GIT_TAG}") endif() - set(${OUTPUT_VARIABLE} ${VERSION} PARENT_SCOPE) + set(${OUTPUT_VARIABLE} "${VERSION}" PARENT_SCOPE) endfunction() # Call the function and store the result @@ -211,8 +214,9 @@ endif() target_compile_options(runcpp2 PRIVATE "${RUNCPP2_STANDARD_COMPILE_FLAGS}") -# Define the version macro -target_compile_definitions(runcpp2 PUBLIC RUNCPP2_VERSION="${RUNCPP2_PROJECT_VERSION}") +# Define the runcpp2 and default config version macro +target_compile_definitions(runcpp2 PUBLIC RUNCPP2_VERSION="${RUNCPP2_PROJECT_VERSION}" + RUNCPP2_CONFIG_VERSION=${RUNCPP2_CONFIG_VERSION}) # ========================================================================= # runcpp2 executable @@ -233,6 +237,7 @@ target_link_libraries(runcpp2_override PRIVATE ${RUNCPP2_PRIVATE_LINK_LIBS}) target_link_libraries(runcpp2_override PUBLIC ${RUNCPP2_PUBLIC_LINK_LIBS}) target_compile_options(runcpp2_override PRIVATE "${RUNCPP2_STANDARD_COMPILE_FLAGS}") target_compile_definitions(runcpp2_override PUBLIC RUNCPP2_VERSION="${RUNCPP2_PROJECT_VERSION}" + RUNCPP2_CONFIG_VERSION=${RUNCPP2_CONFIG_VERSION} INTERNAL_RUNCPP2_UNIT_TESTS=1) if(RUNCPP2_BUILD_TESTS) add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Src/Tests") diff --git a/External/CppOverride b/External/CppOverride index 0f4c252..3404406 160000 --- a/External/CppOverride +++ b/External/CppOverride @@ -1 +1 @@ -Subproject commit 0f4c252b0811ff58e1635b8e67c494aaef6a948e +Subproject commit 3404406e7351772770667afd8bf0d5e5fa90c8ea diff --git a/Include/Tests/BuildsManager/MockComponents.hpp b/Include/Tests/BuildsManager/MockComponents.hpp index 32d8e48..15b7770 100644 --- a/Include/Tests/BuildsManager/MockComponents.hpp +++ b/Include/Tests/BuildsManager/MockComponents.hpp @@ -17,21 +17,21 @@ namespace ghc { namespace filesystem { - CO_OVERRIDE_METHOD( OverrideInstance, + CO_INSERT_METHOD( OverrideInstance, bool, Mock_exists, (const path&, std::error_code&), /* no prepend */, noexcept) - CO_OVERRIDE_METHOD( OverrideInstance, + CO_INSERT_METHOD( OverrideInstance, bool, Mock_create_directories, (const path&, std::error_code&), /* no prepend */, noexcept) - CO_OVERRIDE_METHOD( OverrideInstance, + CO_INSERT_METHOD( OverrideInstance, bool, Mock_remove_all, (const path&, std::error_code&), @@ -45,10 +45,10 @@ namespace std class Mock_ifstream { public: - CO_OVERRIDE_MEMBER_METHOD_CTOR(OverrideInstance, Mock_ifstream, const ghc::filesystem::path&) - CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, std::string, rdbuf, ()) - CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, bool, is_open, ()) - CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, void, close, ()) + CO_INSERT_MEMBER_METHOD_CTOR(OverrideInstance, Mock_ifstream, const ghc::filesystem::path&) + CO_INSERT_MEMBER_METHOD(OverrideInstance, std::string, rdbuf, ()) + CO_INSERT_MEMBER_METHOD(OverrideInstance, bool, is_open, ()) + CO_INSERT_MEMBER_METHOD(OverrideInstance, void, close, ()) }; class Mock_ofstream @@ -56,10 +56,10 @@ namespace std public: std::stringstream StringStream; - CO_OVERRIDE_MEMBER_METHOD_CTOR(OverrideInstance, Mock_ofstream, const ghc::filesystem::path&) + CO_INSERT_MEMBER_METHOD_CTOR(OverrideInstance, Mock_ofstream, const ghc::filesystem::path&) - CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, bool, is_open, ()) - CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, void, close, ()) + CO_INSERT_MEMBER_METHOD(OverrideInstance, bool, is_open, ()) + CO_INSERT_MEMBER_METHOD(OverrideInstance, void, close, ()) template friend Mock_ofstream& operator<<(Mock_ofstream&, T const&); @@ -70,7 +70,7 @@ namespace std { static_assert(std::is_same::value, "We are only mocking std string"); public: - CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, std::size_t, operator(), (T)) + CO_INSERT_MEMBER_METHOD(OverrideInstance, std::size_t, operator(), (T)) }; template diff --git a/Include/Tests/ConfigParsing/MockComponents.hpp b/Include/Tests/ConfigParsing/MockComponents.hpp index d1efe15..f06f8e0 100644 --- a/Include/Tests/ConfigParsing/MockComponents.hpp +++ b/Include/Tests/ConfigParsing/MockComponents.hpp @@ -16,14 +16,14 @@ namespace ghc { namespace filesystem { - CO_OVERRIDE_METHOD( OverrideInstance, + CO_INSERT_METHOD( OverrideInstance, bool, Mock_exists, (const std::string&, std::error_code&), /* no prepend */, noexcept) - CO_OVERRIDE_METHOD( OverrideInstance, + CO_INSERT_METHOD( OverrideInstance, bool, Mock_is_directory, (const std::string&, std::error_code&), @@ -37,12 +37,12 @@ namespace std class Mock_ifstream { public: - CO_OVERRIDE_MEMBER_METHOD_CTOR( OverrideInstance, + CO_INSERT_MEMBER_METHOD_CTOR( OverrideInstance, Mock_ifstream, const ghc::filesystem::path&) - CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, bool, operator!, ()) - CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, std::string, rdbuf, ()) - CO_OVERRIDE_METHOD( OverrideInstance, + CO_INSERT_MEMBER_METHOD(OverrideInstance, bool, operator!, ()) + CO_INSERT_MEMBER_METHOD(OverrideInstance, std::string, rdbuf, ()) + CO_INSERT_METHOD( OverrideInstance, Mock_ifstream&, operator<<, (Mock_ifstream&, T const&), diff --git a/Include/Tests/IncludeManager/MockComponents.hpp b/Include/Tests/IncludeManager/MockComponents.hpp index 10575ed..7fddc0e 100644 --- a/Include/Tests/IncludeManager/MockComponents.hpp +++ b/Include/Tests/IncludeManager/MockComponents.hpp @@ -16,21 +16,21 @@ namespace ghc { namespace filesystem { - CO_OVERRIDE_METHOD( OverrideInstance, + CO_INSERT_METHOD( OverrideInstance, bool, Mock_exists, (const path&, std::error_code&), /* no prepend */, noexcept) - CO_OVERRIDE_METHOD( OverrideInstance, + CO_INSERT_METHOD( OverrideInstance, bool, Mock_create_directories, (const path&, std::error_code&), /* no prepend */, noexcept) - CO_OVERRIDE_METHOD( OverrideInstance, + CO_INSERT_METHOD( OverrideInstance, file_time_type, Mock_last_write_time, (const path&, std::error_code&), @@ -44,8 +44,8 @@ namespace std class Mock_ifstream { public: - CO_OVERRIDE_MEMBER_METHOD_CTOR(OverrideInstance, Mock_ifstream, const ghc::filesystem::path&) - CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, bool, is_open, ()) + CO_INSERT_MEMBER_METHOD_CTOR(OverrideInstance, Mock_ifstream, const ghc::filesystem::path&) + CO_INSERT_MEMBER_METHOD(OverrideInstance, bool, is_open, ()) }; class Mock_ofstream @@ -53,9 +53,9 @@ namespace std public: std::stringstream StringStream; - CO_OVERRIDE_MEMBER_METHOD_CTOR(OverrideInstance, Mock_ofstream, const ghc::filesystem::path&) - CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, bool, is_open, ()) - CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, void, close, ()) + CO_INSERT_MEMBER_METHOD_CTOR(OverrideInstance, Mock_ofstream, const ghc::filesystem::path&) + CO_INSERT_MEMBER_METHOD(OverrideInstance, bool, is_open, ()) + CO_INSERT_MEMBER_METHOD(OverrideInstance, void, close, ()) template friend Mock_ofstream& operator<<(Mock_ofstream&, T const&); @@ -66,7 +66,7 @@ namespace std { static_assert(std::is_same::value, "We are only mocking std string"); public: - CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, std::size_t, operator(), (T)) + CO_INSERT_MEMBER_METHOD(OverrideInstance, std::size_t, operator(), (T)) }; template @@ -84,7 +84,7 @@ namespace std inline bool Mock_getline(Mock_ifstream& stream, std::string& line) { - CO_OVERRIDE_IMPL(OverrideInstance, bool, (stream, line)); + CO_INSERT_IMPL(OverrideInstance, bool, (stream, line)); return false; } } diff --git a/Include/runcpp2/ConfigParsing.hpp b/Include/runcpp2/ConfigParsing.hpp index ddfdd14..500e4df 100644 --- a/Include/runcpp2/ConfigParsing.hpp +++ b/Include/runcpp2/ConfigParsing.hpp @@ -3,13 +3,18 @@ #include "runcpp2/Data/Profile.hpp" #include "runcpp2/Data/ScriptInfo.hpp" + +#include "ghc/filesystem.hpp" + #include #include namespace runcpp2 { std::string GetConfigFilePath(); - bool WriteDefaultConfig(const std::string& userConfigPath); + bool WriteDefaultConfigs( const ghc::filesystem::path& userConfigPath, + const bool writeUserConfig, + const bool writeDefaultConfigs); bool ReadUserConfig(std::vector& outProfiles, std::string& outPreferredProfile, diff --git a/Src/Tests/BuildsManagerTest.cpp b/Src/Tests/BuildsManagerTest.cpp index ac89c88..5dd65a2 100644 --- a/Src/Tests/BuildsManagerTest.cpp +++ b/Src/Tests/BuildsManagerTest.cpp @@ -60,39 +60,26 @@ int main(int argc, char** argv) const std::string mappingsFilePath = buildsDirPath + "/Mappings.csv"; auto prepareInitialization = - [ - &mappingsFilePath, - &scriptsPaths, - &scriptsBuildsPaths - ] - ( - std::shared_ptr& returnMappingsPathExistsResult, - std::shared_ptr& returnIfstreamResult, - std::shared_ptr& returnIsOpenResult, - std::shared_ptr& returnRdbufResult, - std::string customContent - ) + [&mappingsFilePath, &scriptsPaths, &scriptsBuildsPaths](std::string customContent) { //Checking mappings file path - returnMappingsPathExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(mappingsFilePath, CO_ANY) - .Returns(true) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(mappingsFilePath, CO_ANY) + .Returns(true) + .Times(1) + .Expected(); //Open mappings file - returnIfstreamResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_ifstream) - .WhenCalledWith(mappingsFilePath) - .Returns() - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_NO_REF (OverrideInstance, Mock_ifstream) + .WhenCalledWith(mappingsFilePath) + .Returns() + .Times(1) + .Expected(); //Checking if mappings file is opened - returnIsOpenResult = CO_SETUP_OVERRIDE (OverrideInstance, is_open) - .Returns(true) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ifstream, is_open) + .Returns(true) + .Times(1) + .Expected(); //Return file content std::string mappingsContent; if(!customContent.empty()) @@ -103,18 +90,20 @@ int main(int argc, char** argv) mappingsContent += scriptsPaths.at(i) + "," + scriptsBuildsPaths.at(i) + "\n"; } - returnRdbufResult = CO_SETUP_OVERRIDE (OverrideInstance, rdbuf) - .Returns(mappingsContent) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ifstream, rdbuf) + .Returns(mappingsContent) + .Times(1) + .Expected(); }; ssTEST_INIT_TEST_GROUP(); + ssTEST_PARSE_ARGS(argc, argv); + ssTEST_COMMON_SETUP { buildsManager.reset(new runcpp2::BuildsManager(configDirPath)); - CO_CLEAR_ALL_OVERRIDE_SETUP(OverrideInstance); + CO_CLEAR_ALL_INSTRUCTS(OverrideInstance); }; ssTEST_COMMON_CLEANUP @@ -128,20 +117,19 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( - std::shared_ptr result = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_create_directories) - .Times(1) - .Returns(false) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_create_directories) + .Returns(false) + .ExpectedNotSatisfied(); ghc::filesystem::path outPath; ); - ssTEST_OUTPUT_ASSERT(buildsManager->CreateBuildMapping(scriptsPaths.front()) == false); - ssTEST_OUTPUT_ASSERT(result->GetStatusCount() == 0); - ssTEST_OUTPUT_ASSERT(buildsManager->RemoveBuildMapping(scriptsPaths.front()) == false); - ssTEST_OUTPUT_ASSERT(buildsManager->HasBuildMapping(scriptsPaths.front()) == false); - ssTEST_OUTPUT_ASSERT(buildsManager->GetBuildMapping(scriptsPaths.front(), outPath) == false); - ssTEST_OUTPUT_ASSERT(buildsManager->RemoveAllBuildsMappings() == false); - ssTEST_OUTPUT_ASSERT(buildsManager->SaveBuildsMappings() == false); + ssTEST_OUTPUT_ASSERT("", buildsManager->CreateBuildMapping(scriptsPaths.front()), false); + ssTEST_OUTPUT_ASSERT("", buildsManager->RemoveBuildMapping(scriptsPaths.front()), false); + ssTEST_OUTPUT_ASSERT("", buildsManager->HasBuildMapping(scriptsPaths.front()), false); + ssTEST_OUTPUT_ASSERT("", buildsManager->GetBuildMapping(scriptsPaths.front(), outPath), false); + ssTEST_OUTPUT_ASSERT("", buildsManager->RemoveAllBuildsMappings(), false); + ssTEST_OUTPUT_ASSERT("", buildsManager->SaveBuildsMappings(), false); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); + ssTEST_OUTPUT_VALUES_WHEN_FAILED("\n" + CO_GET_FAILED_REPORT(OverrideInstance)); }; ssTEST("Initialize Should Try To Read Mappings File When It Exists") @@ -153,24 +141,23 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( //Checking mappings file path - std::shared_ptr pathExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(mappingsFilePath, CO_ANY) - .Returns(true) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(mappingsFilePath, CO_ANY) + .Returns(true) + .Times(1) + .Expected(); //Open mappings file - std::shared_ptr ifstreamResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_ifstream) - .WhenCalledWith(mappingsFilePath) - .Returns() - .Times(1) - .ReturnsResult(); + std::shared_ptr ifstreamResult; + CO_INSTRUCT_NO_REF (OverrideInstance, Mock_ifstream) + .WhenCalledWith(mappingsFilePath) + .Returns() + .Times(1) + .AssignsResult(ifstreamResult); ); ssTEST_OUTPUT_EXECUTION( buildsManager->Initialize(); ); - ssTEST_OUTPUT_ASSERT("Checking mappings file path", pathExistsResult->LastStatusSucceed()); ssTEST_OUTPUT_ASSERT("Open mappings file", ifstreamResult->LastStatusSucceed()); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("Initialize Should Create Mappings File When It Doesn't Exists") @@ -179,62 +166,45 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( //Checking mappings file path - std::shared_ptr mappingsPathExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(mappingsFilePath, CO_ANY) - .Returns(false) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(mappingsFilePath, CO_ANY) + .Returns(false) + .Times(1) + .Expected(); //Checking builds directory exist - std::shared_ptr buildsDirExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(buildsDirPath, CO_ANY) - .Returns(false) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(buildsDirPath, CO_ANY) + .Returns(false) + .Times(1) + .Expected(); //Create builds directory - std::shared_ptr createBuildsDirResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_create_directories) - .WhenCalledWith(buildsDirPath, CO_ANY) - .Returns(true) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_create_directories) + .WhenCalledWith(buildsDirPath, CO_ANY) + .Returns(true) + .Times(1) + .Expected(); //Creating mappings file - std::shared_ptr ofstreamResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_ofstream) - .WhenCalledWith(mappingsFilePath) - .Returns() - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_NO_REF (OverrideInstance, Mock_ofstream) + .WhenCalledWith(mappingsFilePath) + .Returns() + .Times(1) + .Expected(); //Checking if mappings file is created - std::shared_ptr ofstreamIsOpenResult = - CO_SETUP_OVERRIDE (OverrideInstance, is_open) - .Returns(true) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ofstream, is_open) + .Returns(true) + .Times(1) + .Expected(); //Closing mappings file - std::shared_ptr ofstreamCloseResult = - CO_SETUP_OVERRIDE (OverrideInstance, close) - .Returns() - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ofstream, close) + .Returns() + .Times(1) + .Expected(); ); - ssTEST_OUTPUT_ASSERT( "Initialize should succeed", buildsManager->Initialize(), true); - ssTEST_OUTPUT_ASSERT( "Checking mappings file path", - mappingsPathExistsResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT( "Checking builds directory exist", - buildsDirExistsResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Create builds directory", - createBuildsDirResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Creating mappings file", - ofstreamResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Checking if mappings file is created", - ofstreamIsOpenResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Closing mappings file", - ofstreamCloseResult->LastStatusSucceed()); + ssTEST_OUTPUT_ASSERT("Initialize should succeed", buildsManager->Initialize(), true); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("Initialize Should Parse Mappings File Correctly When It Exists") @@ -242,68 +212,44 @@ int main(int argc, char** argv) using namespace CppOverride; ssTEST_OUTPUT_SETUP ( - std::shared_ptr mappingsPathExistsResult = nullptr; - std::shared_ptr ifstreamResult = nullptr; - std::shared_ptr isOpenResult = nullptr; - std::shared_ptr rdbufResult = nullptr; - prepareInitialization( mappingsPathExistsResult, ifstreamResult, - isOpenResult, rdbufResult, ""); + prepareInitialization(""); //When mapped build path exists - std::shared_ptr mappedBuildPathExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith - < - const ghc::filesystem::path&, - CO_ANY_TYPE - > - ( - buildsDirPath + "/" + scriptsBuildsPaths.front(), - CO_ANY - ) - .Returns(true) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith + ( + buildsDirPath + "/" + scriptsBuildsPaths.front(), + CO_ANY + ) + .Returns(true) + .Times(1) + .Expected(); //When mapped build path doesn't exist - std::shared_ptr mappedBuildPathNotExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith - < - const ghc::filesystem::path&, - CO_ANY_TYPE - > - ( - buildsDirPath + "/" + scriptsBuildsPaths.at(1), - CO_ANY - ) - .Returns(false) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith + ( + buildsDirPath + "/" + scriptsBuildsPaths.at(1), + CO_ANY + ) + .Returns(false) + .Times(1) + .Expected(); static_assert(defaultMappingsCount == 2, "Update test"); ); ssTEST_OUTPUT_ASSERT( "Initialize should succeed", buildsManager->Initialize(), true); - ssTEST_OUTPUT_ASSERT( "Checking mappings file path", - mappingsPathExistsResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT( "Open mappings file", - ifstreamResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Checking if mappings file is opened", - isOpenResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Return file content", - rdbufResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "When mapped build path exists", - mappedBuildPathExistsResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT( "When mapped build path doesn't exist", - mappedBuildPathNotExistsResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT( "First build mapping should exist", - BuildsManagerAccessor ::GetMappings(*buildsManager) - .count(scriptsPaths.front()) > 0); + BuildsManagerAccessor::GetMappings (*buildsManager) + .count(scriptsPaths.front()), + 0, + >); ssTEST_OUTPUT_ASSERT( "Second build mapping should not exist", - BuildsManagerAccessor ::GetMappings(*buildsManager) - .count(scriptsPaths.at(1)) == 0); + BuildsManagerAccessor::GetMappings (*buildsManager) + .count(scriptsPaths.at(1)), + 0); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("Initialize Should Return False When Failed to Parse Mappings File") @@ -314,25 +260,12 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( - std::shared_ptr mappingsPathExistsResult = nullptr; - std::shared_ptr ifstreamResult = nullptr; - std::shared_ptr isOpenResult = nullptr; - std::shared_ptr rdbufResult = nullptr; - std::string mappingsContent = "Invalid content"; - prepareInitialization( mappingsPathExistsResult, ifstreamResult, - isOpenResult, rdbufResult, mappingsContent); + prepareInitialization(mappingsContent); ); - ssTEST_OUTPUT_ASSERT( "Initialize should failed", buildsManager->Initialize(), false); - ssTEST_OUTPUT_ASSERT( "Checking mappings file path", - mappingsPathExistsResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT( "Open mappings file", - ifstreamResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Checking if mappings file is opened", - isOpenResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Return file content", - rdbufResult->LastStatusSucceed()); + ssTEST_OUTPUT_ASSERT("Initialize should failed", buildsManager->Initialize(), false); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; auto commonInitializeBuildsManager = [&]() @@ -340,14 +273,18 @@ int main(int argc, char** argv) using namespace CppOverride; ssTEST_OUTPUT_SETUP ( - std::vector> initializeResults(4, nullptr); - //NOTE: This initializes the mapping for the first 2 scripts in scriptsPaths - prepareInitialization( initializeResults.at(0), initializeResults.at(1), - initializeResults.at(2), initializeResults.at(3), ""); - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .Times(2) - .Returns(true); + prepareInitialization(""); + for(int i = 0; i < defaultMappingsCount; ++i) + { + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith + (buildsDirPath + "/" + scriptsBuildsPaths.at(i), CO_ANY) + .Times(1) + .Returns(true) + .Expected(); + } + static_assert(defaultMappingsCount == 2, "Update test"); ); ssTEST_OUTPUT_ASSERT( "Initialize should succeed", @@ -363,49 +300,37 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( //Hash script path - std::shared_ptr hashResult = - CO_SETUP_OVERRIDE (OverrideInstance, operator()) - .WhenCalledWith(scriptsPaths.at(2) + "0") - .Returns(15) - .Times(1) - .ReturnsResult(); - + CO_INSTRUCT_REF (OverrideInstance, std::Mock_hash, operator()) + .WhenCalledWith(scriptsPaths.at(2) + "0") + .Returns(15) + .Times(1) + .Expected(); //New build mapping doesn't exist - std::shared_ptr newMappedBuildPathExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith - (buildsDirPath + "/" + scriptsBuildsPaths.at(2), CO_ANY) - .Returns(false) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith + (buildsDirPath + "/" + scriptsBuildsPaths.at(2), CO_ANY) + .Returns(false) + .Times(1) + .Expected(); //Create new build mappings directory - std::shared_ptr createNewMappedBuildPathResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_create_directories) - .WhenCalledWith - (buildsDirPath + "/" + scriptsBuildsPaths.at(2), CO_ANY) - .Returns(true) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_create_directories) + .WhenCalledWith + (buildsDirPath + "/" + scriptsBuildsPaths.at(2), CO_ANY) + .Returns(true) + .Times(1) + .Expected(); ); ssTEST_OUTPUT_ASSERT( "CreateBuildMapping should succeed", buildsManager->CreateBuildMapping(scriptsPaths.at(2)), true); - ssTEST_OUTPUT_ASSERT( "Hash script path", hashResult->LastStatusSucceed()); - - ssTEST_OUTPUT_VALUES_WHEN_FAILED(hashResult->GetStatusCount()); - - ssTEST_OUTPUT_ASSERT( "New build mapping doesn't exist", - newMappedBuildPathExistsResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Create new build mappings directory", - createNewMappedBuildPathResult->LastStatusSucceed()); ssTEST_OUTPUT_ASSERT( "New mapping exists", BuildsManagerAccessor ::GetMappings(*buildsManager) .count(scriptsPaths.at(2)) == 1); - ssTEST_OUTPUT_ASSERT - ( - "New mapping value is correct", - BuildsManagerAccessor::GetMappings(*buildsManager).at(scriptsPaths.at(2)) == - scriptsBuildsPaths.at(2) - ); + ssTEST_OUTPUT_ASSERT( "New mapping value is correct", + BuildsManagerAccessor::GetMappings (*buildsManager) + .at(scriptsPaths.at(2)), + scriptsBuildsPaths.at(2)); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); + ssTEST_OUTPUT_VALUES_WHEN_FAILED("\n" + CO_GET_FAILED_REPORT(OverrideInstance)); }; ssTEST("CreateBuildMapping Should Create Build Mapping When Hashed Output Is Not Unique") @@ -415,45 +340,37 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( //Hash script path not unique (first attempt) - std::shared_ptr hashNotUniqueResult = - CO_SETUP_OVERRIDE (OverrideInstance, operator()) - .WhenCalledWith(scriptsPaths.at(2) + "0") - .Returns(10) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_hash, operator()) + .WhenCalledWith(scriptsPaths.at(2) + "0") + .Returns(10) + .Times(1) + .Expected(); //Hash script path unique (second attempt) - std::shared_ptr hashUniqueResult = - CO_SETUP_OVERRIDE (OverrideInstance, operator()) - .WhenCalledWith(scriptsPaths.at(2) + "1") - .Returns(15) - .Times(1) - .ReturnsResult(); - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith - (buildsDirPath + "/" + scriptsBuildsPaths.at(2), CO_ANY) - .Returns(false); - CO_SETUP_OVERRIDE (OverrideInstance, Mock_create_directories) - .WhenCalledWith - (buildsDirPath + "/" + scriptsBuildsPaths.at(2), CO_ANY) - .Returns(true); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_hash, operator()) + .WhenCalledWith(scriptsPaths.at(2) + "1") + .Returns(15) + .Times(1) + .Expected(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith + (buildsDirPath + "/" + scriptsBuildsPaths.at(2), CO_ANY) + .Returns(false); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_create_directories) + .WhenCalledWith + (buildsDirPath + "/" + scriptsBuildsPaths.at(2), CO_ANY) + .Returns(true); ); ssTEST_OUTPUT_ASSERT( "CreateBuildMapping should succeed", buildsManager->CreateBuildMapping(scriptsPaths.at(2)), true); - ssTEST_OUTPUT_ASSERT( "Hash script path not unique (first attempt)", - hashNotUniqueResult->GetSucceedCount() == 1); - ssTEST_OUTPUT_ASSERT( "Hash script path unique (second attempt)", - hashUniqueResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT - ( - "New mapping exists", - BuildsManagerAccessor::GetMappings(*buildsManager).count(scriptsPaths.at(2)) == 1 - ); - ssTEST_OUTPUT_ASSERT - ( - "New mapping value is correct", - BuildsManagerAccessor::GetMappings(*buildsManager).at(scriptsPaths.at(2)) == - scriptsBuildsPaths.at(2) - ); + ssTEST_OUTPUT_ASSERT( "New mapping exists", + BuildsManagerAccessor::GetMappings (*buildsManager) + .count(scriptsPaths.at(2)), + 1); + ssTEST_OUTPUT_ASSERT( "New mapping value is correct", + BuildsManagerAccessor::GetMappings (*buildsManager) + .at(scriptsPaths.at(2)), + scriptsBuildsPaths.at(2)); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("CreateBuildMapping Should Return True When Mapping For Script Exists") @@ -461,8 +378,10 @@ int main(int argc, char** argv) using namespace CppOverride; commonInitializeBuildsManager(); ssTEST_OUTPUT_ASSERT( "CreateBuildMapping should succeed", - buildsManager->CreateBuildMapping(scriptsPaths.at(1)), true); - ssTEST_OUTPUT_ASSERT(BuildsManagerAccessor::GetMappings(*buildsManager).size() == 2); + buildsManager->CreateBuildMapping(scriptsPaths.at(1)), + true); + ssTEST_OUTPUT_ASSERT("", BuildsManagerAccessor::GetMappings(*buildsManager).size(), 2); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("RemoveBuildMapping Should Remove Build Mapping When It Exists") @@ -471,12 +390,15 @@ int main(int argc, char** argv) commonInitializeBuildsManager(); ssTEST_OUTPUT_ASSERT( "RemoveBuildMapping should succeed", buildsManager->RemoveBuildMapping(scriptsPaths.at(1)), true); - ssTEST_OUTPUT_ASSERT(BuildsManagerAccessor::GetMappings(*buildsManager).size() == 1); + ssTEST_OUTPUT_ASSERT("", BuildsManagerAccessor::GetMappings(*buildsManager).size(), 1); if(BuildsManagerAccessor::GetMappings(*buildsManager).size() == 1) { - ssTEST_OUTPUT_ASSERT( BuildsManagerAccessor ::GetMappings(*buildsManager) - .count(scriptsPaths.front()) == 1); + ssTEST_OUTPUT_ASSERT( "", + BuildsManagerAccessor::GetMappings (*buildsManager) + .count(scriptsPaths.front()), + 1); } + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("RemoveBuildMapping Should Return True When It Doesn't Exists") @@ -484,8 +406,10 @@ int main(int argc, char** argv) using namespace CppOverride; commonInitializeBuildsManager(); ssTEST_OUTPUT_ASSERT( "RemoveBuildMapping should succeed", - buildsManager->RemoveBuildMapping(scriptsPaths.at(2)), true); - ssTEST_OUTPUT_ASSERT(BuildsManagerAccessor::GetMappings(*buildsManager).size() == 2); + buildsManager->RemoveBuildMapping(scriptsPaths.at(2)), + true); + ssTEST_OUTPUT_ASSERT("", BuildsManagerAccessor::GetMappings(*buildsManager).size(), 2); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("HasBuildMapping Should Return True Where It Exists") @@ -493,7 +417,9 @@ int main(int argc, char** argv) using namespace CppOverride; commonInitializeBuildsManager(); ssTEST_OUTPUT_ASSERT( "HasBuildMapping should succeed", - buildsManager->HasBuildMapping(scriptsPaths.at(1)), true); + buildsManager->HasBuildMapping(scriptsPaths.at(1)), + true); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("HasBuildMapping Should Return False Where It Doesn't Exist") @@ -501,7 +427,9 @@ int main(int argc, char** argv) using namespace CppOverride; commonInitializeBuildsManager(); ssTEST_OUTPUT_ASSERT( "HasBuildMapping should Failed", - buildsManager->HasBuildMapping(scriptsPaths.at(2)), false); + buildsManager->HasBuildMapping(scriptsPaths.at(2)), + false); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("GetBuildMapping Should Return Correct Mapping When It Exists") @@ -512,18 +440,17 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( //CreateBuildMapping should not be called - std::shared_ptr createBuildMappingResult = - CO_SETUP_OVERRIDE (OverrideInstance, CreateBuildMapping) - .Returns(false) - .OverrideObject(buildsManager.get()) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, runcpp2::BuildsManager, CreateBuildMapping) + .Returns(false) + .MatchesObject(buildsManager.get()) + .ExpectedNotSatisfied(); ghc::filesystem::path outPath; ); ssTEST_OUTPUT_ASSERT( "GetBuildMapping should Succeed", - buildsManager->GetBuildMapping(scriptsPaths.at(0), outPath), true); - ssTEST_OUTPUT_ASSERT( "CreateBuildMapping should not be called", - createBuildMappingResult->GetStatusCount() == 0); - ssTEST_OUTPUT_ASSERT( outPath == buildsDirPath + "/" + scriptsBuildsPaths.at(0)); + buildsManager->GetBuildMapping(scriptsPaths.at(0), outPath), + true); + ssTEST_OUTPUT_ASSERT(outPath == buildsDirPath + "/" + scriptsBuildsPaths.at(0)); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("GetBuildMapping Should Create Build Mapping When It Doesn't Exists") @@ -534,24 +461,24 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( //CreateBuildMapping should be called - std::shared_ptr createBuildMappingResult = - CO_SETUP_OVERRIDE (OverrideInstance, CreateBuildMapping) - .WhenCalledWith(scriptsPaths.at(2)) - .Returns(true) - .Times(1) - .OverrideObject(buildsManager.get()) - .WhenCalledExpectedly_Do - ( - [&buildsManager, &scriptsPaths, &scriptsBuildsPaths](...) - { - BuildsManagerAccessor::GetMappings(*buildsManager) - [scriptsPaths.at(2)] = scriptsBuildsPaths.at(2); - - BuildsManagerAccessor::GetReverseMappings(*buildsManager) - [scriptsBuildsPaths.at(2)] = scriptsPaths.at(2); - } - ) - .ReturnsResult(); + std::shared_ptr createBuildMappingResult; + CO_INSTRUCT_REF (OverrideInstance, runcpp2::BuildsManager, CreateBuildMapping) + .WhenCalledWith(scriptsPaths.at(2)) + .Returns(true) + .Times(1) + .MatchesObject(buildsManager.get()) + .WhenCalledExpectedly_Do + ( + [&buildsManager, &scriptsPaths, &scriptsBuildsPaths](...) + { + BuildsManagerAccessor::GetMappings(*buildsManager) + [scriptsPaths.at(2)] = scriptsBuildsPaths.at(2); + + BuildsManagerAccessor::GetReverseMappings(*buildsManager) + [scriptsBuildsPaths.at(2)] = scriptsPaths.at(2); + } + ) + .AssignsResult(createBuildMappingResult); ghc::filesystem::path outPath; ); ssTEST_OUTPUT_ASSERT( "GetBuildMapping should Succeed", @@ -559,6 +486,7 @@ int main(int argc, char** argv) ssTEST_OUTPUT_ASSERT( "CreateBuildMapping should be called", createBuildMappingResult->LastStatusSucceed()); ssTEST_OUTPUT_ASSERT( outPath == buildsDirPath + "/" + scriptsBuildsPaths.at(2)); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("RemoveAllBuildsMappings Should Remove All Build Mappings") @@ -568,6 +496,7 @@ int main(int argc, char** argv) ssTEST_OUTPUT_ASSERT(buildsManager->RemoveAllBuildsMappings() == true); ssTEST_OUTPUT_ASSERT(BuildsManagerAccessor::GetMappings(*buildsManager).empty()); ssTEST_OUTPUT_ASSERT(BuildsManagerAccessor::GetReverseMappings(*buildsManager).empty()); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("SaveBuildsMappings Should Save Existing Mappings To Disk") @@ -583,48 +512,40 @@ int main(int argc, char** argv) BuildsManagerAccessor::GetReverseMappings(*buildsManager)[scriptsBuildsPaths.at(2)] = scriptsPaths.at(2); ); - ssTEST_OUTPUT_ASSERT(BuildsManagerAccessor::GetMappings(*buildsManager).size() == 3); + ssTEST_OUTPUT_ASSERT("", BuildsManagerAccessor::GetMappings(*buildsManager).size(), 3); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); ssTEST_OUTPUT_SETUP ( //Output to mappings file - std::shared_ptr ofstreamResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_ofstream) - .WhenCalledWith(mappingsFilePath) - .Returns() - .Times(1) - .ReturnsResult(); - //Checking if mappings file is created - std::shared_ptr ofstreamIsOpenResult = - CO_SETUP_OVERRIDE (OverrideInstance, is_open) - .Returns(true) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_NO_REF (OverrideInstance, Mock_ofstream) + .WhenCalledWith(mappingsFilePath) + .Returns() + .Times(1) + .Expected(); + //Removing previous override on is_open, checking if mappings file is created + CO_REMOVE_INSTRUCT_REF(OverrideInstance, std::Mock_ofstream, is_open); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ofstream, is_open) + .Returns(true) + .Times(1) + .Expected(); //Closing mappings file std::string writeResult; - std::shared_ptr ofstreamCloseResult = - CO_SETUP_OVERRIDE (OverrideInstance, close) - .Returns() - .Times(1) - .WhenCalledExpectedly_Do - ( - [&](void* instance, const std::vector&) - { - writeResult = - static_cast(instance)-> - StringStream.str(); - } - ) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ofstream, close) + .Returns() + .Times(1) + .WhenCalledExpectedly_Do + ( + [&](void* instance, const std::vector&) + { + writeResult = + static_cast(instance)->StringStream.str(); + } + ) + .Expected(); ); ssTEST_OUTPUT_ASSERT( buildsManager->SaveBuildsMappings() == true); - ssTEST_OUTPUT_ASSERT( "Output to mappings file", - ofstreamResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Checking if mappings file is created", - ofstreamIsOpenResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Closing mappings file", - ofstreamCloseResult->LastStatusSucceed()); static_assert(defaultMappingsCount == 2, "Update test"); constexpr int outputCount = 3; @@ -649,6 +570,9 @@ int main(int argc, char** argv) ssTEST_OUTPUT_ASSERT("Number of newlines must be n", occurrences, outputCount); } + + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); + ssTEST_OUTPUT_VALUES_WHEN_FAILED("\n" + CO_GET_FAILED_REPORT(OverrideInstance)); }; diff --git a/Src/Tests/ConfigParsingTest.cpp b/Src/Tests/ConfigParsingTest.cpp index 22995cf..ba0e918 100644 --- a/Src/Tests/ConfigParsingTest.cpp +++ b/Src/Tests/ConfigParsingTest.cpp @@ -3,6 +3,7 @@ #include "ssTest.hpp" #include "CppOverride.hpp" #include "ssLogger/ssLog.hpp" +#include "MacroPowerToys.h" CO_DECLARE_INSTANCE(OverrideInstance); @@ -35,94 +36,122 @@ int main(int argc, char** argv) using namespace CppOverride; - std::string configPath; - std::shared_ptr existsResult; - std::shared_ptr isDirResult; - std::shared_ptr ifstreamResult; - std::shared_ptr ifstreamSucceedResult; - std::shared_ptr writeDefaultConfigResult; - std::shared_ptr rdbufResult; + const std::string configPath = "some/config/dir/UserConfig.yaml"; + const std::string versionPath = "some/config/dir/.version"; + #define STR(x) #x + const std::string versionString = MPT_COMPOSE(STR, (RUNCPP2_CONFIG_VERSION)); + #undef STR void* userConfigIfstreamInstance = nullptr; + void* versionIfstreamInstance = nullptr; ssTEST_COMMON_SETUP { - CO_CLEAR_ALL_OVERRIDE_SETUP(OverrideInstance); + CO_CLEAR_ALL_INSTRUCTS(OverrideInstance); ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL(ssLOG_LEVEL_WARNING); - configPath = "some/config/dir/UserConfig.yaml"; - existsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(configPath, CO_ANY) - .Returns(true) - .ReturnsResult(); - isDirResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_is_directory) - .WhenCalledWith(configPath, CO_ANY) - .Returns(false) - .ReturnsResult(); - ifstreamResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_ifstream) - .WhenCalledWith(configPath) - .WhenCalledExpectedly_Do - ( - [&userConfigIfstreamInstance] - (void* instance, const std::vector&) - { - userConfigIfstreamInstance = instance; - } - ) - .ReturnsResult(); - ifstreamSucceedResult = - CO_SETUP_OVERRIDE (OverrideInstance, operator!) - .If - ( - [&userConfigIfstreamInstance] - (void* instance, const std::vector&) -> bool - { - return instance == userConfigIfstreamInstance; - } - ) - .Returns(false) - .ReturnsResult(); - writeDefaultConfigResult = - CO_SETUP_OVERRIDE (OverrideInstance, WriteDefaultConfig) - .Returns(false) - .ReturnsResult(); - }; - - auto commonOverrideStatusCheck = [&]() - { - ssTEST_OUTPUT_ASSERT("", existsResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT("", isDirResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT("", ifstreamResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT("", ifstreamSucceedResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT("", rdbufResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT( "WriteDefaultConfig() should not be called", - writeDefaultConfigResult->GetStatusCount(), 0); + /* + Override so that the test can perform action for the config and version for: + - Check if the file exists, which returns true + - Check if config path is a directory, which returns false + - Create Mock_ifstream with the correct filepath + - Operator! for Mock_ifstream which returns false if Mock_ifstream instances match + - rdbuf for version file Mock_ifstream instance + + And WriteDefaultConfigs() which always returns false + */ + + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(configPath, CO_ANY) + .Times(1) + .Returns(true) + .Expected(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(versionPath, CO_ANY) + .Times(1) + .Returns(true) + .Expected(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_is_directory) + .WhenCalledWith(configPath, CO_ANY) + .Times(1) + .Returns(false) + .Expected(); + CO_INSTRUCT_NO_REF (OverrideInstance, Mock_ifstream) + .WhenCalledWith(configPath) + .WhenCalledExpectedly_Do + ( + [&userConfigIfstreamInstance] + (void* instance, std::vector&) + { + userConfigIfstreamInstance = instance; + } + ) + .Times(1) + .Expected(); + CO_INSTRUCT_NO_REF (OverrideInstance, Mock_ifstream) + .WhenCalledWith(versionPath) + .WhenCalledExpectedly_Do + ( + [&versionIfstreamInstance] + (void* instance, std::vector&) + { + versionIfstreamInstance = instance; + } + ) + .Times(1) + .Expected(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ifstream, operator!) + .If + ( + [&userConfigIfstreamInstance, &versionIfstreamInstance] + (void* instance, ...) -> bool + { + return instance == userConfigIfstreamInstance || + instance == versionIfstreamInstance; + } + ) + .Times(2) + .Returns(false) + .Expected(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ifstream, rdbuf) + .Returns(versionString) + .If + ( + [&versionIfstreamInstance] + (void* instance, ...) -> bool + { + return instance == versionIfstreamInstance; + } + ) + .Times(1) + .Expected(); + CO_INSTRUCT_REF (OverrideInstance, runcpp2, WriteDefaultConfigs) + .Returns(false) + .ExpectedNotSatisfied(); }; auto commonDefaultOverrideSetup = [&]() { - CO_SETUP_OVERRIDE(OverrideInstance, Mock_exists).Returns(false); - CO_SETUP_OVERRIDE(OverrideInstance, Mock_is_directory).Returns(false); - CO_SETUP_OVERRIDE(OverrideInstance, operator!).Returns(false); - CO_SETUP_OVERRIDE(OverrideInstance, WriteDefaultConfig).Returns(false); - CO_SETUP_OVERRIDE(OverrideInstance, rdbuf).Returns(""); + CO_INSTRUCT_REF(OverrideInstance, ghc::filesystem, Mock_exists).Returns(false); + CO_INSTRUCT_REF(OverrideInstance, ghc::filesystem, Mock_is_directory).Returns(false); + CO_INSTRUCT_REF(OverrideInstance, std::Mock_ifstream, operator!).Returns(true); + CO_INSTRUCT_REF(OverrideInstance, std::Mock_ifstream, rdbuf).Returns(""); + CO_INSTRUCT_REF(OverrideInstance, runcpp2, WriteDefaultConfigs).Returns(false); }; ssTEST_COMMON_CLEANUP { ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL(ssLOG_LEVEL_WARNING); - configPath.clear(); - existsResult = CreateOverrideResult(); - isDirResult = CreateOverrideResult(); - ifstreamResult = CreateOverrideResult(); - ifstreamSucceedResult = CreateOverrideResult(); - writeDefaultConfigResult = CreateOverrideResult(); - rdbufResult = CreateOverrideResult(); userConfigIfstreamInstance = nullptr; }; + + //TODO(NOW) + //If version file exists and up to date, writeDefaultConfigs flag should be false + //If version file exists and not up to date, writeDefaultConfigs flag should be true + //If version file doesn't exist, writeDefaultConfigs flag should be true + + + ssTEST("ReadUserConfig Should Parse PreferredProfile As String Correctly") { ssTEST_OUTPUT_SETUP @@ -167,10 +196,18 @@ int main(int argc, char** argv) Name: "g++3" )"; - rdbufResult = CO_SETUP_OVERRIDE (OverrideInstance, rdbuf) - .Returns(yamlStr) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ifstream, rdbuf) + .Returns(yamlStr) + .If + ( + [&userConfigIfstreamInstance] + (void* instance, ...) -> bool + { + return instance == userConfigIfstreamInstance; + } + ) + .Times(1) + .Expected(); commonDefaultOverrideSetup(); std::vector profiles; @@ -182,10 +219,10 @@ int main(int argc, char** argv) bool parseResult = runcpp2::ReadUserConfig(profiles, preferredProfile, configPath); ); - commonOverrideStatusCheck(); ssTEST_OUTPUT_ASSERT("ReadUserConfig should succeed", parseResult); ssTEST_OUTPUT_ASSERT("Should parse 3 profiles", profiles.size() == 3); ssTEST_OUTPUT_ASSERT(preferredProfile == "g++"); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("ReadUserConfig Should Parse PreferredProfile As Platform Map Correctly") @@ -234,17 +271,24 @@ int main(int argc, char** argv) Name: "g++3" )"; - rdbufResult = CO_SETUP_OVERRIDE (OverrideInstance, rdbuf) - .Returns(yamlStr) - .Times(1) - .ReturnsResult(); - std::shared_ptr getPlatformNamesResult = - CO_SETUP_OVERRIDE (OverrideInstance, GetPlatformNames) - .Returns>({"MacOS", - "Unix", - "DefaultPlatform"}) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ifstream, rdbuf) + .Returns(yamlStr) + .Times(1) + .If + ( + [&userConfigIfstreamInstance] + (void* instance, ...) -> bool + { + return instance == userConfigIfstreamInstance; + } + ) + .Expected(); + CO_INSTRUCT_NO_REF (OverrideInstance, GetPlatformNames) + .Returns>({"MacOS", + "Unix", + "DefaultPlatform"}) + .Times(1) + .Expected(); commonDefaultOverrideSetup(); std::vector profiles; @@ -256,11 +300,10 @@ int main(int argc, char** argv) bool parseResult = runcpp2::ReadUserConfig(profiles, preferredProfile, configPath); ); - commonOverrideStatusCheck(); - ssTEST_OUTPUT_ASSERT(getPlatformNamesResult->LastStatusSucceed()); ssTEST_OUTPUT_ASSERT("ReadUserConfig should succeed", parseResult); ssTEST_OUTPUT_ASSERT("Should parse 3 profiles", profiles.size() == 3); ssTEST_OUTPUT_ASSERT("MacOS PreferredProfile should be g++3", preferredProfile == "g++3"); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); ssTEST_OUTPUT_SETUP ( @@ -269,16 +312,24 @@ int main(int argc, char** argv) profiles.clear(); preferredProfile.clear(); - CO_SETUP_OVERRIDE (OverrideInstance, rdbuf) - .Returns(yamlStr) - .Times(1) - .AssignsResult(rdbufResult); - CO_SETUP_OVERRIDE (OverrideInstance, GetPlatformNames) + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ifstream, rdbuf) + .Returns(yamlStr) + .Times(1) + .If + ( + [&userConfigIfstreamInstance] + (void* instance, ...) -> bool + { + return instance == userConfigIfstreamInstance; + } + ) + .Expected(); + CO_INSTRUCT_NO_REF (OverrideInstance, GetPlatformNames) .Returns>({"Linux", "Unix", "DefaultPlatform"}) .Times(1) - .AssignsResult(getPlatformNamesResult); + .Expected(); commonDefaultOverrideSetup(); ); @@ -287,11 +338,11 @@ int main(int argc, char** argv) parseResult = runcpp2::ReadUserConfig(profiles, preferredProfile, configPath); ); - ssTEST_OUTPUT_ASSERT(getPlatformNamesResult->LastStatusSucceed()); ssTEST_OUTPUT_ASSERT("ReadUserConfig should succeed", parseResult); ssTEST_OUTPUT_ASSERT("Should parse 3 profiles", profiles.size() == 3); ssTEST_OUTPUT_ASSERT( "DefaultProfile PreferredProfile should be g++", preferredProfile == "g++"); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("ReadUserConfig Should Import Profile From External YAML File") @@ -377,18 +428,18 @@ int main(int argc, char** argv) )"; //Mock for main config file - rdbufResult = CO_SETUP_OVERRIDE (OverrideInstance, rdbuf) - .Returns(mainConfigYamlStr) - .Times(1) - .If - ( - [&userConfigIfstreamInstance] - (void* instance, const std::vector&) -> bool - { - return instance == userConfigIfstreamInstance; - } - ) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ifstream, rdbuf) + .Returns(mainConfigYamlStr) + .Times(1) + .If + ( + [&userConfigIfstreamInstance] + (void* instance, ...) -> bool + { + return instance == userConfigIfstreamInstance; + } + ) + .Expected(); //Setup filesystem exist for the import yaml files std::string gccExpectedImportPath = "some/config/dir/Default/gcc.yaml"; @@ -396,122 +447,120 @@ int main(int argc, char** argv) std::string gccCompilerLinkerExpectedImportPath = "some/config/dir/Default/gccCompilerLinker.yaml"; - std::shared_ptr gccImportFileExistResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith( gccExpectedImportPath, - CO_ANY) - .Returns(true) - .ReturnsResult(); - std::shared_ptr filetypesImportFileExistResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith( filetypesExpectedImportPath, - CO_ANY) - .Returns(true) - .ReturnsResult(); - std::shared_ptr gccCompilerLinkerImportFileExistResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith - < - const std::string&, - CO_ANY_TYPE - > - ( - gccCompilerLinkerExpectedImportPath, - CO_ANY - ) - .Returns(true) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith( gccExpectedImportPath, + CO_ANY) + .Returns(true) + .Times(1) + .Expected(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith( filetypesExpectedImportPath, + CO_ANY) + .Returns(true) + .Times(1) + .Expected(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith + < + const std::string&, + CO_ANY_TYPE + > + ( + gccCompilerLinkerExpectedImportPath, + CO_ANY + ) + .Returns(true) + .Times(1) + .Expected(); //Record if there's an ifstream created with import paths void* gccImportIfstreamInstance = nullptr; void* filetypesImportIfstreamInstance = nullptr; void* gccCompilerLinkerImportIfstreamInstance = nullptr; - std::shared_ptr gccImportedFileStreamResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_ifstream) - .WhenCalledWith - (gccExpectedImportPath) - .Times(1) - .WhenCalledExpectedly_Do - ( - [&gccImportIfstreamInstance] - (void* instance, const std::vector&) - { - gccImportIfstreamInstance = instance; - } - ) - .ReturnsResult(); - std::shared_ptr filetypesImportedFileStreamResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_ifstream) - .WhenCalledWith - (filetypesExpectedImportPath) - .Times(1) - .WhenCalledExpectedly_Do - ( - [&filetypesImportIfstreamInstance] - (void* instance, const std::vector&) - { - filetypesImportIfstreamInstance = instance; - } - ) - .ReturnsResult(); - std::shared_ptr gccCompilerLinkerImportedFileStreamResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_ifstream) - .WhenCalledWith - (gccCompilerLinkerExpectedImportPath) - .Times(1) - .WhenCalledExpectedly_Do - ( - [&gccCompilerLinkerImportIfstreamInstance] - (void* instance, const std::vector&) - { - gccCompilerLinkerImportIfstreamInstance = instance; - } - ) - .ReturnsResult(); + CO_INSTRUCT_NO_REF (OverrideInstance, Mock_ifstream) + .WhenCalledWith + (gccExpectedImportPath) + .Times(1) + .WhenCalledExpectedly_Do + ( + [&gccImportIfstreamInstance] + (void* instance, ...) + { + gccImportIfstreamInstance = instance; + } + ) + .Expected(); + CO_INSTRUCT_NO_REF (OverrideInstance, Mock_ifstream) + .WhenCalledWith + (filetypesExpectedImportPath) + .Times(1) + .WhenCalledExpectedly_Do + ( + [&filetypesImportIfstreamInstance] + (void* instance, ...) + { + filetypesImportIfstreamInstance = instance; + } + ) + .Expected(); + CO_INSTRUCT_NO_REF (OverrideInstance, Mock_ifstream) + .WhenCalledWith + (gccCompilerLinkerExpectedImportPath) + .Times(1) + .WhenCalledExpectedly_Do + ( + [&gccCompilerLinkerImportIfstreamInstance] + (void* instance, ...) + { + gccCompilerLinkerImportIfstreamInstance = instance; + } + ) + .Expected(); //Mock for rdbuf call with specific path check for import files - std::shared_ptr gccImportedFileRdbufResult = - CO_SETUP_OVERRIDE (OverrideInstance, rdbuf) - .Returns(importedGccProfileYamlStr) - .Times(1) - .If - ( - [&gccImportIfstreamInstance] - (void* instance, const std::vector&) -> bool - { - return instance == gccImportIfstreamInstance; - } - ) - .ReturnsResult(); - std::shared_ptr filetypesImportedFileRdbufResult = - CO_SETUP_OVERRIDE (OverrideInstance, rdbuf) - .Returns(importedFiletypesYamlStr) - .Times(1) - .If - ( - [&filetypesImportIfstreamInstance] - (void* instance, const std::vector&) -> bool - { - return instance == filetypesImportIfstreamInstance; - } - ) - .ReturnsResult(); - std::shared_ptr gccCompilerLinkerImportedFileRdbufResult = - CO_SETUP_OVERRIDE (OverrideInstance, rdbuf) - .Returns(importedCompilerLinkerYamlStr) - .Times(1) - .If - ( - [&gccCompilerLinkerImportIfstreamInstance] - (void* instance, const std::vector&) -> bool - { - return instance == - gccCompilerLinkerImportIfstreamInstance; - } - ) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ifstream, rdbuf) + .Returns(importedGccProfileYamlStr) + .Times(1) + .If + ( + [&gccImportIfstreamInstance] + (void* instance, ...) -> bool + { + return instance == gccImportIfstreamInstance; + } + ) + .Expected(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ifstream, rdbuf) + .Returns(importedFiletypesYamlStr) + .Times(1) + .If + ( + [&filetypesImportIfstreamInstance] + (void* instance, ...) -> bool + { + return instance == filetypesImportIfstreamInstance; + } + ) + .Expected(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ifstream, rdbuf) + .Returns(importedCompilerLinkerYamlStr) + .Times(1) + .If + ( + [&gccCompilerLinkerImportIfstreamInstance] + (void* instance, ...) -> bool + { + return instance == + gccCompilerLinkerImportIfstreamInstance; + } + ) + .Expected(); + + //Tracking each Mock_ifstream instance is too cumbersome, just return false for all + //operator! since rdbuf won't work anyway even if it passed the operator! check + CO_INSTRUCT_REF(OverrideInstance, std::Mock_ifstream, operator!).Returns(false); commonDefaultOverrideSetup(); std::vector profiles; @@ -523,19 +572,6 @@ int main(int argc, char** argv) bool parseResult = runcpp2::ReadUserConfig(profiles, preferredProfile, configPath); ); - commonOverrideStatusCheck(); - ssTEST_OUTPUT_ASSERT("", gccImportFileExistResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT("", filetypesImportFileExistResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT("", gccCompilerLinkerImportFileExistResult->GetSucceedCount(), 1); - - ssTEST_OUTPUT_ASSERT("", gccImportedFileStreamResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT("", filetypesImportedFileStreamResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT("", gccCompilerLinkerImportedFileStreamResult->GetSucceedCount(), 1); - - ssTEST_OUTPUT_ASSERT("", gccImportedFileRdbufResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT("", filetypesImportedFileRdbufResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT("", gccCompilerLinkerImportedFileRdbufResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT("ReadUserConfig should succeed", parseResult); ssTEST_OUTPUT_ASSERT("Should parse 2 profiles (1 imported + 1 inline)", profiles.size(), 2); if(!profiles.empty()) @@ -560,9 +596,10 @@ int main(int argc, char** argv) preferredProfile, "imported-profile"); } + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST_END_TEST_GROUP(); return 0; -} +} diff --git a/Src/Tests/IncludeManagerTest.cpp b/Src/Tests/IncludeManagerTest.cpp index 74004ce..822e32b 100644 --- a/Src/Tests/IncludeManagerTest.cpp +++ b/Src/Tests/IncludeManagerTest.cpp @@ -1,4 +1,6 @@ +#define private public #include "runcpp2/IncludeManager.hpp" +#undef private #include "ssTest.hpp" #include "CppOverride.hpp" @@ -59,11 +61,12 @@ int main(int argc, char** argv) }; ssTEST_INIT_TEST_GROUP(); + ssTEST_PARSE_ARGS(argc, argv); ssTEST_COMMON_SETUP { includeManager.reset(new runcpp2::IncludeManager()); - CO_CLEAR_ALL_OVERRIDE_SETUP(OverrideInstance); + CO_CLEAR_ALL_INSTRUCTS(OverrideInstance); }; ssTEST_COMMON_CLEANUP @@ -77,32 +80,27 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( //Check if directory exists - std::shared_ptr dirExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(includeMapsPath, CO_ANY) - .Returns(false) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(includeMapsPath, CO_ANY) + .Returns(false) + .Times(1) + .Expected(); //Create directory - std::shared_ptr createDirResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_create_directories) - .WhenCalledWith(includeMapsPath, CO_ANY) - .Returns(true) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_create_directories) + .WhenCalledWith(includeMapsPath, CO_ANY) + .Returns(true) + .Times(1) + .Expected(); ); ssTEST_OUTPUT_ASSERT( "Initialize should succeed", includeManager->Initialize(buildDirPath), true); - ssTEST_OUTPUT_ASSERT( "Check if directory exists", - dirExistsResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Create directory", - createDirResult->LastStatusSucceed()); ssTEST_OUTPUT_ASSERT( "IncludeRecordDir should be set correctly", IncludeManagerAccessor::GetIncludeRecordDir(*includeManager) == includeMapsPath); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("Initialize Should Succeed When Directory Already Exists") @@ -111,29 +109,23 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( //Check if directory exists - std::shared_ptr dirExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(includeMapsPath, CO_ANY) - .Returns(true) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(includeMapsPath, CO_ANY) + .Returns(true) + .Times(1) + .Expected(); //Create directory should not be called - std::shared_ptr createDirResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_create_directories) - .Times(0) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_create_directories) + .ExpectedNotSatisfied(); ); ssTEST_OUTPUT_ASSERT( "Initialize should succeed", includeManager->Initialize(buildDirPath), true); - ssTEST_OUTPUT_ASSERT( "Check if directory exists", - dirExistsResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Create directory should not be called", - createDirResult->GetStatusCount() == 0); ssTEST_OUTPUT_ASSERT( "IncludeRecordDir should be set correctly", IncludeManagerAccessor::GetIncludeRecordDir(*includeManager) == includeMapsPath); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("Initialize Should Fail When Directory Creation Fails") @@ -142,29 +134,24 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( //Check if directory exists - std::shared_ptr dirExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(includeMapsPath, CO_ANY) - .Returns(false) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(includeMapsPath, CO_ANY) + .Returns(false) + .Times(1) + .Expected(); //Create directory fails - std::shared_ptr createDirResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_create_directories) - .WhenCalledWith(includeMapsPath, CO_ANY) - .Returns(false) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_create_directories) + .WhenCalledWith(includeMapsPath, CO_ANY) + .Returns(false) + .Times(1) + .Expected(); ); ssTEST_OUTPUT_ASSERT( "Initialize should fail", includeManager->Initialize(buildDirPath), false); - ssTEST_OUTPUT_ASSERT( "Check if directory exists", - dirExistsResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Create directory should be called", - createDirResult->LastStatusSucceed()); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("WriteIncludeRecord Should Write Multiple Includes Successfully") @@ -173,49 +160,48 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( //Initialize first - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(includeMapsPath, CO_ANY) - .Returns(true); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(includeMapsPath, CO_ANY) + .Times(1) + .Returns(true) + .Expected(); //Mock GetRecordPath const std::string recordPath = absPathPrefix + "/tmp/Build/IncludeMaps/test.Includes"; - std::shared_ptr getRecordPathResult = - CO_SETUP_OVERRIDE (OverrideInstance, GetRecordPath) - .WhenCalledWith(sourcePaths[0]) - .Returns(recordPath) - .Times(1) - .OverrideObject(includeManager.get()) - .ReturnsResult(); + + CO_INSTRUCT_REF (OverrideInstance, runcpp2::IncludeManager, GetRecordPath) + .WhenCalledWith(sourcePaths[0]) + .Returns(recordPath) + .Times(1) + .MatchesObject(includeManager.get()) + .Expected(); //Open output file - std::shared_ptr ofstreamResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_ofstream) - .WhenCalledWith(recordPath) - .Returns() - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_NO_REF (OverrideInstance, Mock_ofstream) + .WhenCalledWith(recordPath) + .Returns() + .Times(1) + .Expected(); //Check if file is opened - std::shared_ptr isOpenResult = - CO_SETUP_OVERRIDE (OverrideInstance, is_open) - .Returns(true) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ifstream, is_open) + .Returns(true) + .Times(1) + .Expected(); //Capture content on close std::string writeResult; - std::shared_ptr closeResult = - CO_SETUP_OVERRIDE (OverrideInstance, close) - .Returns() - .Times(1) - .WhenCalledExpectedly_Do - ( - [&](void* instance, const std::vector&) - { - writeResult = - static_cast(instance)-> - StringStream.str(); - } - ) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ofstream, close) + .Returns() + .Times(1) + .WhenCalledExpectedly_Do + ( + [&](void* instance, ...) + { + writeResult = + static_cast(instance)-> + StringStream.str(); + } + ) + .Expected(); ); //Initialize first @@ -230,17 +216,13 @@ int main(int argc, char** argv) includePaths[2] }; - ssTEST_OUTPUT_ASSERT( "WriteIncludeRecord should succeed", - includeManager->WriteIncludeRecord(sourcePaths[0], includes), true); - ssTEST_OUTPUT_ASSERT( "GetRecordPath should be called", - getRecordPathResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Open output file", - ofstreamResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Check if file is opened", - isOpenResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "File should be closed", - closeResult->LastStatusSucceed()); + ssTEST_OUTPUT_EXECUTION + ( + bool writeIncludeRecordResult = + includeManager->WriteIncludeRecord(sourcePaths[0], includes); + ); + ssTEST_OUTPUT_ASSERT("WriteIncludeRecord should succeed", writeIncludeRecordResult, true); //Verify content for(const ghc::filesystem::path& include : includes) { @@ -248,6 +230,8 @@ int main(int argc, char** argv) writeResult.find(include.string()) != std::string::npos); ssTEST_OUTPUT_VALUES_WHEN_FAILED(writeResult, include.string()); } + + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("WriteIncludeRecord Should Fail With Invalid Paths") @@ -256,8 +240,12 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( //Initialize first - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .Returns(true); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(includeMapsPath, CO_ANY) + .Times(1) + .Returns(true) + .Expected(); ); //Initialize first @@ -273,145 +261,124 @@ int main(int argc, char** argv) ( //Test when file open fails const std::string recordPath = absPathPrefix + "/tmp/Build/IncludeMaps/test.Includes"; - std::shared_ptr getRecordPathResult = - CO_SETUP_OVERRIDE (OverrideInstance, GetRecordPath) - .WhenCalledWith(sourcePaths[0]) - .Returns(recordPath) - .Times(1) - .OverrideObject(includeManager.get()) - .ReturnsResult(); - std::shared_ptr ofstreamResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_ofstream) - .WhenCalledWith(recordPath) - .Returns() - .Times(1) - .ReturnsResult(); - std::shared_ptr isOpenResult = - CO_SETUP_OVERRIDE (OverrideInstance, is_open) - .Returns(false) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, runcpp2::IncludeManager, GetRecordPath) + .WhenCalledWith(sourcePaths[0]) + .Returns(recordPath) + .Times(1) + .MatchesObject(includeManager.get()) + .Expected(); + CO_INSTRUCT_NO_REF (OverrideInstance, Mock_ofstream) + .WhenCalledWith(recordPath) + .Returns() + .Times(1) + .Expected(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ofstream, is_open) + .Returns(false) + .Times(1) + .Expected(); ); ssTEST_OUTPUT_ASSERT( "WriteIncludeRecord should fail when file open fails", includeManager->WriteIncludeRecord(sourcePaths[0], includes), false); - ssTEST_OUTPUT_ASSERT( "GetRecordPath should be called", - getRecordPathResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Open output file attempt", - ofstreamResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Check if file is opened", - isOpenResult->LastStatusSucceed()); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; - ssTEST("ReadIncludeRecord Should Read Multiple Includes Successfully") + ssTEST_ONLY_THIS("ReadIncludeRecord Should Read Multiple Includes Successfully") { using namespace CppOverride; ssTEST_OUTPUT_SETUP ( //Initialize first - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(includeMapsPath, CO_ANY) - .Returns(true); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(includeMapsPath, CO_ANY) + .Times(1) + .Returns(true) + .Expected(); //Mock GetRecordPath const std::string recordPath = absPathPrefix + "/tmp/Build/IncludeMaps/test.Includes"; - std::shared_ptr getRecordPathResult = - CO_SETUP_OVERRIDE (OverrideInstance, GetRecordPath) - .WhenCalledWith(sourcePaths[0]) - .Returns(recordPath) - .Times(1) - .OverrideObject(includeManager.get()) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, runcpp2::IncludeManager, GetRecordPath) + .WhenCalledWith(sourcePaths[0]) + .Returns(recordPath) + .Times(1) + .MatchesObject(includeManager.get()) + .Expected(); //Check if record file exists - std::shared_ptr recordExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(recordPath, CO_ANY) - .Returns(true) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(recordPath, CO_ANY) + .Returns(true) + .Times(1) + .Expected(); //Mock last_write_time const auto recordTime = ghc::filesystem::file_time_type::clock::now(); - std::shared_ptr lastWriteResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_last_write_time) - .WhenCalledWith(recordPath, CO_ANY) - .Returns(recordTime) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_last_write_time) + .WhenCalledWith(recordPath, CO_ANY) + .Returns(recordTime) + .Times(1) + .Expected(); //Open input file - std::shared_ptr ifstreamResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_ifstream) + CO_INSTRUCT_NO_REF (OverrideInstance, Mock_ifstream) .WhenCalledWith(recordPath) .Returns() .Times(1) - .ReturnsResult(); + .Expected(); //Check if file is opened - std::shared_ptr isOpenResult = - CO_SETUP_OVERRIDE (OverrideInstance, is_open) - .Returns(true) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ifstream, is_open) + .Returns(true) + .Times(1) + .Expected(); //Mock getline to return includes int callCount = 0; - std::shared_ptr getlineResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_getline) - .Returns(true) - .Times(3) - .WhenCalledExpectedly_Do - ( - [&callCount, &includePaths](void*, const std::vector& args) - { - std::string& line = *static_cast(args[1]); - line = includePaths[callCount++]; - } - ) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std, Mock_getline) + .Returns(true) + .WhenCalledExpectedly_Do + ( + [&callCount, &includePaths] + ( + void*, + std::vector& args + ) + { + if(args.at(1).IsType()) + { + *(args.at(1).GetTypedDataPtr()) = + includePaths[callCount++]; + } + } + ) + .Times(3); //Mock getline to return false for end of file - std::shared_ptr endOfFileResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_getline) - .Returns(false) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std, Mock_getline) + .Returns(false) + .Times(1) + .Expected(); ); //Initialize first ssTEST_OUTPUT_ASSERT( "Initialize should succeed", includeManager->Initialize(buildDirPath), true); - //Read includes std::vector outIncludes; ghc::filesystem::file_time_type outRecordTime; - ssTEST_OUTPUT_ASSERT( "ReadIncludeRecord should succeed", - includeManager->ReadIncludeRecord(sourcePaths[0], outIncludes, outRecordTime), true); - ssTEST_OUTPUT_ASSERT( "GetRecordPath should be called", - getRecordPathResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Check if record exists", - recordExistsResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Get last write time", - lastWriteResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Open input file", - ifstreamResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Check if file is opened", - isOpenResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Read includes with getline", - getlineResult->GetSucceedCount(), 3); - ssTEST_OUTPUT_ASSERT( "Read includes with getline eof", - endOfFileResult->GetStatusCount(), 1); - + includeManager->ReadIncludeRecord( sourcePaths[0], + outIncludes, + outRecordTime), + true); //Verify content ssTEST_OUTPUT_ASSERT( "Number of includes should match", outIncludes.size() == 3); for(std::size_t i = 0; i < outIncludes.size(); ++i) { - ssTEST_OUTPUT_ASSERT( "Include path should match", - outIncludes[i] == includePaths[i]); + ssTEST_OUTPUT_ASSERT("Include path should match", outIncludes[i], includePaths[i]); ssTEST_OUTPUT_VALUES_WHEN_FAILED(outIncludes[i].string(), includePaths[i]); } - ssTEST_OUTPUT_ASSERT( "Record time should match", - outRecordTime == recordTime); + ssTEST_OUTPUT_ASSERT("Record time should match", outRecordTime == recordTime); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); + ssTEST_OUTPUT_VALUES_WHEN_FAILED("\n" + CO_GET_FAILED_REPORT(OverrideInstance)); }; ssTEST("ReadIncludeRecord Should Fail When Record Doesn't Exist") @@ -420,9 +387,12 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( //Initialize first - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .Times(1) - .Returns(true); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(includeMapsPath, CO_ANY) + .Times(1) + .Returns(true) + .Expected(); ); //Initialize first @@ -433,30 +403,28 @@ int main(int argc, char** argv) ( //Test when record doesn't exist const std::string recordPath = absPathPrefix + "/tmp/Build/IncludeMaps/test.Includes"; - std::shared_ptr getRecordPathResult = - CO_SETUP_OVERRIDE (OverrideInstance, GetRecordPath) - .WhenCalledWith(sourcePaths[0]) - .Returns(recordPath) - .Times(1) - .OverrideObject(includeManager.get()) - .ReturnsResult(); - std::shared_ptr recordExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(recordPath, CO_ANY) - .Returns(false) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, runcpp2::IncludeManager, GetRecordPath) + .WhenCalledWith(sourcePaths[0]) + .Returns(recordPath) + .Times(1) + .MatchesObject(includeManager.get()) + .Expected(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(recordPath, CO_ANY) + .Returns(false) + .Times(1) + .Expected(); ); std::vector outIncludes; ghc::filesystem::file_time_type outRecordTime; ssTEST_OUTPUT_ASSERT( "ReadIncludeRecord should fail when record doesn't exist", - includeManager->ReadIncludeRecord(sourcePaths[0], outIncludes, outRecordTime), false); - ssTEST_OUTPUT_ASSERT( "GetRecordPath should be called", - getRecordPathResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Check if record exists", - recordExistsResult->LastStatusSucceed()); + includeManager->ReadIncludeRecord( sourcePaths[0], + outIncludes, + outRecordTime), + false); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("ReadIncludeRecord Should Fail When File Open Fails") @@ -465,8 +433,12 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( //Initialize first - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .Returns(true); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(includeMapsPath, CO_ANY) + .Times(1) + .Returns(true) + .Expected(); ); //Initialize first @@ -477,38 +449,34 @@ int main(int argc, char** argv) ( //Test when file open fails const std::string recordPath = absPathPrefix + "/tmp/Build/IncludeMaps/test.Includes"; - std::shared_ptr getRecordPathResult = - CO_SETUP_OVERRIDE (OverrideInstance, GetRecordPath) - .WhenCalledWith(sourcePaths[0]) - .Returns(recordPath) - .Times(1) - .OverrideObject(includeManager.get()) - .ReturnsResult(); - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) + CO_INSTRUCT_REF (OverrideInstance, runcpp2::IncludeManager, GetRecordPath) + .WhenCalledWith(sourcePaths[0]) + .Returns(recordPath) + .Times(1) + .MatchesObject(includeManager.get()) + .Expected(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) .WhenCalledWith(recordPath, CO_ANY) .Returns(true) .Times(1); const auto recordTime = ghc::filesystem::file_time_type::clock::now(); - std::shared_ptr lastWriteResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_last_write_time) - .WhenCalledWith(recordPath, CO_ANY) - .Returns(recordTime) - .Times(1) - .ReturnsResult(); - std::shared_ptr ifstreamResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_ifstream) - .WhenCalledWith(recordPath) - .Returns() - .Times(1) - .ReturnsResult(); - std::shared_ptr isOpenResult = - CO_SETUP_OVERRIDE (OverrideInstance, is_open) - .Returns(false) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_last_write_time) + .WhenCalledWith(recordPath, CO_ANY) + .Returns(recordTime) + .Times(1) + .Expected(); + CO_INSTRUCT_NO_REF (OverrideInstance, Mock_ifstream) + .WhenCalledWith(recordPath) + .Returns() + .Times(1) + .Expected() + CO_INSTRUCT_REF (OverrideInstance, std::Mock_ifstream, is_open) + .Returns(false) + .Times(1) + .Expected(); ); std::vector outIncludes; @@ -518,14 +486,7 @@ int main(int argc, char** argv) outIncludes, outRecordTime), false); - ssTEST_OUTPUT_ASSERT( "GetRecordPath should be called", - getRecordPathResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Get last write time", - lastWriteResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Open input file attempt", - ifstreamResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Check if file is opened", - isOpenResult->LastStatusSucceed()); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("NeedsUpdate Should Return True When Source Is Newer") @@ -540,41 +501,32 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( //Mock source file time - std::shared_ptr sourceTimeResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_last_write_time) - .WhenCalledWith(sourcePaths[0], CO_ANY) - .Returns(sourceTime) - .Times(1) - .ReturnsResult(); - //Mock include file time (shouldn't be called since source is newer) - std::shared_ptr includeTimeResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_last_write_time) - .WhenCalledWith(includePaths[0], CO_ANY) - .Returns(includeTime) - .Times(0) - .ReturnsResult(); - //Mock include file exists (shouldn't be called since source is newer) - std::shared_ptr includeExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(includePaths[0], CO_ANY) - .Returns(true) - .Times(0) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_last_write_time) + .WhenCalledWith(sourcePaths[0], CO_ANY) + .Returns(sourceTime) + .Times(1) + .Expected(); + //Mock include file time (shouldn't be called since source is newer than record time) + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_last_write_time) + .WhenCalledWith(includePaths[0], CO_ANY) + .Returns(includeTime) + .ExpectedNotSatisfied(); + //Mock include file exists (shouldn't be called since source is newer than record time) + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(includePaths[0], CO_ANY) + .Returns(true) + .ExpectedNotSatisfied(); std::vector includes = { includePaths[0] }; ); ssTEST_OUTPUT_ASSERT( "NeedsUpdate should return true when source is newer", - includeManager->NeedsUpdate(sourcePaths[0], includes, recordTime), true); - ssTEST_OUTPUT_ASSERT( "Source time should be checked", - sourceTimeResult->LastStatusSucceed()); - ssTEST_OUTPUT_ASSERT( "Include time should not be checked", - includeTimeResult->GetStatusCount() == 0); - ssTEST_OUTPUT_ASSERT( "Include exists should not be checked", - includeExistsResult->GetStatusCount() == 0); + includeManager->NeedsUpdate(sourcePaths[0], includes, recordTime), + true); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("NeedsUpdate Should Return True When Include Is Newer") @@ -589,29 +541,26 @@ int main(int argc, char** argv) const auto includeTime = recordTime + std::chrono::seconds(1); //Mock source file time - std::shared_ptr sourceTimeResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_last_write_time) - .WhenCalledWith(sourcePaths[0], CO_ANY) - .Returns(sourceTime) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_last_write_time) + .WhenCalledWith(sourcePaths[0], CO_ANY) + .Returns(sourceTime) + .Times(1) + .Expected(); //Mock include file exists - std::shared_ptr includeExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(includePaths[0], CO_ANY) - .Returns(true) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(includePaths[0], CO_ANY) + .Returns(true) + .Times(1) + .Expected(); //Mock include file time - std::shared_ptr includeTimeResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_last_write_time) - .WhenCalledWith(includePaths[0], CO_ANY) - .Returns(includeTime) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_last_write_time) + .WhenCalledWith(includePaths[0], CO_ANY) + .Returns(includeTime) + .Times(1) + .Expected(); std::vector includes = { includePaths[0] }; ); @@ -619,12 +568,7 @@ int main(int argc, char** argv) ssTEST_OUTPUT_ASSERT( "NeedsUpdate should return true when include is newer", includeManager->NeedsUpdate(sourcePaths[0], includes, recordTime), true); - ssTEST_OUTPUT_ASSERT( "Source time should be checked", - sourceTimeResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT( "Include exists should be checked", - includeExistsResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT( "Include time should be checked", - includeTimeResult->GetSucceedCount(), 1); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST("NeedsUpdate Should Return False When Record Is Newest") @@ -639,31 +583,28 @@ int main(int argc, char** argv) const auto includeTime = recordTime - std::chrono::seconds(2); //Mock source file time - std::shared_ptr sourceTimeResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_last_write_time) - .WhenCalledWith(sourcePaths[0], CO_ANY) - .Returns(sourceTime) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_last_write_time) + .WhenCalledWith(sourcePaths[0], CO_ANY) + .Returns(sourceTime) + .Times(1) + .Expected(); //Mock include file exists - std::shared_ptr includeExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(includePaths[0], CO_ANY) - .Returns(true) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(includePaths[0], CO_ANY) + .Returns(true) + .Times(1) + .Expected(); //Mock include file time - std::shared_ptr includeTimeResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_last_write_time) - .WhenCalledWith(includePaths[0], CO_ANY) - .Returns(includeTime) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_last_write_time) + .WhenCalledWith(includePaths[0], CO_ANY) + .Returns(includeTime) + .Times(1) + .Expected(); std::vector includes = { includePaths[0] }; ); @@ -671,15 +612,10 @@ int main(int argc, char** argv) ssTEST_OUTPUT_ASSERT( "NeedsUpdate should return false when record is newest", includeManager->NeedsUpdate(sourcePaths[0], includes, recordTime), false); - ssTEST_OUTPUT_ASSERT( "Source time should be checked", - sourceTimeResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT( "Include exists should be checked", - includeExistsResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT( "Include time should be checked", - includeTimeResult->GetSucceedCount(), 1); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; - ssTEST("NeedsUpdate Should Handle Missing Include Files") + ssTEST("NeedsUpdate Should Return True When Missing Include File") { using namespace CppOverride; @@ -690,36 +626,34 @@ int main(int argc, char** argv) const auto sourceTime = recordTime - std::chrono::seconds(1); //Mock source file time - std::shared_ptr sourceTimeResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_last_write_time) - .WhenCalledWith(sourcePaths[0], CO_ANY) - .Returns(sourceTime) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_last_write_time) + .WhenCalledWith(sourcePaths[0], CO_ANY) + .Returns(sourceTime) + .Times(1) + .Expected(); //Mock first include file exists (false) - std::shared_ptr include1ExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(includePaths[0], CO_ANY) - .Returns(false) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(includePaths[0], CO_ANY) + .Returns(false) + .Times(1) + .Expected(); //Mock second include file exists (true) - std::shared_ptr include2ExistsResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .WhenCalledWith(includePaths[1], CO_ANY) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .WhenCalledWith(includePaths[1], CO_ANY) + .Times(0) + .Expected(); //Mock second include file time - std::shared_ptr include2TimeResult = - CO_SETUP_OVERRIDE (OverrideInstance, Mock_last_write_time) - .WhenCalledWith(includePaths[1], CO_ANY) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_last_write_time) + .WhenCalledWith(includePaths[1], CO_ANY) + .Times(0) + .Expected(); std::vector includes = { includePaths[0], includePaths[1] }; ); @@ -727,14 +661,8 @@ int main(int argc, char** argv) ssTEST_OUTPUT_ASSERT( "NeedsUpdate should return true when include is newer", includeManager->NeedsUpdate(sourcePaths[0], includes, recordTime), true); - ssTEST_OUTPUT_ASSERT( "Source time should be checked", - sourceTimeResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT( "First include exists should be checked", - include1ExistsResult->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT( "Second include exists should not be checked", - include2ExistsResult->GetStatusCount(), 0); - ssTEST_OUTPUT_ASSERT( "Second include time should not be checked", - include2TimeResult->GetStatusCount(), 0); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); + ssTEST_OUTPUT_VALUES_WHEN_FAILED(CO_GET_FAILED_REPORT(OverrideInstance)); }; ssTEST("GetRecordPath Should Generate Valid And Unique Paths") @@ -759,84 +687,90 @@ int main(int argc, char** argv) ssTEST_OUTPUT_SETUP ( //Initialize first - CO_SETUP_OVERRIDE (OverrideInstance, Mock_exists) - .Returns(true); - - + CO_INSTRUCT_REF (OverrideInstance, ghc::filesystem, Mock_exists) + .Returns(true) + .Expected(); //Mock hash for first source file - std::shared_ptr hash1Result = - CO_SETUP_OVERRIDE (OverrideInstance, operator()) - .If - ( - [&sourcePaths, ProcessPath](void*, - const std::vector& args) - { - if(args.empty()) - return false; - if( ProcessPath(*static_cast(args.at(0))) == - sourcePaths[0]) - { - return true; - } - return false; - } - ) - .Returns(123) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_hash, operator()) + .If + ( + [&sourcePaths, ProcessPath] + ( + void*, + const std::vector& args + ) + { + if(args.empty()) + return false; + if( args.at(0).IsType() && + ProcessPath(*args.at(0).GetTypedDataPtr()) == + sourcePaths.at(0)) + { + return true; + } + return false; + } + ) + .Returns(123) + .Times(1) + .Expected(); //Mock hash for second source file - std::shared_ptr hash2Result = - CO_SETUP_OVERRIDE (OverrideInstance, operator()) - .If - ( - [&sourcePaths, ProcessPath](void*, - const std::vector& args) - { - if(args.empty()) - return false; - if( ProcessPath(*static_cast(args.at(0))) == - sourcePaths[1]) - { - return true; - } - return false; - } - ) - .Returns(456) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_hash, operator()) + .If + ( + [&sourcePaths, ProcessPath] + ( + void*, + const std::vector& args + ) + { + if(args.empty()) + return false; + if( args.at(0).IsType() && + ProcessPath(*args.at(0).GetTypedDataPtr()) == + sourcePaths.at(1)) + { + return true; + } + return false; + } + ) + .Returns(456) + .Times(1) + .Expected(); //Mock hash for third source file - std::shared_ptr hash3Result = - CO_SETUP_OVERRIDE (OverrideInstance, operator()) - .If - ( - [&sourcePaths, ProcessPath](void*, - const std::vector& args) - { - if(args.empty()) - return false; - if( ProcessPath(*static_cast(args.at(0))) == - sourcePaths[2]) - { - return true; - } - return false; - } - ) - .Returns(789) - .Times(1) - .ReturnsResult(); + CO_INSTRUCT_REF (OverrideInstance, std::Mock_hash, operator()) + .If + ( + [&sourcePaths, ProcessPath] + ( + void*, + const std::vector& args + ) + { + if(args.empty()) + return false; + if( args.at(0).IsType() && + ProcessPath(*args.at(0).GetTypedDataPtr()) == + sourcePaths.at(2)) + { + return true; + } + return false; + } + ) + .Returns(789) + .Times(1) + .Expected(); ); - //Initialize first - ssTEST_OUTPUT_ASSERT( "Initialize should succeed", - includeManager->Initialize(buildDirPath), true); - - ssTEST_OUTPUT_SETUP + ssTEST_OUTPUT_EXECUTION ( + //Initialize first + bool initializeResult = includeManager->Initialize(buildDirPath); //Get paths for different source files ghc::filesystem::path path1 = IncludeManagerAccessor::GetRecordPath(*includeManager, sourcePaths[0]); @@ -846,6 +780,7 @@ int main(int argc, char** argv) IncludeManagerAccessor::GetRecordPath(*includeManager, sourcePaths[2]); ); + ssTEST_OUTPUT_ASSERT("Initialize should succeed", initializeResult, true); //Verify exact paths ssTEST_OUTPUT_ASSERT( "Path1 should match expected", path1 == includeMapsPath + "/123.Includes"); @@ -853,18 +788,7 @@ int main(int argc, char** argv) path2 == includeMapsPath + "/456.Includes"); ssTEST_OUTPUT_ASSERT( "Path3 should match expected", path3 == includeMapsPath + "/789.Includes"); - - //Verify hash was called for each source file - ssTEST_OUTPUT_ASSERT( "Hash should be called for first source file", - hash1Result->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT( "Hash should be called for second source file", - hash2Result->GetSucceedCount(), 1); - ssTEST_OUTPUT_ASSERT( "Hash should be called for third source file", - hash3Result->GetSucceedCount(), 1); - - ssTEST_OUTPUT_VALUES_WHEN_FAILED( hash1Result->GetStatusCount(), - hash2Result->GetStatusCount(), - hash3Result->GetStatusCount()); + ssTEST_OUTPUT_ASSERT("", CO_GET_FAILED_FUNCTIONS(OverrideInstance).size(), 0); }; ssTEST_END_TEST_GROUP(); diff --git a/Src/runcpp2/BuildsManager.cpp b/Src/runcpp2/BuildsManager.cpp index 0c3ec1e..9d617b0 100644 --- a/Src/runcpp2/BuildsManager.cpp +++ b/Src/runcpp2/BuildsManager.cpp @@ -167,7 +167,7 @@ namespace runcpp2 bool BuildsManager::CreateBuildMapping(const ghc::filesystem::path& scriptPath) { - CO_OVERRIDE_MEMBER_IMPL(OverrideInstance, bool, (scriptPath)); + CO_INSERT_MEMBER_IMPL(OverrideInstance, bool, (scriptPath)); ssLOG_FUNC_DEBUG(); diff --git a/Src/runcpp2/ConfigParsing.cpp b/Src/runcpp2/ConfigParsing.cpp index 3afe062..2fed37f 100644 --- a/Src/runcpp2/ConfigParsing.cpp +++ b/Src/runcpp2/ConfigParsing.cpp @@ -1,10 +1,10 @@ #include "runcpp2/ConfigParsing.hpp" #include "runcpp2/ParseUtil.hpp" +#include "runcpp2/StringUtil.hpp" #include "runcpp2/PlatformUtil.hpp" #include "runcpp2/YamlLib.hpp" #include "cfgpath.h" -#include "ghc/filesystem.hpp" #include "ssLogger/ssLog.hpp" #if INTERNAL_RUNCPP2_UNIT_TESTS @@ -27,7 +27,7 @@ extern "C" const size_t Vs2022_v17Plus_size; namespace { bool ResovleProfileImport( ryml::NodeRef currentProfileNode, - const std::string& configPath, + const ghc::filesystem::path& configPath, std::vector& importProfileTrees) { INTERNAL_RUNCPP2_SAFE_START(); @@ -124,7 +124,7 @@ namespace } bool ParseUserConfig( const std::string& userConfigString, - const std::string& configPath, + const ghc::filesystem::path& configPath, std::vector& outProfiles, std::string& outPreferredProfile) { @@ -238,7 +238,7 @@ namespace std::string runcpp2::GetConfigFilePath() { - CO_OVERRIDE_IMPL(OverrideInstance, std::string, ()); + CO_INSERT_IMPL(OverrideInstance, std::string, ()); //Check if user config exists char configDirC_Str[MAX_PATH] = {0}; @@ -275,23 +275,26 @@ std::string runcpp2::GetConfigFilePath() return compilerConfigFilePaths[0]; } -bool runcpp2::WriteDefaultConfig(const std::string& userConfigPath) +bool runcpp2::WriteDefaultConfigs( const ghc::filesystem::path& userConfigPath, + const bool writeUserConfig, + const bool writeDefaultConfigs) { - CO_OVERRIDE_IMPL(OverrideInstance, bool, (userConfigPath)); + CO_INSERT_IMPL(OverrideInstance, bool, (userConfigPath, writeUserConfig, writeDefaultConfigs)); + //Backup existing user config std::error_code _; - if(ghc::filesystem::exists(userConfigPath, _)) + if(writeUserConfig && ghc::filesystem::exists(userConfigPath, _)) { int backupCount = 0; do { if(backupCount > 10) { - ssLOG_ERROR("Failed to backup existing user config: " << userConfigPath); + ssLOG_ERROR("Failed to backup existing user config: " << userConfigPath.string()); return false; } - std::string backupPath = userConfigPath; + std::string backupPath = userConfigPath.string(); if(backupCount > 0) backupPath += "." + std::to_string(backupCount); @@ -309,7 +312,7 @@ bool runcpp2::WriteDefaultConfig(const std::string& userConfigPath) ghc::filesystem::copy(userConfigPath, backupPath, copyErrorCode); if(copyErrorCode) { - ssLOG_ERROR("Failed to backup existing user config: " << userConfigPath << + ssLOG_ERROR("Failed to backup existing user config: " << userConfigPath.string() << " with error: " << _.message()); return false; @@ -318,7 +321,7 @@ bool runcpp2::WriteDefaultConfig(const std::string& userConfigPath) ssLOG_INFO("Backed up existing user config: " << backupPath); if(!ghc::filesystem::remove(userConfigPath, _)) { - ssLOG_ERROR("Failed to delete existing user config: " << userConfigPath); + ssLOG_ERROR("Failed to delete existing user config: " << userConfigPath.string()); return false; } @@ -328,16 +331,20 @@ bool runcpp2::WriteDefaultConfig(const std::string& userConfigPath) } //Create user config + if(writeUserConfig) { std::ofstream configFile(userConfigPath, std::ios::binary); if(!configFile) { - ssLOG_ERROR("Failed to create default config file: " << userConfigPath); + ssLOG_ERROR("Failed to create default config file: " << userConfigPath.string()); return false; } configFile.write((const char*)DefaultUserConfig, DefaultUserConfig_size); } + if(!writeDefaultConfigs) + return true; + ghc::filesystem::path userConfigDirectory = userConfigPath; userConfigDirectory = userConfigDirectory.parent_path(); ghc::filesystem::path defaultYamlDirectory = userConfigDirectory / "Default"; @@ -358,7 +365,8 @@ bool runcpp2::WriteDefaultConfig(const std::string& userConfigPath) (ghc::filesystem::path outputPath, const uint8_t* outputContent, size_t outputSize) { const ghc::filesystem::path currentOutputPath = defaultYamlDirectory / outputPath; - std::ofstream defaultFile(currentOutputPath.string(), std::ios::binary); + std::ofstream defaultFile( currentOutputPath.string(), + std::ios::binary | std::ios_base::trunc); if(!defaultFile) { ssLOG_ERROR("Failed to create default config file: " << currentOutputPath.string()); @@ -375,10 +383,22 @@ bool runcpp2::WriteDefaultConfig(const std::string& userConfigPath) return false; } + //Writing .version to indicate everything is up-to-date + std::ofstream configVersionFile(userConfigDirectory / ".version", + std::ios::binary | std::ios_base::trunc); + if(!configVersionFile) + { + ssLOG_ERROR("Failed to open version file: " << + ghc::filesystem::path(userConfigDirectory / ".version").string()); + return false; + } + + configVersionFile << std::to_string(RUNCPP2_CONFIG_VERSION); + return true; } - +//TODO(NOW): Update test bool runcpp2::ReadUserConfig( std::vector& outProfiles, std::string& outPreferredProfile, const std::string& customConfigPath) @@ -387,27 +407,64 @@ bool runcpp2::ReadUserConfig( std::vector& outProfiles, ssLOG_FUNC_INFO(); - std::string configPath = !customConfigPath.empty() ? customConfigPath : GetConfigFilePath(); + ghc::filesystem::path configPath = !customConfigPath.empty() ? + customConfigPath : + GetConfigFilePath(); + ghc::filesystem::path configVersionPath = configPath.parent_path() / ".version"; + if(configPath.empty()) return false; std::error_code e; + + bool writeUserConfig = false; + bool writeDefaultConfigs = false; + + //Create default config files if it doesn't exist if(!ghc::filesystem::exists(configPath, e)) { if(!customConfigPath.empty()) { - ssLOG_ERROR("Config file doesn't exist: " << configPath); + ssLOG_ERROR("Config file doesn't exist: " << configPath.string()); return false; } - ssLOG_INFO("Config file doesn't exist. Creating one at: " << configPath); - if(!WriteDefaultConfig(configPath)) + ssLOG_INFO("Config file doesn't exist. Creating one at: " << configPath.string()); + writeUserConfig = true; + writeDefaultConfigs = true; + } + //Overwrite default config files if it is using old version + else if(ghc::filesystem::exists(configVersionPath, e)) + { + std::ifstream configVersionFile(configVersionPath); + if(!configVersionFile) + { + ssLOG_ERROR("Failed to open version file: " << configVersionPath.string()); return false; + } + std::string configVersionStr; + std::stringstream buffer; + buffer << configVersionFile.rdbuf(); + configVersionStr = buffer.str(); + + Trim(configVersionStr); + int configVersion = std::stoi(configVersionStr); + if(configVersion < RUNCPP2_CONFIG_VERSION) + writeDefaultConfigs = true; + } + //Overwrite default config files if missing version file + else + writeDefaultConfigs = true; + + if( (writeUserConfig || writeDefaultConfigs) && + !WriteDefaultConfigs(configPath, writeUserConfig, writeDefaultConfigs)) + { + return false; } if(ghc::filesystem::is_directory(configPath, e)) { - ssLOG_ERROR("Config file path is a directory: " << configPath); + ssLOG_ERROR("Config file path is a directory: " << configPath.string()); return false; } @@ -417,7 +474,7 @@ bool runcpp2::ReadUserConfig( std::vector& outProfiles, std::ifstream userConfigFile(configPath); if(!userConfigFile) { - ssLOG_ERROR("Failed to open config file: " << configPath); + ssLOG_ERROR("Failed to open config file: " << configPath.string()); return false; } std::stringstream buffer; @@ -427,7 +484,7 @@ bool runcpp2::ReadUserConfig( std::vector& outProfiles, if(!ParseUserConfig(userConfigContent, configPath, outProfiles, outPreferredProfile)) { - ssLOG_ERROR("Failed to parse config file: " << configPath); + ssLOG_ERROR("Failed to parse config file: " << configPath.string()); return false; } diff --git a/Src/runcpp2/IncludeManager.cpp b/Src/runcpp2/IncludeManager.cpp index 5964b95..2b032e0 100644 --- a/Src/runcpp2/IncludeManager.cpp +++ b/Src/runcpp2/IncludeManager.cpp @@ -151,7 +151,7 @@ namespace runcpp2 ghc::filesystem::path IncludeManager::GetRecordPath(const ghc::filesystem::path& sourceFile) const { - CO_OVERRIDE_MEMBER_IMPL(OverrideInstance, ghc::filesystem::path, (sourceFile)); + CO_INSERT_MEMBER_IMPL(OverrideInstance, ghc::filesystem::path, (sourceFile)); ghc::filesystem::path cleanSourceFile = sourceFile.lexically_normal(); std::size_t pathHash = std::hash{}(cleanSourceFile.string()); diff --git a/Src/runcpp2/PlatformUtil.cpp b/Src/runcpp2/PlatformUtil.cpp index 66736ec..59986ae 100644 --- a/Src/runcpp2/PlatformUtil.cpp +++ b/Src/runcpp2/PlatformUtil.cpp @@ -65,7 +65,7 @@ std::string runcpp2::ProcessPath(const std::string& path) std::vector runcpp2::GetPlatformNames() { - CO_OVERRIDE_IMPL(OverrideInstance, std::vector, ()); + CO_INSERT_IMPL(OverrideInstance, std::vector, ()); #ifdef _WIN32 return {"Windows", "DefaultPlatform"}; diff --git a/Src/runcpp2/main.cpp b/Src/runcpp2/main.cpp index 72b7345..c64801c 100644 --- a/Src/runcpp2/main.cpp +++ b/Src/runcpp2/main.cpp @@ -360,7 +360,7 @@ int main(int argc, char* argv[]) if(currentOptions.count(runcpp2::CmdOptions::RESET_USER_CONFIG)) { ssLOG_INFO("Resetting user config"); - if(!runcpp2::WriteDefaultConfig(runcpp2::GetConfigFilePath())) + if(!runcpp2::WriteDefaultConfigs(runcpp2::GetConfigFilePath(), true, true)) { ssLOG_ERROR("Failed reset user config"); return -1; diff --git a/mkdocs/docs/build_settings.md b/mkdocs/docs/build_settings.md index d683d39..4981627 100644 --- a/mkdocs/docs/build_settings.md +++ b/mkdocs/docs/build_settings.md @@ -45,6 +45,22 @@ ```yaml BuildType: Executable ``` + +!!! warning + When you specify `BuildType` as `Executable`, it will still produce a **shared library** for running. + Under the hood, runcpp2 simply loads the shared library and call the `main()` function. + + The reason of this behavior is because this makes it possible to "catch" if there's any + missing external (shared) libraries that failed to be resolved, either because of missing + `.dll`/`.so` or misconfigured search path. + + This allows runcpp2 to differentiate a failure on resolving shared library and if the program + just returns a non-zero exit code. + + Therefore, when calling with the build flag `--build`, the output of the binary is **shared + library instead of an executable**. This behavior can be **overridden** by passing the + `--executable`/`-e` flag to force runcpp2 to produce the executable. + ### `RequiredProfiles` - Type: `Platform Profile List` - Optional: `true` @@ -58,21 +74,21 @@ MacOS: ["g++"] ``` ### `OverrideCompileFlags` -- Type: `Platform Profile Map` +- Type: `Platform Profile Map` with child fields - Optional: `true` - Default: None -- Description: The compile flags to override for each platform and profile. +- Description: The compile flags to override for the profile being run under each platform. - Child Fields: - `Remove` - Type: `string` - Optional: `true` - Default: None - - Description: The compile flags to remove for each platform and profile. + - Description: The compile flags to remove for the profile being run. - `Append` - Type: `string` - Optional: `true` - Default: None - - Description: The compile flags to append for each platform and profile. + - Description: The compile flags to append for the profile being run. ??? example ```yaml OverrideCompileFlags: @@ -85,18 +101,18 @@ - Type: `Platform Profile Map` with child fields - Optional: `true` - Default: None -- Description: The link flags to override for each platform and profile. +- Description: The link flags to override for the profile being run under each platform. - Child Fields: - `Remove` - Type: `string` - Optional: `true` - Default: None - - Description: The link flags to remove for each platform and profile. + - Description: The link flags to remove for the profile being run. - `Append` - Type: `string` - Optional: `true` - Default: None - - Description: The link flags to append for each platform and profile. + - Description: The link flags to append for the profile being run. ??? example ```yaml OverrideLinkFlags: @@ -147,7 +163,7 @@ - Type: `Platform Profile Map` with `list` of `string` - Optional: `true` - Default: None -- Description: The setup commands to be used for each platform and profile. +- Description: The setup commands to be used for each platform and profile. This runs before the script built for the first time. ??? example ```yaml Setup: @@ -159,7 +175,7 @@ - Type: `Platform Profile Map` with `list` of `string` - Optional: `true` - Default: None -- Description: The pre-build commands to be used for each platform and profile. +- Description: The pre-build commands to be used for each platform and profile. This runs before each build. ??? example ```yaml PreBuild: @@ -171,7 +187,7 @@ - Type: `Platform Profile Map` with `list` of `string` - Optional: `true` - Default: None -- Description: The post-build commands to be used for each platform and profile. +- Description: The post-build commands to be used for each platform and profile. This runs after each build. ??? example ```yaml PostBuild: @@ -183,7 +199,7 @@ - Type: `Platform Profile Map` with `list` of `string` - Optional: `true` - Default: None -- Description: The cleanup commands to be used for each platform and profile. +- Description: The cleanup commands to be used for each platform and profile. This runs when `--cleanup` command is specified. ??? example ```yaml Cleanup: diff --git a/mkdocs/docs/guides/building_project_sources.md b/mkdocs/docs/guides/building_project_sources.md index b5446a6..b0c4ac0 100644 --- a/mkdocs/docs/guides/building_project_sources.md +++ b/mkdocs/docs/guides/building_project_sources.md @@ -18,8 +18,8 @@ The `BuildType` setting specifies what type of output to build. There are four s !!! note If not specified, the default build type is Executable. -!!! important - When you specify `BuildType` as `Executable`, it will still produce a **shared library**. +!!! warning + When you specify `BuildType` as `Executable`, it will still produce a **shared library** for running. Under the hood, runcpp2 simply loads the shared library and call the `main()` function. The reason of this behavior is because this makes it possible to "catch" if there's any