Skip to content

Commit

Permalink
Add HeadVersion tests
Browse files Browse the repository at this point in the history
vladshablinsky authored and xu-cheng committed Jul 16, 2016

Verified

This commit was signed with the committer’s verified signature. The key has expired.
xu-cheng Cheng Xu
1 parent 2e91611 commit 00cdd5f
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions Library/Homebrew/test/test_versions.rb
Original file line number Diff line number Diff line change
@@ -55,7 +55,11 @@ def test_comparing_regular_versions

def test_HEAD
assert_operator version("HEAD"), :>, version("1.2.3")
assert_operator version("HEAD-abcdef"), :>, version("1.2.3")
assert_operator version("1.2.3"), :<, version("HEAD")
assert_operator version("1.2.3"), :<, version("HEAD-fedcba")
assert_operator version("HEAD-abcdef"), :==, version("HEAD-fedcba")
assert_operator version("HEAD"), :==, version("HEAD-fedcba")
end

def test_comparing_alpha_versions
@@ -156,6 +160,12 @@ def test_no_version
assert_version_nil "foo"
end

def test_create
v = Version.create("1.20")
refute_predicate v, :head?
assert_equal "1.20", v.to_str
end

def test_version_all_dots
assert_version_detected "1.14", "http://example.com/foo.bar.la.1.14.zip"
end
@@ -441,3 +451,38 @@ def test_from_url
"http://github.com/foo/bar.git", {:tag => "v1.2.3"}
end
end

class HeadVersionTests < Homebrew::TestCase
def test_create_head
v1 = Version.create("HEAD-abcdef")
v2 = Version.create("HEAD")

assert_predicate v1, :head?
assert_predicate v2, :head?
end

def test_commit_assigned
v = HeadVersion.new("HEAD-abcdef")
assert_equal "abcdef", v.commit
assert_equal "HEAD-abcdef", v.to_str
end

def test_no_commit
v = HeadVersion.new("HEAD")
assert_nil v.commit
assert_equal "HEAD", v.to_str
end

def test_update_commit
v1 = HeadVersion.new("HEAD-abcdef")
v2 = HeadVersion.new("HEAD")

v1.update_commit("ffffff")
assert_equal "ffffff", v1.commit
assert_equal "HEAD-ffffff", v1.to_str

v2.update_commit("ffffff")
assert_equal "ffffff", v2.commit
assert_equal "HEAD-ffffff", v2.to_str
end
end
2 changes: 1 addition & 1 deletion Library/Homebrew/test/testing_env.rb
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@
module Homebrew
module VersionAssertions
def version(v)
Version.new(v)
Version.create(v)
end

def assert_version_equal(expected, actual)

0 comments on commit 00cdd5f

Please sign in to comment.