mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	Integrate tests for #1394 into our test suite
This commit is contained in:
		| @@ -9,6 +9,38 @@ | ||||
| #include <string> | ||||
| #include <vector> | ||||
|  | ||||
| std::string escape_arg(const std::string& arg) { | ||||
|     if (arg.empty() == false && | ||||
|         arg.find_first_of(" \t\n\v\"") == arg.npos) { | ||||
|         return arg; | ||||
|     } | ||||
|  | ||||
|     std::string escaped; | ||||
|     escaped.push_back('"'); | ||||
|     for (auto it = arg.begin(); ; ++it) { | ||||
|         int num_backslashes = 0; | ||||
|  | ||||
|         while (it != arg.end() && *it == '\\') { | ||||
|             ++it; | ||||
|             ++num_backslashes; | ||||
|         } | ||||
|  | ||||
|         if (it == arg.end()) { | ||||
|             escaped.append(num_backslashes * 2, '\\'); | ||||
|             break; | ||||
|         } else if (*it == '"') { | ||||
|             escaped.append(num_backslashes * 2 + 1, '\\'); | ||||
|             escaped.push_back(*it); | ||||
|         } else { | ||||
|             escaped.append(num_backslashes, '\\'); | ||||
|             escaped.push_back(*it); | ||||
|         } | ||||
|     } | ||||
|     escaped.push_back('"'); | ||||
|  | ||||
|     return escaped; | ||||
| } | ||||
|  | ||||
|  | ||||
| void create_empty_file(std::string const& path) { | ||||
|     std::ofstream ofs(path); | ||||
| @@ -60,8 +92,9 @@ std::string windowsify_path(std::string path) { | ||||
| void exec_cmd(std::string const& cmd, int log_num, std::string const& path) { | ||||
|     std::array<char, 128> 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 " + path + " --cover_children -- " + cmd; | ||||
|         + ".bin --quiet " + "--sources " + escape_arg(path) + " --cover_children -- " + cmd; | ||||
|     std::cout << "=== Marker ===: Cmd: " << real_cmd << '\n'; | ||||
|     std::shared_ptr<FILE> pipe(_popen(real_cmd.c_str(), "r"), _pclose); | ||||
| #else // Just for testing, in the real world we will always work under WIN32 | ||||
| @@ -91,9 +124,9 @@ int main(int argc, char** argv) { | ||||
|     assert(sep - begin(args) == 2 && "Structure differs from expected!"); | ||||
|  | ||||
|     auto num = parse_log_file_arg(args[1]); | ||||
|  | ||||
|      | ||||
|     auto cmdline = std::accumulate(++sep, end(args), std::string{}, [] (const std::string& lhs, const std::string& rhs) { | ||||
|         return lhs + ' ' + rhs; | ||||
|         return lhs + ' ' + escape_arg(rhs); | ||||
|     }); | ||||
|  | ||||
|     try { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Martin Hořeňovský
					Martin Hořeňovský