From e2c5515cbe7ed3c5681d53d29eb6e91952db7e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=20=D0=A7?= =?UTF-8?q?=D0=B8=D0=B6?= Date: Thu, 29 Feb 2024 13:21:13 +0100 Subject: [PATCH] added mac suppot and trying to integrate integration tests --- .github/workflows/cmake-multi-platform.yml | 45 +++++++++++++++++----- rebuild.sh | 9 +++-- srcbpatch/fileprocessing.cpp | 4 +- testbpatch/CMakeLists.txt | 4 +- testbpatch/test.cpp | 12 +++--- 5 files changed, 50 insertions(+), 24 deletions(-) mode change 100644 => 100755 rebuild.sh diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 319fcbf..321fd7a 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -4,7 +4,7 @@ name: CMake on multiple platforms on: push: - branches: [ "master" ] + branches: [ "master", "clang_support"] pull_request: branches: [ "master" ] @@ -26,7 +26,7 @@ jobs: # # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest, windows-latest, macos-14] build_type: [Release, Debug] c_compiler: [gcc, cl, clang-15] include: @@ -36,7 +36,7 @@ jobs: - os: ubuntu-latest c_compiler: gcc cpp_compiler: g++ - - os: ubuntu-latest + - os: macos-14 c_compiler: clang-15 cpp_compiler: clang++-15 exclude: @@ -46,17 +46,16 @@ jobs: c_compiler: clang-15 - os: ubuntu-latest c_compiler: cl + - os: ubuntu-latest + c_compiler: clang-15 + - os: macos-14 + c_compiler: cl + - os: macos-14 + c_compiler: gcc steps: - uses: actions/checkout@v4 - - name: Install clang - if: matrix.os=='ubuntu-latest' && matrix.c_compiler=='clang-15' - run: | - sudo apt -y install clang-15 - sudo apt -y install libc++-15-dev libc++abi-15-dev - - - name: Set reusable strings # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. id: strings @@ -85,6 +84,13 @@ jobs: working-directory: ${{ steps.strings.outputs.build-output-dir }}/testbpatch/ run: ./testbpatch + - name: Unit Tests on Mac + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + if: matrix.os=='macos-14' + working-directory: ${{ steps.strings.outputs.build-output-dir }}/testbpatch/ + run: ./testbpatch + - name: Unit Tests on Windows # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail @@ -93,3 +99,22 @@ jobs: shell: cmd run: .\testbpatch.exe + - name: Integration Tests on Ubuntu + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + if: matrix.os=='ubuntu-latest' + run: ./IntegrationTests/in_tests.sh ${{ steps.strings.outputs.build-output-dir }}/bpatch + + - name: Integration Tests on Mac + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + if: matrix.os=='macos-14' + run: ./IntegrationTests/in_tests.sh ${{ steps.strings.outputs.build-output-dir }}/bpatch + + - name: Integration Tests on Windows + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + if: matrix.os=='windows-latest' + shell: cmd + run: ./IntegrationTests/in_tests.sh ${{ steps.strings.outputs.build-output-dir }}/testbpatch/${{ matrix.build_type }}/bpatch.exe + diff --git a/rebuild.sh b/rebuild.sh old mode 100644 new mode 100755 index 7ce9af8..d840557 --- a/rebuild.sh +++ b/rebuild.sh @@ -6,6 +6,7 @@ divisor() { # Establish the mode, defaulting to Release if no argument is given MODE=Release +SYSTEM=$(uname) if [ "$1" != "" ]; then MODE=$1 fi @@ -44,14 +45,14 @@ PROJECTDIR=${SCRIPT_PATH} # rebuilding initiation cd $PROJECTDIR -rm -rf "buildLinux$MODE" -mkdir "buildLinux$MODE" && cd "buildLinux$MODE" +rm -rf "build$SYSTEM$MODE" +mkdir "build$SYSTEM$MODE" && cd "build$SYSTEM$MODE" cmake -DCMAKE_BUILD_TYPE=$MODE .. cmake --build . --config $MODE divisor -FILENAME="$PROJECTDIR/buildLinux$MODE/bpatch" +FILENAME="$PROJECTDIR/build$SYSTEM$MODE/bpatch" if [ -e "$FILENAME" ]; then echo "bpatch built for $MODE mode is here:" @@ -61,7 +62,7 @@ else echo "$FILENAME" fi -FILENAME="$PROJECTDIR/buildLinux$MODE/testbpatch/testbpatch" +FILENAME="$PROJECTDIR/build$SYSTEM$MODE/testbpatch/testbpatch" if [ -e "$FILENAME" ]; then echo "Unit tests for bpatch are here:" diff --git a/srcbpatch/fileprocessing.cpp b/srcbpatch/fileprocessing.cpp index 3499175..78f6084 100644 --- a/srcbpatch/fileprocessing.cpp +++ b/srcbpatch/fileprocessing.cpp @@ -25,13 +25,13 @@ using namespace std::filesystem; FileProcessing::FileProcessing(const char* fname, const char* mode) { #if !defined(__linux__) && !(defined(__APPLE__) && defined(__MACH__)) - #pragma warning(disable: 4996) // I would like to use fopen instead of fopen_s, because +#pragma warning(disable: 4996) // I would like to use fopen instead of fopen_s, because // 1. I would like to write fast code // 2. MSVS compiler does not respect C++ standard and __STDC_LIB_EXT1__ define #endif if (stream_ = fopen(fname, mode); nullptr == stream_) #if !defined(__linux__) && !(defined(__APPLE__) && defined(__MACH__)) - #pragma warning(default: 4996) +#pragma warning(default: 4996) #endif { throw filesystem_error(fio_errors[0], filesystem::path(fname), error_code()); diff --git a/testbpatch/CMakeLists.txt b/testbpatch/CMakeLists.txt index 5486c51..1d3d19e 100644 --- a/testbpatch/CMakeLists.txt +++ b/testbpatch/CMakeLists.txt @@ -5,8 +5,8 @@ project(test${pname}) include(FetchContent) FetchContent_Declare( googletest - # Specify the commit you depend on and update it regularly. - URL https://github.com/google/googletest/archive/5376968f6948923e2411081fd9372e71a59d8e77.zip + GIT_REPOSITORY https://github.com/google/googletest + GIT_TAG release-1.12.1 ) # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) diff --git a/testbpatch/test.cpp b/testbpatch/test.cpp index 224f3d3..6e35328 100644 --- a/testbpatch/test.cpp +++ b/testbpatch/test.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include -#ifdef __linux__ +#if defined(__linux__) || ((defined(__APPLE__) && defined(__MACH__))) #include #else #include @@ -29,7 +29,7 @@ TEST(WildCharacters, ProcessingValidTrue) } okMask[] = { -#ifdef __linux__ +#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) {R"(/Users/Bobby/kon?e?.txt)", R"(./kon?e?.txt)"} , {R"(../Bobby/kon*e*.*)", R"(../kon*e*.*)"} , {R"(kon*e*.*)", R"(./kon*e*.*)"} @@ -77,7 +77,7 @@ TEST(WildCharacters, ProcessingValidFalse) } okMask[] = { -#ifdef __linux__ +#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) {R"(/Users/Bobby/kon?e?.txt)", R"(/Users/Bobby/kon?e?.txt)"} , {R"(./../*.???)", R"(./../*.???)"} , {R"(*.*)", R"(*.*)"} @@ -111,7 +111,7 @@ TEST(WildCharacters, ProcessingInvalid) } badMask[] = { -#ifdef __linux__ +#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) {R"(/Users/Bo?by/kon?e?.txt)", emptySV} , {R"(../Bo*by/kon*e*.*)", emptySV} , {R"(*/kon*e*.*)", emptySV} @@ -158,7 +158,7 @@ TEST(WildCharacters, ProcessingInvalid) TEST(WildCharacters, SearchingTests) { // get full path for executable -#ifdef __linux__ +#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) char pathBuffer[PATH_MAX] = {0}; [[maybe_unused]] auto result = readlink(R"(/proc/self/exe)", pathBuffer, PATH_MAX); #else @@ -172,7 +172,7 @@ TEST(WildCharacters, SearchingTests) filesystem::path pathTestFolder(pathBuffer); pathTestFolder = pathTestFolder.parent_path(); -#ifdef __linux__ +#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) #else pathTestFolder /= ".."; // creation of Debug or Release subfolder is Window's 'EVERYTHING' #endif