diff options
| author | Leitwolf | 2026-10-24 19:03:40 +0300 |
|---|---|---|
| committer | GitHub | 2026-10-24 19:03:40 +0300 |
| commit | 4f1c759cffcb14bd6511e1d7c5fbace682e24f2d (patch) | |
| tree | 415fe5d48a5b48650bba3747beaf245d727c4f61 /src/Progmasoft/Runner/Protocol.cpp | |
| parent | 83c6fc3ac13abe83fa39f7b5f8559ccaf4412233 (diff) | |
| parent | 622188f9c08e4af35941c146979883ed4882410e (diff) | |
| download | catch3-4f1c759cffcb14bd6511e1d7c5fbace682e24f2d.tar.gz | |
Merge pull request #15 from Progmasoft/feature/catch3-runner
Replace Catch2's runner with the Catch3 runner
Diffstat (limited to 'src/Progmasoft/Runner/Protocol.cpp')
| -rw-r--r-- | src/Progmasoft/Runner/Protocol.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/Progmasoft/Runner/Protocol.cpp b/src/Progmasoft/Runner/Protocol.cpp new file mode 100644 index 00000000..48bf52b9 --- /dev/null +++ b/src/Progmasoft/Runner/Protocol.cpp @@ -0,0 +1,64 @@ +// Copyright (c) 2026 Progmasoft. +// SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-1.1 +#include "Protocol.hpp" + +namespace Progmasoft::Catch3::Runner +{ + std::optional<std::string> + LineReader::Next() + { + while (true) + { + const auto end = buffer_.find('\n', scanned_); + if (end != std::string::npos) + { + std::string line = buffer_.substr(0, end); + buffer_.erase(0, end + 1); + scanned_ = 0; + if (!line.empty() && line.back() == '\r') + { + line.pop_back(); + } + return line; + } + scanned_ = buffer_.size(); + if (ended_) + { + if (buffer_.empty()) + { + return std::nullopt; + } + // A last line without its end still counts. + std::string line = std::move(buffer_); + buffer_.clear(); + scanned_ = 0; + return line; + } + char chunk[8192]; + const auto count = pipe_.Read(chunk, sizeof(chunk)); + if (count <= 0) + { + ended_ = true; + continue; + } + buffer_.append(chunk, static_cast<std::size_t>(count)); + } + } + + Status + MessageWriter::Send(const JsonValue &message) + { + std::string line = message.ToString(); + line.push_back('\n'); + const std::lock_guard lock{mutex_}; + return pipe_.Write(line); + } + + JsonValue + Message(std::string_view kind) + { + JsonValue message = JsonValue::Object(); + message.Set("t", kind); + return message; + } +} // namespace Progmasoft::Catch3::Runner |