diff options
-rw-r--r-- | debian/changelog | 6 | ||||
-rwxr-xr-x | debian/rules | 2 | ||||
-rw-r--r-- | src/Makefile | 5 | ||||
-rwxr-xr-x | tests/test-moz-version | 97 |
4 files changed, 107 insertions, 3 deletions
diff --git a/debian/changelog b/debian/changelog index 55f2214..8b0c650 100644 --- a/debian/changelog +++ b/debian/changelog @@ -68,6 +68,10 @@ mozilla-devscripts (0.19) UNRELEASED; urgency=low - update man/moz-version.1 - update src/moz_version.py - update src/moz-version + - Add a test suite for testing moz-version --compare + - add tests/test-moz-version + - update debian/rules + - update src/Makefile * packaging: - add homepage field - update debian/control @@ -80,7 +84,7 @@ mozilla-devscripts (0.19) UNRELEASED; urgency=low - update src/dh_xul-ext - update debian/control - -- Benjamin Drung <bdrung@ubuntu.com> Fri, 08 Jan 2010 19:04:37 +0100 + -- Benjamin Drung <bdrung@ubuntu.com> Fri, 08 Jan 2010 22:49:03 +0100 mozilla-devscripts (0.18) unstable; urgency=low diff --git a/debian/rules b/debian/rules index c1d6454..8285ed4 100755 --- a/debian/rules +++ b/debian/rules @@ -29,7 +29,7 @@ include /usr/share/cdbs/1/class/makefile.mk DEB_SRCDIR := $(CURDIR)/src DEB_MAKE_BUILD_TARGET := build DEB_MAKE_INSTALL_TARGET := install DESTDIR=$(CURDIR)/debian/mozilla-devscripts/ -DEB_MAKE_CHECK_TARGET := $(NULL) +DEB_MAKE_CHECK_TARGET := test DEB_INSTALL_DOCS_ALL := README diff --git a/src/Makefile b/src/Makefile index aa12a73..f802774 100644 --- a/src/Makefile +++ b/src/Makefile @@ -79,6 +79,9 @@ extra_dirs = \ build: $(subst_files) +test: + ../tests/test-moz-version + install: $(subst_files) $(extra_files) $(foreach dir,$(extra_dirs),$(wildcard $(dir)/*)) install -m 755 -d $(DESTDIR)$(DATADIR) $(foreach dir,$(extra_dirs),$(DESTDIR)$(DATADIR)/$(dir)) install -m 644 $(subst_files) $(extra_files) $(DESTDIR)$(DATADIR) @@ -101,4 +104,4 @@ install: $(subst_files) $(extra_files) $(foreach dir,$(extra_dirs),$(wildcard $( clean: rm -f $(subst_files) -.PHONY: clean install +.PHONY: clean install test 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) |