38 lines
819 B
C++
38 lines
819 B
C++
//
|
|
// Created by erki on 07.03.21.
|
|
//
|
|
|
|
#include "RunOnCodeFixture.hpp"
|
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
#include <clang/Tooling/Tooling.h>
|
|
#include <clang/Frontend/FrontendActions.h>
|
|
|
|
RunOnCodeFixture::RunOnCodeFixture()
|
|
: finder(&storage)
|
|
, action(&finder)
|
|
{ }
|
|
|
|
bool RunOnCodeFixture::runCode(const std::string& code)
|
|
{
|
|
return clang::tooling::runToolOnCode(
|
|
clang::tooling::newFrontendActionFactory(&action)->create(),
|
|
code,
|
|
RunOnCodeFixture::INPUT_FILE
|
|
);
|
|
}
|
|
|
|
const std::vector<OperationLog>& RunOnCodeFixture::operator()(const std::string& code)
|
|
{
|
|
const bool success = runCode(code);
|
|
|
|
REQUIRE(success);
|
|
|
|
const auto& operations = storage.getOperations();
|
|
|
|
REQUIRE(operations.count(RunOnCodeFixture::INPUT_FILE) == 1);
|
|
|
|
return operations.at(RunOnCodeFixture::INPUT_FILE);
|
|
}
|