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
|
//===- unittests/Core/DependencyInfoParserTest.cpp ------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 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/Core/DependencyInfoParser.h"
#include "gtest/gtest.h"
#include <string>
#include <vector>
using namespace llbuild;
using namespace llbuild::core;
namespace {
TEST(DependencyInfoParserTest, basic) {
typedef std::pair<std::string, std::string> Event;
typedef std::pair<std::string, uint64_t> Error;
struct TestActions : public DependencyInfoParser::ParseActions {
std::vector<Event> events;
std::vector<Error> errors;
virtual void error(const char* message, uint64_t length) override {
errors.push_back({ message, length });
}
virtual void actOnVersion(StringRef name) override {
events.push_back({ "version", std::string(name) });
}
virtual void actOnInput(StringRef name) override {
events.push_back({ "input", std::string(name) });
}
virtual void actOnOutput(StringRef name) override {
events.push_back({ "output", std::string(name) });
}
virtual void actOnMissing(StringRef name) override {
events.push_back({ "missing", std::string(name) });
}
};
#define INPUT(str) \
StringRef(str, sizeof(str) - 1); \
assert(sizeof(str) != 0);
// Check missing terminator diagnose (on empty file).
{
TestActions actions;
auto input = INPUT("xxx");
DependencyInfoParser(input, actions).parse();
EXPECT_EQ(std::vector<Error>{ Error("missing null terminator", 3) },
actions.errors);
EXPECT_EQ(std::vector<Event>{}, actions.events);
}
// Check invalid initial record.
{
TestActions actions;
auto input = INPUT("\x01\x00");
DependencyInfoParser(input, actions).parse();
EXPECT_EQ(std::vector<Error>{ Error("missing version record", 0) },
actions.errors);
EXPECT_EQ(std::vector<Event>{}, actions.events);
}
// Check empty operand.
{
TestActions actions;
auto input = INPUT("\x00\x00");
DependencyInfoParser(input, actions).parse();
EXPECT_EQ(std::vector<Error>{ Error("empty operand", 0) },
actions.errors);
EXPECT_EQ(std::vector<Event>{}, actions.events);
}
// Check duplicate version.
{
TestActions actions;
auto input = INPUT("\x00VERSION\x00\x00VERSION\x00");
DependencyInfoParser(input, actions).parse();
EXPECT_EQ(std::vector<Error>{ Error("invalid duplicate version", 9) },
actions.errors);
EXPECT_EQ(std::vector<Event>{ Event("version", "VERSION") },
actions.events);
}
// Check a valid file.
{
TestActions actions;
auto input = INPUT("\x00VERSION\x00"
"\x10INPUT\x00"
"\x11MISSING\x00"
"\x40OUTPUT\x00");
DependencyInfoParser(input, actions).parse();
EXPECT_EQ(std::vector<Error>{}, actions.errors);
auto expectedEvents = std::vector<Event>{
Event("version", "VERSION"),
Event("input", "INPUT"),
Event("missing", "MISSING"),
Event("output", "OUTPUT"),
};
EXPECT_EQ(expectedEvents, actions.events);
}
}
}
|