navid/veins / 83508482911f348af86cb892949a35bdce0d6b2f949b4a0faab7cba9a499fb82 / xveins/tests/integration/refs_tests.cpp

refs_tests.cpp

← xveins/tests/integration · 2929 bytes · raw · download

#include "test_support.h"

#include "integration/support.h"

namespace vn::integration {
namespace {

void refs_bookmarks(test::Context& t) {
    VnFixture f;
    f.init();
    f.write("f.txt", "one\n");
    f.commit("one");
    const std::string one = f.commit_for_message("one");
    f.write("f.txt", "two\n");
    f.commit("two");
    const std::string two = f.commit_for_message("two");
    f.vn({"bmk", "set", "main", "-rev", one});
    f.vn({"bmk", "set", "feature", "-rev", two});
    std::string listing = f.vn({"bmk", "ls"}).out;
    t.expect_contains(listing, "main");
    t.expect_contains(listing, "feature");
    f.vn({"bmk", "mv", "main", "-rev", two});
    t.expect_contains(f.vn({"bmk", "ls"}).out, two.substr(0, 12));
    f.vn({"bmk", "rm", "feature"});
    t.expect_not_contains(f.vn({"bmk", "ls"}).out, "feature");
    f.failed({"bmk", "rm", "missing"}, "no such bookmark");
}

void refs_current_bookmark(test::Context& t) {
    VnFixture f;
    f.init();
    f.write("f.txt", "one\n");
    f.vn({"bmk", "set", "main"});
    f.commit("one");
    const std::string one = f.hash("main");
    t.expect_contains(f.vn({"bmk", "ls"}).out, one.substr(0, 12));
    f.write("f.txt", "two\n");
    f.commit("two");
    const std::string two = f.hash("main");
    t.expect_ne(one, two);
    t.expect_contains(f.vn({"bmk", "ls"}).out, two.substr(0, 12));
    t.expect_contains(f.vn({"cfg"}).out, "bookmark.current = main");
}

void refs_tags(test::Context& t) {
    VnFixture f;
    f.init();
    f.write("f.txt", "one\n");
    f.commit("one");
    f.vn({"tag", "set", "v0.0.9"});
    f.vn({"tag", "set", "v0.0.10"});
    const std::string listing = f.vn({"tag", "ls"}).out;
    t.expect_contains(listing, "v0.0.9");
    t.expect_contains(listing, "v0.0.10");
    t.expect_eq(trim_copy(f.vn({"tag", "latest"}).out), "v0.0.10");
    f.vn({"tag", "rm", "v0.0.9"});
    t.expect_not_contains(f.vn({"tag", "ls"}).out, "v0.0.9");
    f.failed({"tag", "rm", "missing"}, "no such tag");
}

void refs_remote_configuration(test::Context& t) {
    VnFixture f;
    f.init();
    f.vn({"remote", "add", "origin", "file:///tmp/example"});
    t.expect_contains(f.vn({"remote", "list"}).out, "origin");
    f.failed({"remote", "add", "origin", "file:///other"}, "already exists");
    f.vn({"remote", "set-url", "origin", "file:///tmp/other"});
    t.expect_contains(f.vn({"remote", "list"}).out, "file:///tmp/other");
    f.vn({"remote", "remove", "origin"});
    t.expect_not_contains(f.vn({"remote", "list"}).out, "origin");
    f.failed({"remote", "remove", "origin"}, "unknown remote");
}

} // namespace

test::Suite refs_suite() {
    return {"refs",
            {
                {"bookmarks", refs_bookmarks},
                {"current_bookmark", refs_current_bookmark},
                {"tags", refs_tags},
                {"remote_configuration", refs_remote_configuration},
            }};
}
} // namespace vn::integration