Example #1
0
TEST(copyStrings, CopyMultiple)
{
    std::vector<uint8_t> contents;
    MemoryFilesystem filesystem = MemoryFilesystem({
        MemoryFilesystem::Entry::File("in1.strings", Contents("string1 = value1;")),
        MemoryFilesystem::Entry::File("in2.strings", Contents("string2 = value2;")),
        MemoryFilesystem::Entry::Directory("output", { }),
    });

    Driver driver;
    EXPECT_EQ(0, driver.run({
        "in1.strings",
        "in2.strings",
        "--outdir", "output",
        "--outputencoding", "utf-8",
    }, { }, &filesystem, "/"));

    contents.clear();
    EXPECT_TRUE(filesystem.read(&contents, "output/in1.strings"));
    EXPECT_EQ(contents, Contents("string1 = value1;\n"));

    contents.clear();
    EXPECT_TRUE(filesystem.read(&contents, "output/in2.strings"));
    EXPECT_EQ(contents, Contents("string2 = value2;\n"));
}
Example #2
0
TEST(copyStrings, InputOutputEncoding)
{
    std::unordered_map<std::string, plist::Format::Encoding> encodings = {
        { "utf-8", plist::Format::Encoding::UTF8 },
        { "utf-16", plist::Format::Encoding::UTF16LE },
        { "utf-32", plist::Format::Encoding::UTF32LE },
    };

    for (auto const &entry1 : encodings) {
        for (auto const &entry2 : encodings) {
            /* Convert input to each encoding. */
            MemoryFilesystem filesystem = MemoryFilesystem({
                MemoryFilesystem::Entry::File("in.strings", plist::Format::Encodings::Convert(
                    Contents("string = value;\n"),
                    plist::Format::Encoding::UTF8,
                    entry1.second
                )),
                MemoryFilesystem::Entry::Directory("output", { }),
            });

            Driver driver;
            EXPECT_EQ(0, driver.run({
                "in.strings",
                "--outdir", "output",
                "--inputencoding", entry1.first,
                "--outputencoding", entry2.first,
            }, { }, &filesystem, "/"));

            std::vector<uint8_t> contents;
            EXPECT_TRUE(filesystem.read(&contents, "output/in.strings"));

            /* Expect output in each encoding. */
            EXPECT_EQ(contents, plist::Format::Encodings::Convert(
                Contents("string = value;\n"),
                plist::Format::Encoding::UTF8,
                entry2.second
            ));
        }
    }
}
TEST(DirectoryDependencyInfo, Deserialize)
{
    MemoryFilesystem filesystem = MemoryFilesystem({
        MemoryFilesystem::Entry::Directory("root", {
            MemoryFilesystem::Entry::File("file1", { }),
            MemoryFilesystem::Entry::File("file2", { }),
            MemoryFilesystem::Entry::Directory("dir", {
                MemoryFilesystem::Entry::File("file3", { }),
            }),
        }),
    });

    auto info = DirectoryDependencyInfo::Deserialize(&filesystem, "/root");
    ASSERT_TRUE(info);
    EXPECT_EQ(info->dependencyInfo().inputs(), std::vector<std::string>({
        "/root/file1",
        "/root/file2",
        "/root/dir",
        "/root/dir/file3",
    }));
    EXPECT_TRUE(info->dependencyInfo().outputs().empty());
}
Example #4
0
TEST(SimpleExecutor, PropagateToolResult)
{
    /* Create in-memory execution environment. */
    auto filesystem = MemoryFilesystem({
        MemoryFilesystem::Entry::File("fail-tool", std::vector<uint8_t>()),
        MemoryFilesystem::Entry::File("success-tool", std::vector<uint8_t>()),
    });

    auto launcher = process::MemoryLauncher({
        { "/fail-tool", [](Filesystem *filesystem, process::Context const *context) -> ext::optional<int> {
            return 1;
        } },
        { "/success-tool", [](Filesystem *filesystem, process::Context const *context) -> ext::optional<int> {
            return 0;
        } },
    });

    auto registry = builtin::Registry::Create({
        std::static_pointer_cast<builtin::Driver>(std::make_shared<Driver>("builtin-fail", [](process::Context const *context, Filesystem *filesystem) -> int {
            return 1;
        })),
        std::static_pointer_cast<builtin::Driver>(std::make_shared<Driver>("builtin-success", [](process::Context const *context, Filesystem *filesystem) -> int {
            return 0;
        })),
    });

    auto context = process::MemoryContext(
        "",
        "/",
        std::vector<std::string>(),
        std::unordered_map<std::string, std::string>(),
        0,
        0,
        "user",
        "group");

    /* Create invocations to execute. */
    auto builtinSuccess = pbxbuild::Tool::Invocation();
    builtinSuccess.executable() = pbxbuild::Tool::Invocation::Executable::Builtin("builtin-success");
    auto builtinFail = pbxbuild::Tool::Invocation();
    builtinFail.executable() = pbxbuild::Tool::Invocation::Executable::Builtin("builtin-fail");

    auto externalSuccess = pbxbuild::Tool::Invocation();
    externalSuccess.executable() = pbxbuild::Tool::Invocation::Executable::External("success-tool");
    auto externalFail = pbxbuild::Tool::Invocation();
    externalFail.executable() = pbxbuild::Tool::Invocation::Executable::External("fail-tool");

    /* Create test executor. */
    auto formatter = xcformatter::NullFormatter::Create();
    std::vector<std::string> const executablePaths = { "/" };
    SimpleExecutor executor = SimpleExecutor(formatter, false, registry);

    /* Succeed if all tools succeed. */
    auto success = executor.performInvocations(
        &context,
        &launcher,
        &filesystem,
        executablePaths,
        {
            builtinSuccess,
            externalSuccess,
        },
        false);
    ASSERT_TRUE(success.first);
    EXPECT_EQ(success.second.size(), 0);

    /* Fail if a tool fails. */
    auto fail1 = executor.performInvocations(
        &context,
        &launcher,
        &filesystem,
        executablePaths,
        {
            externalFail,
            builtinSuccess,
            externalSuccess,
        },
        false);
    ASSERT_FALSE(fail1.first);
    EXPECT_EQ(fail1.second.size(), 1);

    /* Fail if a tool fails, even if not first. */
    auto fail2 = executor.performInvocations(
        &context,
        &launcher,
        &filesystem,
        executablePaths,
        {
            builtinSuccess,
            builtinFail,
            externalSuccess,
            externalFail,
        },
        false);
    ASSERT_FALSE(fail2.first);
    EXPECT_EQ(fail2.second.size(), 1);
}