navid/veins / 83508482911f348af86cb892949a35bdce0d6b2f949b4a0faab7cba9a499fb82 / xveins/tests/integration/git_tests.cpp
git_tests.cpp
← xveins/tests/integration · 6493 bytes · raw · download
#include "test_support.h"
#include "integration/support.h"
namespace vn::integration {
namespace {
void git_bridge_import_materialize_export(test::Context& t) {
#if defined(_WIN32)
t.expect(true);
#else
if (!git_available()) {
t.expect(true);
return;
}
VnFixture f;
const fs::path git_repo = make_git_repository(t, f);
const fs::path vn_repo = f.root / "vnrepo";
f.vn({"init", vn_repo.string(), "-git-import:" + git_repo.string(),
"-remote:file:///tmp/veins-native"},
f.root);
t.expect_contains(f.vn({"remote", "list"}, vn_repo).out, "o\tfile:///tmp/veins-native");
t.expect_contains(f.vn({"cfg", "remote.default"}, vn_repo).out, "o");
std::string log = f.vn({"log", "-no-col-titles"}, vn_repo).out;
t.expect_contains(log, "git one");
t.expect_contains(log, "git two");
t.expect_eq(split_lines(f.vn({"ls", "-plain"}, vn_repo).out).size(), 1u);
f.vn({"git", "materialize"}, vn_repo);
t.expect_contains(f.vn({"stat"}, vn_repo).out, "working copy clean");
t.expect_eq(f.read("a.txt", vn_repo), "one\ntwo\n");
f.write("b.txt", "native\n", vn_repo);
f.commit("native commit", vn_repo);
f.vn({"git", "export"}, vn_repo);
const fs::path git_dir = vn_repo / ".veins" / "git";
const CommandResult subjects =
run_shell({"git", "--git-dir", git_dir.string(), "log", "--format=%s", "--all"}, f.root);
require_shell(t, subjects, "git log");
t.expect_contains(subjects.out, "native commit");
const CommandResult tree =
run_shell({"git", "--git-dir", git_dir.string(), "show", "master:b.txt"}, f.root);
require_shell(t, tree, "git show");
t.expect_eq(tree.out, "native\n");
t.expect_contains(f.vn({"fsck"}, vn_repo).out, "fsck: clean");
#endif
}
void git_bridge_invalid_import(test::Context& t) {
(void)t;
#if defined(_WIN32)
t.expect(true);
#else
VnFixture f;
const fs::path not_git = f.root / "not-git";
fs::create_directories(not_git);
f.failed({"init", (f.root / "bad").string(), "-git-import:" + not_git.string()},
"not a git repository root", f.root);
#endif
}
void git_bridge_import_remote_options(test::Context& t) {
#if defined(_WIN32)
t.expect(true);
#else
if (!git_available()) {
t.expect(true);
return;
}
VnFixture f;
const fs::path git_repo = make_git_repository(t, f);
const fs::path named = f.root / "named";
f.vn({"init", named.string(), "-git-import:" + git_repo.string(),
"-remote:file:///tmp/veins-upstream", "-remote-name:upstream"},
f.root);
t.expect_contains(f.vn({"remote", "list"}, named).out, "upstream\tfile:///tmp/veins-upstream");
t.expect_contains(f.vn({"cfg", "remote.default"}, named).out, "upstream");
const fs::path warning = f.root / "warning";
const CommandResult imported =
f.vn({"init", warning.string(), "-git-import:" + git_repo.string()}, f.root);
t.expect_contains(imported.text(), "no native remote configured");
t.expect_contains(imported.text(), "vn psh o");
const fs::path via_import = f.root / "via-import";
f.vn({"init", via_import.string()}, f.root);
f.vn({"git", "import", "-source:" + git_repo.string(), "-remote:file:///tmp/veins-import"},
via_import);
t.expect_contains(f.vn({"remote", "list"}, via_import).out, "o\tfile:///tmp/veins-import");
t.expect_contains(f.vn({"cfg", "remote.default"}, via_import).out, "o");
#endif
}
void git_mirror_push_and_tag(test::Context& t) {
#if defined(_WIN32)
t.expect(true);
#else
if (!git_available()) {
t.expect(true);
return;
}
VnFixture f;
f.init();
f.write("a.txt", "one\n");
f.vn({"bmk", "set", "master"});
f.commit("first");
const fs::path mirror = f.root / "mirror.git";
fs::create_directories(mirror);
require_shell(t, run_shell({"git", "init", "--bare", mirror.string()}, f.root),
"git init bare");
f.vn({"git", "remote", "add", "mirror", mirror.string()});
const CommandResult pushed = f.vn({"git", "mirror", "psh"}, f.repo);
t.expect_contains(pushed.out, "mirrored 1 bookmark(s)");
CommandResult heads =
run_shell({"git", "--git-dir", mirror.string(), "show-ref", "--heads"}, f.root);
require_shell(t, heads, "git show-ref heads");
t.expect_contains(heads.out, "refs/heads/master");
f.vn({"tag", "set", "v0.0.1"});
f.vn({"tag", "set", "v0.0.2"});
f.vn({"git", "mirror", "pt", "v0.0.1", "mirror"});
CommandResult tags =
run_shell({"git", "--git-dir", mirror.string(), "show-ref", "--tags"}, f.root);
require_shell(t, tags, "git show-ref tags");
t.expect_contains(tags.out, "refs/tags/v0.0.1");
t.expect_not_contains(tags.out, "refs/tags/v0.0.2");
f.vn({"tag", "set", "v0.0.3"});
f.vn({"git", "mirror", "pt", "v0.0.3", "mirror", "-dry-run"});
tags = run_shell({"git", "--git-dir", mirror.string(), "show-ref", "--tags"}, f.root);
require_shell(t, tags, "git show-ref tags after dry run");
t.expect_not_contains(tags.out, "refs/tags/v0.0.3");
f.vn({"git", "mirror", "push", "mirror"});
tags = run_shell({"git", "--git-dir", mirror.string(), "show-ref", "--tags"}, f.root);
require_shell(t, tags, "git show-ref tags after full push");
t.expect_contains(tags.out, "refs/tags/v0.0.2");
t.expect_contains(tags.out, "refs/tags/v0.0.3");
f.vn({"tag", "rm", "v0.0.2"});
f.vn({"git", "mirror", "push", "mirror"});
tags = run_shell({"git", "--git-dir", mirror.string(), "show-ref", "--tags"}, f.root);
require_shell(t, tags, "git show-ref tags without prune");
t.expect_contains(tags.out, "refs/tags/v0.0.2");
f.vn({"git", "mirror", "push", "mirror", "-prune"});
tags = run_shell({"git", "--git-dir", mirror.string(), "show-ref", "--tags"}, f.root);
require_shell(t, tags, "git show-ref tags after prune");
t.expect_not_contains(tags.out, "refs/tags/v0.0.2");
f.failed({"git", "mirror", "pt", "missing", "mirror"}, "unknown tag");
#endif
}
} // namespace
test::Suite git_suite() {
return {"git",
{
{"import_materialize_export", git_bridge_import_materialize_export},
{"invalid_import", git_bridge_invalid_import},
{"import_remote_options", git_bridge_import_remote_options},
{"mirror_push_and_tag", git_mirror_push_and_tag},
}};
}
} // namespace vn::integration