1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#!/bin/bash
set -pu
# Mock the "rpm" command
# mocked package: coconut-4.5.17
# The mock is used to avoid the need to have a specific RPM package in a
# specific version installed on the system where this test is run.
function rpm()
{
if [[ "$*" == "--quiet -q coconut" ]] ; then
return 0
elif [[ "$*" == "-q --queryformat %{VERSION} coconut" ]] ; then
echo "4.5.17"
return 0
elif [[ "$*" == "-q --queryformat %{EPOCH} coconut" ]] ; then
echo "(none)"
return 0
else
echo "BATS mock for rpm doesn't support this command"
return 1
fi
}
export -f rpm
@test "bash_pkg_conditional_rpm - test package presence" {
{{{ bash_pkg_conditional_rpm("coconut") | indent(4) }}}
}
@test "bash_pkg_conditional_rpm - test package version" {
{{{ bash_pkg_conditional_rpm("coconut", "<", "0:5") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", "<", "0:5.0") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", "<=", "0:5") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", "<=", "0:5.0") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", "<", "0:4.5.18") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", "<=", "0:4.5.17") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", "<=", "0:4.5.18") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", ">", "0:4.5.16") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", ">", "0:4.1.1") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", ">=", "0:4.5.16") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", ">=", "0:4.1.1") | indent(4) }}}
! ( {{{ bash_pkg_conditional_rpm("coconut", "!=", "0:4.5.17") | indent(4) }}} )
! ( {{{ bash_pkg_conditional_rpm("coconut", "==", "0:4.5.18") | indent(4) }}} )
{{{ bash_pkg_conditional_rpm("coconut", ">", "0:3") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", ">", "0:3.0") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", ">", "0:3.0.0") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", ">", "0:3") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", ">=", "0:3.0") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", ">=", "0:3.0.0") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", "<", "1:1.0") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", "<", "1:5.0.4") | indent(4) }}}
{{{ bash_pkg_conditional_rpm("coconut", "!=", "1:4.5.17") | indent(4) }}}
! ( {{{ bash_pkg_conditional_rpm("coconut", "==", "1:4.5.17") | indent(4) }}} )
! ( {{{ bash_pkg_conditional_rpm("coconut", ">", "1:4.5") | indent(4) }}} )
! ( {{{ bash_pkg_conditional_rpm("coconut", ">", "1:6.7") | indent(4) }}} )
}
@test "bash_compare_version - test basic version comparison algorithm" {
{{{ bash_compare_version("0:0.1.2", "<", "0:1.2") }}}
{{{ bash_compare_version("0:2.3", ">", "0:0.2.3") }}}
{{{ bash_compare_version("1:2.3", ">", "0:3.2") }}}
# Undefined behavior - only one epoch specified doesn't produce reasonable results
# Kept here for reference, if the behavior is fixed, remove the negation.
! {{{ bash_compare_version("1:2.3", ">", "3.2") }}}
! {{{ bash_compare_version("0:3.2", "==", "3.2") }}}
{{{ bash_compare_version("1:22.3", ">", "1:3.2") }}}
{{{ bash_compare_version("1:2.3", "<", "1:3.2") }}}
{{{ bash_compare_version("0:2.3", "<", "1:1.0") }}}
{{{ bash_compare_version("1.0", "==", "1.0") }}}
{{{ bash_compare_version("0:1.0", "!=", "1:1.0") }}}
! ({{{ bash_compare_version("0:1.0", "==", "1:1.0") }}} )
{{{ bash_compare_version("2:17.15.4.5", "<", "2:17.15.4.6") }}}
{{{ bash_compare_version("2:17.15.4.5", "<=", "2:17.15.4.6") }}}
{{{ bash_compare_version("2:17.15.4.9", ">", "2:17.15.4.7") }}}
{{{ bash_compare_version("2:17.15.4.9", ">=", "2:17.15.4.7") }}}
}
|