navid/veins / 4fd13fa7c7603bf558806ccfb7f45c765d05b76656b66e4497a9bbab0ca1f09f / xveins/tests/integration/git_tests.cpp
git_tests.cpp
← xveins/tests/integration · 2204 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()}, f.root);
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
}
} // namespace
test::Suite git_suite() {
return {"git",
{
{"import_materialize_export", git_bridge_import_materialize_export},
{"invalid_import", git_bridge_invalid_import},
}};
}
} // namespace vn::integration