Testing Debian version number comparisons
The Debian Policy Manual specifies how Debian version numbers are
The specification is reasonably straightforward on the surface, but
there are a lot of details that need to be exactly right. The canonical
implementation of this comparision is
dpkg --compare-versions, but
it has been implemented in other places as well, for various reasons.
It strikes me that it would be cool to have a set of test cases that could be used to verify that all implementations of version number comparisons work the same way. I envision a file like this:
1 eq 1 1 lt 2 10 gt 2 1.1 lt 2 1 gt 0 1 eq 0:1 2 lt 1:0 1 lt 1-0
(For simplicity, let's assume the only relations are eq, lt, and gt.) An implementation of the version number comparison algorithm could use such a data set in its test suite.
A quick and dirty implementation for dpkg might look like this:
#!/bin/sh set -e error=0 grep -vE '^:space:*(#.*)?$' "$@" | while read v1 relation v2 do if ! dpkg --compare-versions "$v1" "$relation" "$v2" then echo "Error: $v1 $relation $v2" 1>&2 error=1 fi done exit "$error"
I don't have time to think through all cases and construct a comprehensive set of test cases, but I think someone should do that.