summaryrefslogtreecommitdiff
path: root/tests/test-moz-version
diff options
context:
space:
mode:
authorBenjamin Drung <bdrung@ubuntu.com>2010-01-08 22:49:52 +0100
committerBenjamin Drung <bdrung@ubuntu.com>2010-01-08 22:49:52 +0100
commit6f552eb2940efa5fc4ccc6afe924bbb1fd110daf (patch)
tree7e464e73ebc560218d77d583446b7337f74139ce /tests/test-moz-version
parent6e3c4da4f384bfbb95e5fd74512ae1ce74dbcf24 (diff)
- Add a test suite for testing moz-version --compare
- add tests/test-moz-version - update debian/rules - update src/Makefile
Diffstat (limited to 'tests/test-moz-version')
-rwxr-xr-xtests/test-moz-version97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/test-moz-version b/tests/test-moz-version
new file mode 100755
index 0000000..7707b71
--- /dev/null
+++ b/tests/test-moz-version
@@ -0,0 +1,97 @@
+#!/usr/bin/python
+
+# Copyright (c) 2010 Benjamin Drung <bdrung@ubuntu.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+import getopt
+import os
+import sys
+
+sys.path.insert(1, os.path.abspath(os.path.dirname(sys.argv[0]) + "/../src"))
+from moz_version import *
+
+# error codes
+COMMAND_LINE_SYNTAX_ERROR = 1
+TEST_FAILED_ERROR = 2
+
+test_pattern = (("1.-1", "lt", "1", True),
+ ("1", "eq", "1.", True),
+ ("1", "eq", "1.0", True),
+ ("1", "eq", "1.0.0", True),
+ ("1.0.0", "lt", "1.1a", True),
+ ("1.1a", "lt", "1.1aa", True),
+ ("1.1aa", "lt", "1.1ab", True),
+ ("1.1ab", "lt", "1.1b", True),
+ ("1.1b", "lt", "1.1c", True),
+ ("1.1pre", "eq", "1.1pre0", True),
+ ("1.1pre0", "eq", "1.0+", True),
+ ("1.0+", "lt", "1.1pre1a", True),
+ ("1.1pre1a", "lt", "1.1pre1aa", True),
+ ("1.1pre1aa", "lt", "1.1pre1b", True),
+ ("1.1pre1b", "lt", "1.1pre1", True),
+ ("1.1pre1", "lt", "1.1pre2", True),
+ ("1.1pre2", "lt", "1.1pre10", True),
+ ("1.1pre10", "lt", "1.1.-1", True),
+ ("1.1.-1", "lt", "1.1", True),
+ ("1.1", "eq", "1.1.0", True),
+ ("1.1.0", "eq", "1.1.00", True),
+ ("1.1.00", "lt", "1.10", True),
+ ("1.10", "lt", "1.*", True),
+ ("1.*", "lt", "1.*.1", True),
+ ("1.*.1", "lt", "2.0", True),
+ ("1.*.1", "gt", "2.0", False),
+ )
+
+def fail(message):
+ print >> sys.stderr, "E: " + message
+ sys.exit(TEST_FAILED_ERROR)
+
+def test_compare(verbose=False):
+ for pattern in test_pattern:
+ if pattern[1] == "lt":
+ if (compare_versions(pattern[0], pattern[2], verbose) < 0) != pattern[3]:
+ fail('Test pattern "%s %s %s" failed (result should be %s).' % pattern)
+ elif pattern[1] == "eq":
+ if (compare_versions(pattern[0], pattern[2], verbose) == 0) != pattern[3]:
+ fail('Test pattern "%s %s %s" failed (result should be %s).' % pattern)
+ elif pattern[1] == "gt":
+ if (compare_versions(pattern[0], pattern[2], verbose) > 0) != pattern[3]:
+ fail('Test pattern "%s %s %s" failed (result should be %s).' % pattern)
+ else:
+ fail('Unknown pattern %s.' % (pattern[1]))
+
+if __name__ == "__main__":
+ try:
+ long_opts = ["verbose"]
+ opts, args = getopt.gnu_getopt(sys.argv[1:], "v", long_opts)
+ except getopt.GetoptError, e:
+ # print help information and exit:
+ print >> sys.stderr, str(e) # will print something like "option -a not recognized"
+ sys.exit(COMMAND_LINE_SYNTAX_ERROR)
+
+ verbose = False
+
+ for o, a in opts:
+ if o in ("-v", "--verbose"):
+ verbose = True
+ else:
+ assert False, "unhandled option"
+
+ test_compare(verbose)