navid/veins / master / xveins/tests/integration/git_tests.cpp
git_tests.cpp
← xveins/tests/integration · 3842 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
}
} // 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},
}};
}
} // namespace vn::integration