1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

Fix versioncmp regression after update

Commit 8428367285 introduced the regression,
and a previous commit introduced the vercmptest.sh test script to track down
these issues. This commit solves the problem by removing the previous
attempt at locating the pkgrel portions and replacing it with something that
performs the correct logic.

While tracking down everything I needed to, I also found a mistake in one of
the pactests which is fixed here as well as increased the functionality and
verbosity of the vercmptest script to both print out each test it is running
as well as automatically run the mirror of each test case.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2008-05-29 23:12:44 -05:00
parent 2cd0a87b3f
commit 54e1e3e642
3 changed files with 59 additions and 18 deletions

View File

@ -566,8 +566,6 @@ alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(pmpkg_t *pkg)
return(reqs); return(reqs);
} }
/** @} */
/** Compare two version strings and determine which one is 'newer'. /** Compare two version strings and determine which one is 'newer'.
* Returns a value comparable to the way strcmp works. Returns 1 * Returns a value comparable to the way strcmp works. Returns 1
* if a is newer than b, 0 if a and b are the same version, or -1 * if a is newer than b, 0 if a and b are the same version, or -1
@ -577,6 +575,12 @@ alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(pmpkg_t *pkg)
* at lib/rpmvercmp.c, and was most recently updated against rpm * at lib/rpmvercmp.c, and was most recently updated against rpm
* version 4.4.2.3. Small modifications have been made to make it more * version 4.4.2.3. Small modifications have been made to make it more
* consistent with the libalpm coding style. * consistent with the libalpm coding style.
*
* Keep in mind that the pkgrel is only compared if it is available
* on both versions handed to this function. For example, comparing
* 1.5-1 and 1.5 will yield 0; comparing 1.5-1 and 1.5-2 will yield
* -1 as expected. This is mainly for supporting versioned dependencies
* that do not include the pkgrel.
*/ */
int SYMEXPORT alpm_pkg_vercmp(const char *a, const char *b) int SYMEXPORT alpm_pkg_vercmp(const char *a, const char *b)
{ {
@ -688,6 +692,26 @@ int SYMEXPORT alpm_pkg_vercmp(const char *a, const char *b)
one = ptr1; one = ptr1;
*ptr2 = oldch2; *ptr2 = oldch2;
two = ptr2; two = ptr2;
/* libalpm added code. check if version strings have hit the pkgrel
* portion. depending on which strings have hit, take correct action.
* this is all based on the premise that we only have one dash in
* the version string, and it separates pkgver from pkgrel. */
if(*ptr1 == '-' && *ptr2 == '-') {
/* no-op, continue comparing since we are equivalent throughout */
} else if(*ptr1 == '-') {
/* ptr1 has hit the pkgrel and ptr2 has not.
* version 2 is newer iff we are not at the end of ptr2;
* if we are at end then one version had pkgrel and one did not */
ret = *ptr2 ? -1 : 0;
goto cleanup;
} else if(*ptr2 == '-') {
/* ptr2 has hit the pkgrel and ptr1 has not.
* version 1 is newer iff we are not at the end of ptr1;
* if we are at end then one version had pkgrel and one did not */
ret = *ptr1 ? 1 : 0;
goto cleanup;
}
} }
/* this catches the case where all numeric and alpha segments have */ /* this catches the case where all numeric and alpha segments have */
@ -698,13 +722,6 @@ int SYMEXPORT alpm_pkg_vercmp(const char *a, const char *b)
goto cleanup; goto cleanup;
} }
/* libalpm added code. one version string may have a pkgrel number, the
* other may not. unless both have them, we ignore it and return 0. */
if( (*one && *one == '-') || (*two && *two == '-') ) {
ret = 0;
goto cleanup;
}
/* whichever version still has characters left over wins */ /* whichever version still has characters left over wins */
if (!*one) { if (!*one) {
ret = -1; ret = -1;
@ -718,6 +735,7 @@ cleanup:
return(ret); return(ret);
} }
/** @} */
pmpkg_t *_alpm_pkg_new(void) pmpkg_t *_alpm_pkg_new(void)
{ {

View File

@ -14,4 +14,4 @@ self.addpkg(p)
self.args = "-U %s" % p.filename() self.args = "-U %s" % p.filename()
self.addrule("PACMAN_RETCODE=1") self.addrule("PACMAN_RETCODE=1")
self.addrule("!PKG_VERSION=pkg2|1.1") self.addrule("!PKG_VERSION=pkg2|1.1-1")

View File

@ -19,22 +19,43 @@
# default binary if one was not specified as $1 # default binary if one was not specified as $1
bin='vercmp' bin='vercmp'
# holds count of failed tests # holds counts of tests
total=0
failure=0 failure=0
# args:
# pass ver1 ver2 ret expected
pass() {
echo "test: ver1: $1 ver2: $2 ret: $3 expected: $4"
echo " --> pass"
}
# args: # args:
# fail ver1 ver2 ret expected # fail ver1 ver2 ret expected
fail() { fail() {
echo "unexpected failure:" echo "test: ver1: $1 ver2: $2 ret: $3 expected: $4"
echo " ver1: $1 ver2: $2 ret: $3 expected: $4" echo " ==> FAILURE"
failure=$(expr $failure + 1) failure=$(expr $failure + 1)
} }
# args: # args:
# runtest ver1 ver2 expected # runtest ver1 ver2 expected
runtest() { runtest() {
# run the test
ret=$($bin $1 $2) ret=$($bin $1 $2)
[ $ret -eq $3 ] || fail $1 $2 $ret $3 func='pass'
[ $ret -eq $3 ] || func='fail'
$func $1 $2 $ret $3
total=$(expr $total + 1)
# and run its mirror case just to be sure
reverse=0
[ $3 -eq 1 ] && reverse=-1
[ $3 -eq -1 ] && reverse=1
ret=$($bin $2 $1)
func='pass'
[ $ret -eq $reverse ] || func='fail'
$func $1 $2 $ret $reverse
total=$(expr $total + 1)
} }
# use first arg as our binary if specified # use first arg as our binary if specified
@ -44,11 +65,9 @@ runtest() {
# all similar length, no pkgrel # all similar length, no pkgrel
runtest 1.5.0 1.5.0 0 runtest 1.5.0 1.5.0 0
runtest 1.5.0 1.5.1 -1
runtest 1.5.1 1.5.0 1 runtest 1.5.1 1.5.0 1
# mixed length # mixed length
runtest 1.5 1.5.1 -1
runtest 1.5.1 1.5 1 runtest 1.5.1 1.5 1
# with pkgrel, simple # with pkgrel, simple
@ -65,13 +84,17 @@ runtest 1.5-2 1.5.1-2 -1
# mixed pkgrel inclusion # mixed pkgrel inclusion
runtest 1.5 1.5-1 0 runtest 1.5 1.5-1 0
runtest 1.5-1 1.5 0 runtest 1.5-1 1.5 0
runtest 1.1-1 1.1 0
runtest 1.0-1 1.1 -1
runtest 1.1-1 1.0 1
#END TESTS #END TESTS
echo
if [ $failure -eq 0 ]; then if [ $failure -eq 0 ]; then
echo "All tests successful" echo "All $total tests successful"
exit 0 exit 0
fi fi
echo "$failure failed tests" echo "$failure of $total tests failed"
exit 1 exit 1