`clang::PluginASTAction` with `clang::tooling::runToolOnCode` produce string output (for tests)?

206 Views Asked by At

With clang::tooling::runToolOnCode I can provide std::string input but I only get a bool output.

static const char
  *const from = "#include <string.h>\n"
                "int main(void) {\n"
                "    for(int i=0; i<strlen(\"FOO\"); i++) {}\n"
                "}\n",
  *const want = "#include <string.h>\n"
                "int main(void) {\n"
                "    for(size_t i=0; i<strlen(\"FOO\"); i++) {}\n"
                "}\n";

clang::tooling::runToolOnCode(std::make_unique<TypeCorrectPluginAction>(), from));

How do I get the modified source-code, without outputting to disk and reading from disk?

1

There are 1 best solutions below

0
On

I'm not sure about how to achieve this specifically, but I have a pointer.

You can check how it's done in the unittests in clang-tools, more specifically: here