[asterisk-commits] mnicholson: testsuite/asterisk/trunk r779 - in /asterisk/trunk/asttest: lib/l...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 26 10:57:47 CDT 2010


Author: mnicholson
Date: Thu Aug 26 10:57:43 2010
New Revision: 779

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=779
Log:
Enhance version parsing and comparison.  SVN versions can now be compared with non svn versions and are also handled more intelligently.

Modified:
    asterisk/trunk/asttest/lib/lua/astlib.lua
    asterisk/trunk/asttest/self-tests/asterisk_version/test.lua

Modified: asterisk/trunk/asttest/lib/lua/astlib.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/lib/lua/astlib.lua?view=diff&rev=779&r1=778&r2=779
==============================================================================
--- asterisk/trunk/asttest/lib/lua/astlib.lua (original)
+++ asterisk/trunk/asttest/lib/lua/astlib.lua Thu Aug 26 10:57:43 2010
@@ -58,17 +58,7 @@
 	local v1 = version(v)
 	local v2 = version()
 
-	if v1.svn and v2.svn and v1.branch == v2.branch then return true end
-	if v2.svn then
-		v1 = version("SVN-branch-" .. v .. "-r00000")
-		if v1.branch == v2.branch then return true end
-	end
-	if not v2.svn and not v1.svn and v1.concept == v2.concept and v1.major == v2.major then
-		if not v1.minor then return true end
-		if v1.minor == v2.minor then return true end
-	end
-
-	return false
+	return v1.branch == v2.branch
 end
 
 -- asterisk table is created in astlib.c
@@ -362,6 +352,31 @@
 		if not self.branch then
 			self.branch, self.revision = self.version:match("SVN%-(.*)%-r(%d+M?)")
 		end
+
+		if not self.branch then
+			error("error parsing SVN version number: " .. self.version)
+		end
+
+		-- generate a synthetic version number for svn branch versions
+		self.patch = self.revision:match("(%d+)M?")
+		self.concept, self.major, self.minor = self.branch:match("branch%-(%d+).(%d+).(%d+)")
+		if not self.concept then
+			self.minor = "999" -- assume the SVN branch is newer than all released versions
+			self.concept, self.major = self.branch:match("branch%-(%d+).(%d+)")
+		end
+		if not self.concept then
+			if self.branch == "trunk" then
+				self.concept = "999"
+				self.major = "0"
+				self.minor = "0"
+			else
+				-- branch names that don't match are greater
+				-- than everything except trunk
+				self.concept = "998"
+				self.major = "0"
+				self.minor = "0"
+			end
+		end
 	else
 		self.concept, self.major, self.minor, self.patch = self.version:match("(%d+).(%d+).(%d+).(%d+)")
 		if not self.concept then
@@ -370,6 +385,19 @@
 		if not self.concept then
 			self.concept, self.major, self.minor = self.version:match("(%d+).(%d+)")
 		end
+
+		if not self.concept then
+			error("error parsing version number: " .. self.version)
+		end
+
+		-- generate synthetic svn information
+		self.branch = "branch-" .. self.concept .. "." .. self.major
+
+		-- special handling for 1.6 branches
+		if self.concept == "1" and self.major == "6"  and self.minor ~= nil then
+			self.branch = self.branch .. "." .. self.minor
+		end
+		self.revision = "00000"
 	end
 end
 
@@ -378,31 +406,25 @@
 end
 
 function asterisk_version:__lt(other)
-	if self.svn and other.svn then
-		-- for svn versions, just compare revisions
-		local v1 = tonumber(self.revision:match("(%d)M?"))
-		local v2 = tonumber(other.revision:match("(%d)M?"))
-		return v1 < v2
-	elseif not self.svn and not other.svn then
-		-- compare each component of othe version number starting with
-		-- the most significant
-		local v = {
-			{tonumber(self.concept), tonumber(other.concept)},
-			{tonumber(self.major), tonumber(other.major)},
-			{tonumber(self.minor or 0), tonumber(other.minor or 0)},
-			{tonumber(self.patch or 0), tonumber(other.patch or 0)},
-		}
-
-		for _, i in ipairs(v) do
-			if i[1] < i[2] then
-				return true
-			elseif i[1] ~= i[2] then
-				return false
-			end
-		end
-		return false
-	end
-	error("cannot compare svn version number with non svn version number")
+	-- compare each component of othe version number starting with the most
+	-- significant.  Synthetic version numbers are generated for SVN
+	-- versions.
+	
+	local v = {
+		{tonumber(self.concept), tonumber(other.concept)},
+		{tonumber(self.major), tonumber(other.major)},
+		{tonumber(self.minor or 0), tonumber(other.minor or 0)},
+		{tonumber(self.patch or 0), tonumber(other.patch or 0)},
+	}
+
+	for _, i in ipairs(v) do
+		if i[1] < i[2] then
+			return true
+		elseif i[1] ~= i[2] then
+			return false
+		end
+	end
+	return false
 end
 
 function asterisk_version:__eq(other)

Modified: asterisk/trunk/asttest/self-tests/asterisk_version/test.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/self-tests/asterisk_version/test.lua?view=diff&rev=779&r1=778&r2=779
==============================================================================
--- asterisk/trunk/asttest/self-tests/asterisk_version/test.lua (original)
+++ asterisk/trunk/asttest/self-tests/asterisk_version/test.lua Thu Aug 26 10:57:43 2010
@@ -4,6 +4,17 @@
 	print("testing " .. version)
 	local v = ast.version(version)
 	fail_if(v.svn, version .. " was detected as an svn version")
+	fail_if(tostring(v) ~= version, string.format("tostring(v) for %s ~= %s", version, version))
+	fail_if(v.concept ~= concept, string.format("v.concept ~= concept (%s ~= %s)", v.concept or "nil", concept or "nil"))
+	fail_if(v.major ~= major, string.format("v.major ~= major (%s ~= %s)", v.major or "nil", major or "nil"))
+	fail_if(v.minor ~= minor, string.format("v.minor ~= minor (%s ~= %s)", v.minor or "nil", minor or "nil"))
+	fail_if(v.patch ~= patch, string.format("v.patch ~= patch (%s ~= %s)", v.patch or "nil", patch or "nil"))
+end
+
+function synthetic_version(version, concept, major, minor, patch)
+	print("testing synthetic " .. version)
+	local v = ast.version(version)
+	fail_if(not v.svn, version .. " was NOT detected as an svn version")
 	fail_if(tostring(v) ~= version, string.format("tostring(v) for %s ~= %s", version, version))
 	fail_if(v.concept ~= concept, string.format("v.concept ~= concept (%s ~= %s)", v.concept or "nil", concept or "nil"))
 	fail_if(v.major ~= major, string.format("v.major ~= major (%s ~= %s)", v.major or "nil", major or "nil"))
@@ -19,6 +30,15 @@
 	fail_if(v.branch ~= branch, string.format("v.branch ~= branch (%s ~= %s)", v.branch or "nil", branch or "nil"))
 	fail_if(v.revision ~= revision, string.format("v.revision ~= revision (%s ~= %s)", v.revision or "nil", revision or "nil"))
 	fail_if(v.parent ~= parent, string.format("v.parent ~= parent (%s ~= %s)", v.parent or "nil", parent or "nil"))
+end
+
+function synthetic_svn_version(version, branch, revision)
+	print("testing synthetic svn " .. version)
+	local v = ast.version(version)
+	fail_if(v.svn, version .. " was detected as an svn version")
+	fail_if(tostring(v) ~= version, string.format("tostring(v) for %s ~= %s", version, version))
+	fail_if(v.branch ~= branch, string.format("v.branch ~= branch (%s ~= %s)", v.branch or "nil", branch or "nil"))
+	fail_if(v.revision ~= revision, string.format("v.revision ~= revision (%s ~= %s)", v.revision or "nil", revision or "nil"))
 end
 
 function major_version(v1, v2)
@@ -48,10 +68,19 @@
 normal_version("1.4.30", "1", "4", "30")
 normal_version("1.4.30.1", "1", "4", "30", "1")
 normal_version("1.4", "1", "4")
+synthetic_svn_version("1.4.30", "branch-1.4", "00000")
+synthetic_svn_version("1.4.30.1", "branch-1.4", "00000")
+synthetic_svn_version("1.4", "branch-1.4", "00000")
+
 svn_version("SVN-trunk-r252849", "trunk", "252849")
 svn_version("SVN-branch-1.6.2-r245581M", "branch-1.6.2", "245581M")
 svn_version("SVN-russell-cdr-q-r249059M-/trunk", "russell-cdr-q", "249059M", "/trunk")
 svn_version("SVN-russell-rest-r1234", "russell-rest", "1234")
+synthetic_version("SVN-trunk-r252849", "999", "0", "0", "252849")
+synthetic_version("SVN-branch-1.6.2-r245581M", "1", "6", "2", "245581")
+synthetic_version("SVN-russell-cdr-q-r249059M-/trunk", "998", "0", "0", "249059")
+synthetic_version("SVN-russell-rest-r1234", "998", "0", "0", "1234")
+synthetic_version("SVN-branch-1.4-r1234", "1", "4", "999", "1234")
 
 major_version("1.4", "1.4.30")
 major_version("1.4", "1.4.30.1")
@@ -64,7 +93,9 @@
 not_major_version("1.4", "1.8")
 not_major_version("1.6", "SVN-trunk-r224353")
 not_major_version("1.6.1", "1.6.2")
+not_major_version("trunk", "1.6.2")
 
+print("testing comparisons")
 fail_if(ast.version("1.6") > ast.version("1.6.2"), "1.6 > 1.6.2 failed")
 fail_if(ast.version("1.6.2") < ast.version("1.6.2"), "1.6.2 < 1.6.2 failed")
 fail_if(ast.version("1.6.2") ~= ast.version("1.6.2"), "1.6.2 ~= 1.6.2 failed")
@@ -72,8 +103,15 @@
 fail_if(not (ast.version("1.4") < ast.version("1.6.2")), "1.4 < 1.6.2 failed")
 fail_if(not (ast.version("1.4") < ast.version("1.4.2")), "1.4 < 1.4.2 failed")
 fail_if(not (ast.version("1.4.30") < ast.version("1.6")), "1.4.30 < 1.6 failed")
+fail_if(not (ast.version("1.4.30") < ast.version("SVN-branch-1.6.2-r224353")), "1.4.30 < SVN-branch-1.6.2-r224353 failed")
+fail_if(not (ast.version("1.4.30") < ast.version("SVN-branch-1.4-r224353")), "1.4.30 < SVN-branch-1.4-r224353 failed")
+fail_if(not (ast.version("SVN-branch-1.6.2-r224353") == ast.version("SVN-branch-1.6.2-r224353")), "SVN-branch-1.6.2-r224353 == SVN-branch-1.6.2-r224353 failed")
+fail_if(not (ast.version("SVN-branch-1.6.2-r224352") < ast.version("SVN-branch-1.6.2-r224353")), "SVN-branch-1.6.2-r224352 < SVN-branch-1.6.2-r224353 failed")
+fail_if(not (ast.version("SVN-trunk-r1234") > ast.version("SVN-branch-1.6.2-r224353")), "SVN-trunk-r1234 < SVN-branch-1.6.2-r224353 failed")
+fail_if(not (ast.version("1.4.30") < ast.version("SVN-branch-1.6.2-r224353")), "1.4.30 < SVN-branch-1.6.2-r224353 failed")
+fail_if(not (ast.version("1.4.30") < ast.version("SVN-branch-1.6.2-r224353")), "1.4.30 < SVN-branch-1.6.2-r224353 failed")
 
 if ast.exists() then
-	print(ast.version())
+	print("automatically detected version " .. tostring(ast.version()))
 end
 




More information about the asterisk-commits mailing list