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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
//===- unittests/BuildSystem/BuildValueTest.cpp ---------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "llbuild/Basic/Hashing.h"
#include "llbuild/BuildSystem/BuildValue.h"
#include "gtest/gtest.h"
using namespace llbuild;
using namespace llbuild::buildsystem;
using namespace llvm;
namespace {
/// We should support decoding an empty value without crashing.
TEST(BuildValueTest, emptyDecode) {
auto result = BuildValue::fromData(core::ValueType());
EXPECT_EQ(result.toData(), BuildValue::makeInvalid().toData());
}
TEST(BuildValueTest, virtualValueSerialization) {
// Check that two identical values are equivalent.
{
BuildValue a = BuildValue::makeVirtualInput();
EXPECT_EQ(a.toData(), BuildValue::makeVirtualInput().toData());
}
// Check that a moved complex value is equivalent.
{
BuildValue tmp = BuildValue::makeVirtualInput();
BuildValue a = std::move(tmp);
EXPECT_EQ(a.toData(), BuildValue::makeVirtualInput().toData());
}
// Check that an rvalue initialized complex value is equivalent.
{
BuildValue tmp = BuildValue::makeVirtualInput();
BuildValue a{ std::move(tmp) };
EXPECT_EQ(a.toData(), BuildValue::makeVirtualInput().toData());
}
// Check that a round-tripped value is equivalent.
EXPECT_EQ(BuildValue::makeVirtualInput().toData(),
BuildValue::fromData(
BuildValue::makeVirtualInput().toData()).toData());
}
TEST(BuildValueTest, commandValueSingleOutputSerialization) {
basic::FileInfo infos[1] = {};
infos[0].size = 1;
// Check that two identical values are equivalent.
{
BuildValue a = BuildValue::makeSuccessfulCommand(infos);
EXPECT_EQ(a.toData(), BuildValue::makeSuccessfulCommand(infos).toData());
}
// Check that a moved complex value is equivalent.
{
BuildValue tmp = BuildValue::makeSuccessfulCommand(infos);
BuildValue a = std::move(tmp);
EXPECT_EQ(a.toData(), BuildValue::makeSuccessfulCommand(infos).toData());
}
// Check that an rvalue initialized complex value is equivalent.
{
BuildValue tmp = BuildValue::makeSuccessfulCommand(infos);
BuildValue a{ std::move(tmp) };
EXPECT_EQ(a.toData(), BuildValue::makeSuccessfulCommand(infos).toData());
}
// Check that a round-tripped value is equivalent.
EXPECT_EQ(BuildValue::makeSuccessfulCommand(infos).toData(),
BuildValue::fromData(
BuildValue::makeSuccessfulCommand(infos).toData()).toData());
}
TEST(BuildValueTest, commandValueMultipleOutputsSerialization) {
basic::FileInfo infos[2] = {};
infos[0].size = 1;
infos[1].size = 2;
// Check that two identical values are equivalent.
{
BuildValue a = BuildValue::makeSuccessfulCommand(infos);
EXPECT_EQ(a.toData(),
BuildValue::makeSuccessfulCommand(infos).toData());
}
// Check that a moved complex value is equivalent.
{
BuildValue tmp = BuildValue::makeSuccessfulCommand(infos);
BuildValue a = std::move(tmp);
EXPECT_EQ(a.toData(),
BuildValue::makeSuccessfulCommand(infos).toData());
}
// Check that an rvalue initialized complex value is equivalent.
{
BuildValue tmp = BuildValue::makeSuccessfulCommand(infos);
BuildValue a{ std::move(tmp) };
EXPECT_EQ(a.toData(), BuildValue::makeSuccessfulCommand(infos).toData());
}
// Check that a round-tripped value is equivalent.
EXPECT_EQ(BuildValue::makeSuccessfulCommand(infos).toData(),
BuildValue::fromData(
BuildValue::makeSuccessfulCommand(infos).toData()).toData());
}
TEST(BuildValueTest, commandValueWithSignatureSingleOutputSerialization) {
auto signature = llbuild::basic::CommandSignature(0xDEADBEEF);
basic::FileInfo infos[1] = {};
infos[0].size = 1;
// Check that two identical values are equivalent.
{
BuildValue a = BuildValue::makeSuccessfulCommandWithOutputSignature(infos, signature);
EXPECT_EQ(a.toData(),
BuildValue::makeSuccessfulCommandWithOutputSignature(infos, signature).toData());
}
// Check that a moved complex value is equivalent.
{
BuildValue tmp = BuildValue::makeSuccessfulCommandWithOutputSignature(infos, signature);
BuildValue a = std::move(tmp);
EXPECT_EQ(a.toData(),
BuildValue::makeSuccessfulCommandWithOutputSignature(infos, signature).toData());
}
// Check that an rvalue initialized complex value is equivalent.
{
BuildValue tmp = BuildValue::makeSuccessfulCommandWithOutputSignature(infos, signature);
BuildValue a{ std::move(tmp) };
EXPECT_EQ(a.toData(),
BuildValue::makeSuccessfulCommandWithOutputSignature(infos, signature).toData());
}
// Check that a round-tripped value is equivalent.
EXPECT_EQ(BuildValue::makeSuccessfulCommandWithOutputSignature(infos, signature).toData(),
BuildValue::fromData(
BuildValue::makeSuccessfulCommandWithOutputSignature(
infos, signature).toData()).toData());
}
TEST(BuildValueTest, directoryListValues) {
basic::FileInfo mockInfo{};
std::vector<std::string> strings{ "hello", "world" };
// Check that two identical values are equivalent.
{
BuildValue a = BuildValue::makeDirectoryContents(mockInfo, strings);
EXPECT_EQ(a.toData(),
BuildValue::makeDirectoryContents(mockInfo, strings).toData());
}
// Check that a moved complex value is equivalent.
{
BuildValue tmp = BuildValue::makeDirectoryContents(mockInfo, strings);
BuildValue a = std::move(tmp);
EXPECT_EQ(a.toData(),
BuildValue::makeDirectoryContents(mockInfo, strings).toData());
}
// Check that an rvalue initialized complex value is equivalent.
{
BuildValue tmp = BuildValue::makeDirectoryContents(mockInfo, strings);
BuildValue a{ std::move(tmp) };
EXPECT_EQ(a.toData(),
BuildValue::makeDirectoryContents(mockInfo, strings).toData());
}
// Check the contents are correct.
{
BuildValue tmp = BuildValue::makeDirectoryContents(mockInfo, strings);
auto result = tmp.getDirectoryContents();
EXPECT_EQ(result.size(), 2U);
EXPECT_EQ(result[0], "hello");
EXPECT_EQ(result[1], "world");
}
}
TEST(BuildValueTest, staleFileRemovalValues) {
std::vector<std::string> files { "a.out", "Info.plist" };
{
BuildValue a = BuildValue::makeStaleFileRemoval(ArrayRef<std::string>(files));
auto nodes = a.getStaleFileList();
EXPECT_EQ(2UL, nodes.size());
EXPECT_EQ(nodes[0], "a.out");
EXPECT_EQ(nodes[1], "Info.plist");
}
{
BuildValue a = BuildValue::makeStaleFileRemoval(ArrayRef<std::string>(files));
BuildValue b = BuildValue::fromData(a.toData());
auto nodes = b.getStaleFileList();
EXPECT_EQ(2UL, nodes.size());
EXPECT_EQ(nodes[0], "a.out");
EXPECT_EQ(nodes[1], "Info.plist");
}
}
}
|