I am learning CTest
over the following code:
// A program that echoes lines on stdin back.
#include <iostream>
#include <string>
int main()
{
std::string line;
do
{
std::getline(std::cin, line);
std::cout << line << std::endl;
}while(! line.empty());
}
Now I need to perform a system test.
How can my tests.cpp
refer to standard input and output of the compiled binary? The test should obviously invoke it, produce some input and verify the output mirrors it. What's the CTest way of doing that?
My current CMakeLists.txt
stanza, though probably completely irrelevant:
enable_testing()
add_executable(tests tests.cpp)
add_test(NAME Tests
COMMAND tests)
Conclusion after reading the linked question(also closed).
- CTest can't do that. See @Tsyvarev 's comment below on how to do it in C++ in a non-portable way.
- There are various frameworks that can do it, my favourite was not mentioned unfortunately.
- A simple solution would be transform the tool into a non-interactive one.