cpp-subprocess/test/test_double_quotes.cc
Haowen Liu f6232a7f26
Improve CMake setup (#118)
* Support CMake 4

CMake 4 has removed compatibility with CMake < 3.5
Bumping minimum required version to 3.5 enables
CMake 4 to build this code.

* Move header into subdir

* Improve CMake setup

This commit configures and installs CMake metadata files. This also
provides the namespaced ALIAS target `cpp-subprocess::subprocess`.

* Update README with CMake instructions

* Update include paths in tests
2025-05-04 20:22:13 +05:30

31 lines
821 B
C++

#include <cpp-subprocess/subprocess.hpp>
#include <cassert>
#include <string>
namespace sp = subprocess;
// JSON requires the use of double quotes (see: https://json.org/).
// This test verifies proper handling of them.
void test_double_quotes()
{
// A simple JSON object.
const std::string expected{"{\"name\": \"value\"}"};
#ifdef __USING_WINDOWS__
const std::string command{"cmd.exe /c echo "};
#else
const std::string command{"echo "};
#endif
auto p = sp::Popen(command + expected, sp::output{sp::PIPE});
const auto out = p.communicate().first;
std::string result{out.buf.begin(), out.buf.end()};
// The `echo` command appends a newline.
result.erase(result.find_last_not_of(" \n\r\t") + 1);
assert(result == expected);
}
int main() {
test_double_quotes();
return 0;
}