From 8d9c05fd2b716924db510c01289a66940856bad4 Mon Sep 17 00:00:00 2001 From: Thorulf Neustrup Date: Tue, 12 Sep 2023 10:13:44 +0200 Subject: [PATCH 1/6] Changed json to match Response refactor --- include/uls/server.h | 3 ++- src/highlight.cpp | 4 ++-- src/server.cpp | 17 +++++++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/uls/server.h b/include/uls/server.h index 78f2653..f7efe57 100644 --- a/include/uls/server.h +++ b/include/uls/server.h @@ -29,6 +29,7 @@ class Server bool is_running{false}; void send(const std::string& message_type, const nlohmann::json& message); + void send_error(const nlohmann::json& message); public: Server(IOStream io): io(std::move(io)) {} @@ -58,7 +59,7 @@ class Server void send_notification(const std::string& type, Data&& element) { auto message = Serializer>::serialize(std::forward(element)); - send(type, message); + send("notif/" + type, message); } void start(); diff --git a/src/highlight.cpp b/src/highlight.cpp index 0fbbd1f..aac68e9 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -50,11 +50,11 @@ void Highlight::configure(Server& server) repository.add_on_document_update([this, &server](UTAP::Document& doc) { auto keywords = keywords_for_path(doc, repository.get_current_xpath()); - server.send_notification("notif/keywords", keywords); + server.send_notification("keywords", keywords); }); repository.add_on_current_node_changed([this, &server](const std::string& xpath) { auto keywords = keywords_for_path(repository.get_document(), xpath); - server.send_notification("notif/keywords", keywords); + server.send_notification("keywords", keywords); }); } \ No newline at end of file diff --git a/src/server.cpp b/src/server.cpp index 449164e..69a839b 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -9,8 +9,8 @@ namespace views = std::ranges::views; using namespace std::chrono_literals; using json = nlohmann::json; -nlohmann::json OK_RESPONSE = {{"res", "OK"}}; -nlohmann::json FAIL_RESPONSE = {{"res", "FAIL"}}; +nlohmann::json OK_RESPONSE = {"OK"}; +nlohmann::json FAIL_RESPONSE = {"FAIL"}; const Command& get_command(const std::vector& commands, const std::string& command_name) { @@ -34,12 +34,12 @@ void Server::start() const Command& command = get_command(commands, message["cmd"].get()); auto response = command.callback(message["args"]); - send("response/" + command.name, response); + send("response/" + command.name, std::move(response)); } catch (nlohmann::json::parse_error& e) { - send("error", e.what()); + send_error(e.what()); stop(); } catch (std::exception& e) { - send("error", e.what()); + send_error(e.what()); } } } @@ -55,7 +55,12 @@ Server& Server::add_close_command(std::string name) void Server::send(const std::string& message_type, const nlohmann::json& message) { - io.out << json{{"type", message_type}, {"msg", message}} << std::endl; + io.out << json{{"res", message_type}, {"info", message}} << std::endl; +} + +void Server::send_error(const nlohmann::json& message) +{ + send("err", message); } void Server::stop() { is_running = false; } From b4a82a3f44ca4b4ce284ebde7c5f341ec73d6175 Mon Sep 17 00:00:00 2001 From: Thorulf Neustrup Date: Tue, 12 Sep 2023 10:26:24 +0200 Subject: [PATCH 2/6] Fixed tests --- .github/workflows/build-test.yml | 2 +- CMakeLists.txt | 4 ++-- test/server_mock.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index db25a0b..9a78c35 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v3 - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Debug -DTESTING=ON + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Debug -DULS_TESTING=ON - name: Build run: cmake --build ${{github.workspace}}/build diff --git a/CMakeLists.txt b/CMakeLists.txt index b72c4f3..7dc248f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.26.4) -option(TESTING "Enables unit testing" OFF) +option(ULS_TESTING "Enables unit testing" OFF) project(ULS CXX) set(CMAKE_CXX_STANDARD 20) @@ -13,7 +13,7 @@ include(cmake/nlohmann.cmake) add_subdirectory(src) -if(TESTING) +if(ULS_TESTING) enable_testing() add_subdirectory(test) endif() \ No newline at end of file diff --git a/test/server_mock.h b/test/server_mock.h index 8291458..7b22400 100644 --- a/test/server_mock.h +++ b/test/server_mock.h @@ -26,14 +26,14 @@ struct MockIO : IOStream { nlohmann::json message; out_buf >> message; - return message["msg"]; + return message["info"]; } bool expect_error() { nlohmann::json message; out_buf >> message; - return message["type"] == "error"; + return message["type"] == "err"; } bool out_eof() { return out_buf.eof(); } From a5f84a8cca0d19a1ff955f75a59c737c9b347167 Mon Sep 17 00:00:00 2001 From: Thorulf Neustrup Date: Mon, 9 Oct 2023 13:40:34 +0200 Subject: [PATCH 3/6] Set tests to off by default --- CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b0bb4fa..881b0a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.22) -option(TESTING "Enables unit testing" OFF) +option(ULS_WITH_TESTS "ULS Unit Tests" OFF) project(ULS CXX) set(CMAKE_CXX_STANDARD 20) @@ -7,8 +7,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -option(ULS_WITH_TESTS "ULS Unit Tests" ON) - #Hack used to force UTAP to compile statically set(BUILD_SHARED_LIBS OFF) From 38a73932ac8b822b6d73bc79a12a190a036c06c4 Mon Sep 17 00:00:00 2001 From: Thorulf Neustrup Date: Fri, 13 Oct 2023 09:25:01 +0200 Subject: [PATCH 4/6] Corrected option name in CI --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 9a78c35..cd3f3c2 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v3 - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Debug -DULS_TESTING=ON + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Debug -DULS_WITH_TESTS=ON - name: Build run: cmake --build ${{github.workspace}}/build From 1c2ed33290d4583f1e67b5fc36090ceca122b919 Mon Sep 17 00:00:00 2001 From: Thorulf Neustrup Date: Tue, 7 Nov 2023 14:01:06 +0100 Subject: [PATCH 5/6] Fixed bad WError issues in libraries --- cmake/nlohmann.cmake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmake/nlohmann.cmake b/cmake/nlohmann.cmake index ab38701..7254a7e 100644 --- a/cmake/nlohmann.cmake +++ b/cmake/nlohmann.cmake @@ -4,4 +4,10 @@ FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz DOWNLOAD_EXTRACT_TIMESTAMP ON ) -FetchContent_MakeAvailable(json) + +# Manually make available so we can mark library as SYSTEM headers thus disabling warnings +FetchContent_GetProperties(json) +if(NOT json_POPULATED) + FetchContent_Populate(json) + add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} SYSTEM) +endif() \ No newline at end of file From abad259ec9eb9bc0e893cecf05f583c4ab1dafbe Mon Sep 17 00:00:00 2001 From: Thorulf Neustrup Date: Fri, 10 Nov 2023 14:52:31 +0100 Subject: [PATCH 6/6] Update .github/workflows/build-test.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marius Mikučionis --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 8c16117..0169986 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -22,5 +22,5 @@ jobs: run: cmake --build "$BUILD_DIR" --config $CMAKE_BUILD_TYPE - name: Test - working-directory: "$BUILD_DIR" + working-directory: ${{env.BUILD_DIR}} run: ctest --config $CMAKE_BUILD_TYPE --output-on-failure