[pacman-dev] [PATCH] Remove unused strverscmp substitute
Our internal vercmp function was the only user of this, and it no longer relies on it. Signed-off-by: Dan McGee <dan@archlinux.org> --- configure.ac | 2 +- lib/libalpm/util.c | 102 ---------------------------------------------------- lib/libalpm/util.h | 3 -- 3 files changed, 1 insertions(+), 106 deletions(-) diff --git a/configure.ac b/configure.ac index b4b6a56..37fcab5 100644 --- a/configure.ac +++ b/configure.ac @@ -170,7 +170,7 @@ AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK AC_FUNC_MKTIME AC_TYPE_SIGNAL AC_CHECK_FUNCS([geteuid realpath regcomp strcasecmp \ - strndup strrchr strsep strverscmp swprintf \ + strndup strrchr strsep swprintf \ wcwidth uname]) # Enable large file support if available diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 9199545..c38dfb5 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -48,108 +48,6 @@ #include "alpm_list.h" #include "md5.h" -#ifndef HAVE_STRVERSCMP -/* GNU's strverscmp() function, taken from glibc 2.3.2 sources - */ - -/* Compare strings while treating digits characters numerically. - Copyright (C) 1997, 2002 Free Software Foundation, Inc. - Contributed by Jean-François Bignolles <bignolle@ecoledoc.ibp.fr>, 1997. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. -*/ - -/* states: S_N: normal, S_I: comparing integral part, S_F: comparing - fractionnal parts, S_Z: idem but with leading Zeroes only */ -#define S_N 0x0 -#define S_I 0x4 -#define S_F 0x8 -#define S_Z 0xC - -/* result_type: CMP: return diff; LEN: compare using len_diff/diff */ -#define CMP 2 -#define LEN 3 - -/* Compare S1 and S2 as strings holding indices/version numbers, - returning less than, equal to or greater than zero if S1 is less than, - equal to or greater than S2 (for more info, see the texinfo doc). -*/ - -int strverscmp (s1, s2) - const char *s1; - const char *s2; -{ - const unsigned char *p1 = (const unsigned char *) s1; - const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; - int state; - int diff; - - /* Symbol(s) 0 [1-9] others (padding) - Transition (10) 0 (01) d (00) x (11) - */ - static const unsigned int next_state[] = - { - /* state x d 0 - */ - /* S_N */ S_N, S_I, S_Z, S_N, - /* S_I */ S_N, S_I, S_I, S_I, - /* S_F */ S_N, S_F, S_F, S_F, - /* S_Z */ S_N, S_F, S_Z, S_Z - }; - - static const int result_type[] = - { - /* state x/x x/d x/0 x/- d/x d/d d/0 d/- - 0/x 0/d 0/0 0/- -/x -/d -/0 -/- */ - - /* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP, - CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, - /* S_I */ CMP, -1, -1, CMP, +1, LEN, LEN, CMP, - +1, LEN, LEN, CMP, CMP, CMP, CMP, CMP, - /* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP, - CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, - /* S_Z */ CMP, +1, +1, CMP, -1, CMP, CMP, CMP, - -1, CMP, CMP, CMP - }; - - if (p1 == p2) - return 0; - - c1 = *p1++; - c2 = *p2++; - /* Hint: '0' is a digit too. */ - state = S_N | ((c1 == '0') + (isdigit (c1) != 0)); - - while ((diff = c1 - c2) == 0 && c1 != '\0') - { - state = next_state[state]; - c1 = *p1++; - c2 = *p2++; - state |= (c1 == '0') + (isdigit (c1) != 0); - } - - state = result_type[state << 2 | (((c2 == '0') + (isdigit (c2) != 0)))]; - - switch (state) - { - case CMP: - return diff; - - case LEN: - while (isdigit (*p1++)) - if (!isdigit (*p2++)) - return 1; - - return isdigit (*p2) ? -1 : diff; - - default: - return state; - } -} -#endif - #ifndef HAVE_STRSEP /* This is a replacement for strsep which is not portable (missing on Solaris). * Copyright (c) 2001 by François Gouget <fgouget_at_codeweavers.com> */ diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 6c7a05e..a05a3e5 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -73,9 +73,6 @@ int _alpm_lstat(const char *path, struct stat *buf); int _alpm_test_md5sum(const char *filepath, const char *md5sum); char *_alpm_archive_fgets(char *line, size_t size, struct archive *a); -#ifndef HAVE_STRVERSCMP -int strverscmp(const char *, const char *); -#endif #ifndef HAVE_STRSEP char *strsep(char **, const char *); #endif -- 1.5.6.4
This will enable us to mark tests we know currently fail to differentiate them from those that we know should pass. Regressions should be easier to spot this way. Signed-off-by: Dan McGee <dan@archlinux.org> --- pactest/pmenv.py | 31 ++++++++++++++++++++++++++----- pactest/pmtest.py | 1 + pactest/tests/fileconflict001.py | 2 ++ pactest/tests/fileconflict002.py | 2 ++ pactest/tests/fileconflict004.py | 2 ++ pactest/tests/sync403.py | 2 ++ pactest/tests/trans001.py | 2 ++ pactest/tests/upgrade046.py | 2 ++ pactest/tests/upgrade051.py | 2 ++ 9 files changed, 41 insertions(+), 5 deletions(-) diff --git a/pactest/pmenv.py b/pactest/pmenv.py index f2327f9..b86abe9 100755 --- a/pactest/pmenv.py +++ b/pactest/pmenv.py @@ -86,13 +86,25 @@ class pmenv: """ passed = 0 tpassed = [] + failed = 0 tfailed = [] + expectedfail = 0 + texpectedfail = [] + unexpectedpass = 0 + tunexpectedpass = [] for test in self.testcases: fail = test.result["fail"] - if fail == 0: + if fail == 0 and not test.expectfailure: passed += 1 tpassed.append(test) + elif fail != 0 and test.expectfailure: + expectedfail += 1 + texpectedfail.append(test) + elif fail == 0: # and not test.expectfail + unexpectedpass += 1 + tunexpectedpass.append(test) else: + failed += 1 tfailed.append(test) def _printtest(t): @@ -114,17 +126,26 @@ class pmenv: print "=========="*8 print "Results" print "----------"*8 + print " Passed:" for test in tpassed: _printtest(test) print "----------"*8 + print " Expected Failures:" + for test in texpectedfail: _printtest(test) + print "----------"*8 + print " Unexpected Passes:" + for test in tunexpectedpass: _printtest(test) + print "----------"*8 + print " Failed:" for test in tfailed: _printtest(test) print "----------"*8 total = len(self.testcases) - failed = total - passed - print "TOTAL = %3u" % total + print "Total = %3u" % total if total: - print "PASS = %3u (%6.2f%%)" % (passed, float(passed) * 100 / total) - print "FAIL = %3u (%6.2f%%)" % (failed, float(failed) * 100 / total) + print "Pass = %3u (%6.2f%%)" % (passed, float(passed) * 100 / total) + print "Expected Fail = %3u (%6.2f%%)" % (expectedfail, float(expectedfail) * 100 / total) + print "Unexpected Pass = %3u (%6.2f%%)" % (unexpectedpass, float(unexpectedpass) * 100 / total) + print "Fail = %3u (%6.2f%%)" % (failed, float(failed) * 100 / total) print "" if __name__ == "__main__": diff --git a/pactest/pmtest.py b/pactest/pmtest.py index e8f6fa8..f31563b 100755 --- a/pactest/pmtest.py +++ b/pactest/pmtest.py @@ -90,6 +90,7 @@ class pmtest: # Test rules self.rules = [] self.files = [] + self.expectfailure = False if os.path.isfile(self.name): execfile(self.name) diff --git a/pactest/tests/fileconflict001.py b/pactest/tests/fileconflict001.py index 4c2069e..8c13911 100644 --- a/pactest/tests/fileconflict001.py +++ b/pactest/tests/fileconflict001.py @@ -18,3 +18,5 @@ self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") self.addrule("!PKG_EXIST=pkg2") + +self.expectfailure = True diff --git a/pactest/tests/fileconflict002.py b/pactest/tests/fileconflict002.py index c54f6da..f70873b 100644 --- a/pactest/tests/fileconflict002.py +++ b/pactest/tests/fileconflict002.py @@ -14,3 +14,5 @@ self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") self.addrule("!PKG_EXIST=pkg2") + +self.expectfailure = True diff --git a/pactest/tests/fileconflict004.py b/pactest/tests/fileconflict004.py index a5347cc..2396ced 100644 --- a/pactest/tests/fileconflict004.py +++ b/pactest/tests/fileconflict004.py @@ -17,3 +17,5 @@ self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") self.addrule("PKG_VERSION=pkg1|2.0-1") self.addrule("FILE_TYPE=test|link") + +self.expectfailure = True diff --git a/pactest/tests/sync403.py b/pactest/tests/sync403.py index b8d0101..d8ab763 100644 --- a/pactest/tests/sync403.py +++ b/pactest/tests/sync403.py @@ -19,3 +19,5 @@ self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") self.addrule("!PKG_EXIST=pkg2") self.addrule("PKG_EXIST=pkg3") + +self.expectfailure = True diff --git a/pactest/tests/trans001.py b/pactest/tests/trans001.py index b9889b1..b3d7883 100644 --- a/pactest/tests/trans001.py +++ b/pactest/tests/trans001.py @@ -18,3 +18,5 @@ self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") self.addrule("PKG_EXIST=pkg2") self.addrule("PKG_EXIST=pkg3") + +self.expectfailure = True diff --git a/pactest/tests/upgrade046.py b/pactest/tests/upgrade046.py index 60164b7..1239064 100644 --- a/pactest/tests/upgrade046.py +++ b/pactest/tests/upgrade046.py @@ -29,3 +29,5 @@ self.addrule("FILE_MODIFIED=bin/dummy") self.addrule("FILE_MODIFIED=bin/foobar") self.addrule("FILE_EXIST=usr/share/file") self.addrule("FILE_MODIFIED=usr/share/file") + +self.expectfailure = True diff --git a/pactest/tests/upgrade051.py b/pactest/tests/upgrade051.py index e8c69eb..4346c24 100644 --- a/pactest/tests/upgrade051.py +++ b/pactest/tests/upgrade051.py @@ -13,3 +13,5 @@ self.args = "-U %s" % p.filename() self.addrule("PACMAN_RETCODE=0") self.addrule("!PKG_EXIST=pkg1") self.addrule("PKG_EXIST=pkg2") + +self.expectfailure = True -- 1.5.6.4
This will allow the return code of pactest to be useful, for such things as use in a git-bisect test script. Signed-off-by: Dan McGee <dan@archlinux.org> --- pactest/pactest.py | 9 +++++++-- pactest/pmenv.py | 34 +++++++++++++++++----------------- pactest/pmtest.py | 6 +++--- pactest/util.py | 5 +---- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/pactest/pactest.py b/pactest/pactest.py index 7cda255..f95ef3c 100755 --- a/pactest/pactest.py +++ b/pactest/pactest.py @@ -93,13 +93,18 @@ if __name__ == "__main__": env.pacman["valgrind"] = opts.valgrind env.pacman["manual-confirm"] = opts.manualconfirm - if len(opts.testcases) == 0: + if opts.testcases is None or len(opts.testcases) == 0: print "no tests defined, nothing to do" + sys.exit(2) else: - for i in opts.testcases: env.addtest(i) + for i in opts.testcases: + env.addtest(i) # run tests and print overall results env.run() env.results() + if env.failed > 0: + sys.exit(1) + # vim: set ts=4 sw=4 et: diff --git a/pactest/pmenv.py b/pactest/pmenv.py index b86abe9..e9d0b4c 100755 --- a/pactest/pmenv.py +++ b/pactest/pmenv.py @@ -27,6 +27,12 @@ class pmenv: """Environment object """ + testcases = [] + passed = 0 + failed = 0 + expectedfail = 0 + unexpectedpass = 0 + def __init__(self, root = "root"): self.root = os.path.abspath(root) self.pacman = { @@ -36,7 +42,6 @@ class pmenv: "valgrind": 0, "nolog": 0 } - self.testcases = [] def __str__(self): return "root = %s\n" \ @@ -47,8 +52,7 @@ class pmenv: """ """ if not os.path.isfile(testcase): - err("file %s not found" % testcase) - return + raise IOError("test file %s not found" % testcase) test = pmtest.pmtest(testcase, self.root) self.testcases.append(test) @@ -84,27 +88,23 @@ class pmenv: def results(self): """ """ - passed = 0 tpassed = [] - failed = 0 tfailed = [] - expectedfail = 0 texpectedfail = [] - unexpectedpass = 0 tunexpectedpass = [] for test in self.testcases: fail = test.result["fail"] if fail == 0 and not test.expectfailure: - passed += 1 + self.passed += 1 tpassed.append(test) elif fail != 0 and test.expectfailure: - expectedfail += 1 + self.expectedfail += 1 texpectedfail.append(test) elif fail == 0: # and not test.expectfail - unexpectedpass += 1 + self.unexpectedpass += 1 tunexpectedpass.append(test) else: - failed += 1 + self.failed += 1 tfailed.append(test) def _printtest(t): @@ -142,13 +142,13 @@ class pmenv: total = len(self.testcases) print "Total = %3u" % total if total: - print "Pass = %3u (%6.2f%%)" % (passed, float(passed) * 100 / total) - print "Expected Fail = %3u (%6.2f%%)" % (expectedfail, float(expectedfail) * 100 / total) - print "Unexpected Pass = %3u (%6.2f%%)" % (unexpectedpass, float(unexpectedpass) * 100 / total) - print "Fail = %3u (%6.2f%%)" % (failed, float(failed) * 100 / total) + print "Pass = %3u (%6.2f%%)" % (self.passed, float(self.passed) * 100 / total) + print "Expected Fail = %3u (%6.2f%%)" % (self.expectedfail, float(self.expectedfail) * 100 / total) + print "Unexpected Pass = %3u (%6.2f%%)" % (self.unexpectedpass, float(self.unexpectedpass) * 100 / total) + print "Fail = %3u (%6.2f%%)" % (self.failed, float(self.failed) * 100 / total) print "" if __name__ == "__main__": - env = pmenv("/tmp") - print env + pass + # vim: set ts=4 sw=4 et: diff --git a/pactest/pmtest.py b/pactest/pmtest.py index f31563b..39f4dea 100755 --- a/pactest/pmtest.py +++ b/pactest/pmtest.py @@ -95,7 +95,7 @@ class pmtest: if os.path.isfile(self.name): execfile(self.name) else: - err("file %s does not exist!" % self.name) + raise IOerror("file %s does not exist!" % self.name) def generate(self): """ @@ -268,6 +268,6 @@ class pmtest: if __name__ == "__main__": - test = pmtest("test1", "./root") - print test + pass + # vim: set ts=4 sw=4 et: diff --git a/pactest/util.py b/pactest/util.py index c6d5a59..db9560f 100755 --- a/pactest/util.py +++ b/pactest/util.py @@ -43,10 +43,6 @@ LOGFILE = "var/log/pactest.log" verbose = 0 -def err(msg): - print "error: " + msg - sys.exit(1) - def vprint(msg): if verbose: print msg @@ -273,4 +269,5 @@ def mkdir(dir): if __name__ == "__main__": pass + # vim: set ts=4 sw=4 et: -- 1.5.6.4
On Fri, Jul 25, 2008 at 5:20 AM, Dan McGee <dan@archlinux.org> wrote:
This will enable us to mark tests we know currently fail to differentiate them from those that we know should pass. Regressions should be easier to spot this way.
Signed-off-by: Dan McGee <dan@archlinux.org>
This is great, and the other pactest patch too. Nice job, and thanks for completing this stuff.
On Fri, Jul 25, 2008 at 5:20 AM, Dan McGee <dan@archlinux.org> wrote:
Our internal vercmp function was the only user of this, and it no longer relies on it.
Well this patch was pretty straightforward, but nice catch :)
participants (2)
-
Dan McGee
-
Xavier