Skip to content

Commit b4ebc22

Browse files
committed
Add regression tests for error cases on Rugged::Diff.diff
I would like to start refactoring `Rugged::Diff.diff`, but we are missing tests for some of the branches in the C code. This commit adds tests for those branches.
1 parent e514359 commit b4ebc22

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/diff_test.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,3 +1153,38 @@ def test_stats
11531153
end
11541154
end
11551155
end
1156+
1157+
class TreeDiffRegression < Rugged::TestCase
1158+
def test_nil_repo
1159+
assert_raises TypeError do
1160+
Rugged::Tree.diff nil, "foo"
1161+
end
1162+
end
1163+
1164+
def test_self_is_not_tree
1165+
repo = FixtureRepo.from_libgit2("diff")
1166+
1167+
ex = assert_raises TypeError do
1168+
Rugged::Tree.diff repo, "foo"
1169+
end
1170+
assert_equal "At least a Rugged::Tree object is required for diffing", ex.message
1171+
end
1172+
1173+
def test_self_or_other_must_be_present
1174+
repo = FixtureRepo.from_libgit2("diff")
1175+
1176+
ex = assert_raises TypeError do
1177+
Rugged::Tree.diff repo, nil, nil
1178+
end
1179+
assert_equal "Need 'old' or 'new' for diffing", ex.message
1180+
end
1181+
1182+
def test_other_is_wrong_type
1183+
repo = FixtureRepo.from_libgit2("diff")
1184+
1185+
ex = assert_raises TypeError do
1186+
Rugged::Tree.diff repo, nil, Object.new
1187+
end
1188+
assert_equal "A Rugged::Commit, Rugged::Tree or Rugged::Index instance is required", ex.message
1189+
end
1190+
end

0 commit comments

Comments
 (0)