From 153ba2a5c1bc421fe8366f4966964bad557ac26e Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 9 Mar 2023 14:04:42 -0600 Subject: [PATCH] Add main test Signed-off-by: Felipe Contreras --- t/.gitignore | 1 + t/main.t | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 t/.gitignore create mode 100755 t/main.t diff --git a/t/.gitignore b/t/.gitignore new file mode 100644 index 0000000..12b46b8 --- /dev/null +++ b/t/.gitignore @@ -0,0 +1 @@ +/test-results/ diff --git a/t/main.t b/t/main.t new file mode 100755 index 0000000..c4603fc --- /dev/null +++ b/t/main.t @@ -0,0 +1,94 @@ +#!/bin/bash +# +# Copyright (c) 2023 Felipe Contreras +# + +test_description='Main tests' + +. "${SHARNESS_TEST_SRCDIR-/usr/share/sharness}"/sharness.sh || exit 1 + +check() { + echo "$3" > expected && + git -C "$1" show -q --format='%s' "$2" > actual && + test_cmp expected actual +} + +git_clone() { + ( + git init -q "$2" && + cd "$2" && + hg-fast-export.sh --repo "../$1" + ) +} + +setup() { + cat > "$HOME"/.hgrc <<-EOF + [ui] + username = H G Wells + EOF +} + +setup + +test_expect_success 'basic' ' + test_when_finished "rm -rf hgrepo gitrepo" && + + ( + hg init hgrepo && + cd hgrepo && + echo zero > content && + hg add content && + hg commit -m zero + ) && + + git_clone hgrepo gitrepo && + check gitrepo @ zero +' + +test_expect_success 'merge' ' + test_when_finished "rm -rf hgrepo gitrepo" && + + ( + hg init hgrepo && + cd hgrepo && + echo a > content && + echo a > file1 && + hg add content file1 && + hg commit -m "origin" && + + echo b > content && + echo b > file2 && + hg add file2 && + hg rm file1 && + hg commit -m "right" && + + hg update -r0 && + echo c > content && + hg commit -m "left" && + + HGMERGE=true hg merge -r1 && + hg commit -m "merge" + ) && + + git_clone hgrepo gitrepo && + + cat > expected <<-EOF && + left + c + tree @: + + content + file2 + EOF + + ( + cd gitrepo + git show -q --format='%s' @^ && + git show @:content && + git show @: + ) > actual && + + test_cmp expected actual +' + +test_done