From 0b42ada60d702568b0191c16761b5fbed8cfbab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Fri, 19 Jul 2019 13:56:08 +0200 Subject: [PATCH] Coverage helper now passes-on test return value This allows #1684 to proceed forward. --- misc/coverage-helper.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/misc/coverage-helper.cpp b/misc/coverage-helper.cpp index a6643838..b9558b75 100644 --- a/misc/coverage-helper.cpp +++ b/misc/coverage-helper.cpp @@ -89,27 +89,30 @@ std::string windowsify_path(std::string path) { return path; } -void exec_cmd(std::string const& cmd, int log_num, std::string const& path) { +int exec_cmd(std::string const& cmd, int log_num, std::string const& path) { std::array buffer; -#if defined(_WIN32) + // cmd has already been escaped outside this function. auto real_cmd = "OpenCppCoverage --export_type binary:cov-report" + std::to_string(log_num) + ".bin --quiet " + "--sources " + escape_arg(path) + " --cover_children -- " + cmd; std::cout << "=== Marker ===: Cmd: " << real_cmd << '\n'; - std::shared_ptr pipe(_popen(real_cmd.c_str(), "r"), _pclose); -#else // Just for testing, in the real world we will always work under WIN32 - (void)log_num; (void)path; - std::shared_ptr pipe(popen(cmd.c_str(), "r"), pclose); -#endif - + auto pipe = _popen(real_cmd.c_str(), "r"); + if (!pipe) { throw std::runtime_error("popen() failed!"); } - while (!feof(pipe.get())) { - if (fgets(buffer.data(), 128, pipe.get()) != nullptr) { + while (!feof(pipe)) { + if (fgets(buffer.data(), 128, pipe) != nullptr) { std::cout << buffer.data(); } } + + auto ret = _pclose(pipe); + if (ret == -1) { + throw std::runtime_error("underlying error in pclose()"); + } + + return ret; } // argv should be: