1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
//===- unittests/Frontend/CompileJobCacheResultTest.cpp - CI tests //------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "clang/Frontend/CompileJobCacheResult.h"
#include "llvm/Testing/Support/Error.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using namespace clang;
using namespace clang::cas;
using namespace llvm::cas;
using llvm::Succeeded;
using Output = CompileJobCacheResult::Output;
using OutputKind = CompileJobCacheResult::OutputKind;
std::vector<Output> getAllOutputs(CompileJobCacheResult Result) {
std::vector<Output> Outputs;
llvm::cantFail(Result.forEachOutput([&](Output O) {
Outputs.push_back(O);
return llvm::Error::success();
}));
return Outputs;
}
TEST(CompileJobCacheResultTest, Empty) {
std::unique_ptr<ObjectStore> CAS = createInMemoryCAS();
CompileJobCacheResult::Builder B;
std::optional<ObjectRef> Result;
ASSERT_THAT_ERROR(B.build(*CAS).moveInto(Result), Succeeded());
std::optional<CompileJobCacheResult> Proxy;
CompileJobResultSchema Schema(*CAS);
ASSERT_THAT_ERROR(Schema.load(*Result).moveInto(Proxy), Succeeded());
EXPECT_EQ(Proxy->getNumOutputs(), 0u);
}
TEST(CompileJobCacheResultTest, AddOutputs) {
std::unique_ptr<ObjectStore> CAS = createInMemoryCAS();
auto Obj1 = llvm::cantFail(CAS->storeFromString({}, "obj1"));
auto Obj2 = llvm::cantFail(CAS->storeFromString({}, "obj2"));
std::vector<Output> Expected = {
Output{Obj1, OutputKind::MainOutput},
Output{Obj2, OutputKind::Dependencies},
};
CompileJobCacheResult::Builder B;
for (const auto &Output : Expected)
B.addOutput(Output.Kind, Output.Object);
std::optional<ObjectRef> Result;
ASSERT_THAT_ERROR(B.build(*CAS).moveInto(Result), Succeeded());
std::optional<CompileJobCacheResult> Proxy;
CompileJobResultSchema Schema(*CAS);
ASSERT_THAT_ERROR(Schema.load(*Result).moveInto(Proxy), Succeeded());
EXPECT_EQ(Proxy->getNumOutputs(), 2u);
auto Actual = getAllOutputs(*Proxy);
EXPECT_EQ(Actual, Expected);
}
TEST(CompileJobCacheResultTest, AddKindMap) {
std::unique_ptr<ObjectStore> CAS = createInMemoryCAS();
auto Obj1 = llvm::cantFail(CAS->storeFromString({}, "obj1"));
auto Obj2 = llvm::cantFail(CAS->storeFromString({}, "obj2"));
auto Obj3 = llvm::cantFail(CAS->storeFromString({}, "err"));
std::vector<Output> Expected = {
Output{Obj1, OutputKind::MainOutput},
Output{Obj2, OutputKind::Dependencies},
};
CompileJobCacheResult::Builder B;
B.addKindMap(OutputKind::MainOutput, "/main");
B.addKindMap(OutputKind::Dependencies, "/deps");
ASSERT_THAT_ERROR(B.addOutput("/main", Obj1), Succeeded());
ASSERT_THAT_ERROR(B.addOutput("/deps", Obj2), Succeeded());
EXPECT_THAT_ERROR(B.addOutput("/other", Obj3), llvm::Failed());
std::optional<ObjectRef> Result;
ASSERT_THAT_ERROR(B.build(*CAS).moveInto(Result), Succeeded());
std::optional<CompileJobCacheResult> Proxy;
CompileJobResultSchema Schema(*CAS);
ASSERT_THAT_ERROR(Schema.load(*Result).moveInto(Proxy), Succeeded());
EXPECT_EQ(Proxy->getNumOutputs(), 2u);
auto Actual = getAllOutputs(*Proxy);
EXPECT_EQ(Actual, Expected);
}
|