| git.druid.rocks | index | druid520 | mp | test/ | suites/ | patches.sh |
test/suites/patches.sh
# suite: patches/patches.conf -- per-patch IF_DEP/IF_VER conditions and
# AFTER ordering, layered on top of the plain unconditional patch list.
# IF_DEP (both %-sigil and bare forms), IF_VER, AFTER ordering (including
# an AFTER edge to a filtered-out patch, which must be silently ignored),
# and a real AFTER cycle failing loudly instead of hanging or silently
# dropping patches.
test_patches_conf() {
t_begin "patches_conf"
reset_state
mkdir -p "$SCRATCH/rt10test/patches"
mkport rt10test <<'EOF'
pkg_name="rt10test"
pkg_ver="2.5"
pkg_deps="rt10dep"
fetch:
mkdir -p rt10test
install:
touch $MP_PREFIX/rt10test-installed
remove:
rm -f $MP_PREFIX/rt10test-installed
EOF
mkport rt10dep <<'EOF'
pkg_name="rt10dep"
pkg_ver="1.0"
install:
touch $MP_PREFIX/rt10dep-installed
remove:
rm -f $MP_PREFIX/rt10dep-installed
EOF
for p in 001-base 002-needs-dep 003-old-ver-only 004-runs-last; do
printf -- '--- a/dummy\n+++ b/dummy\n@@ -0,0 +1 @@\n+%s\n' "$p" > "$SCRATCH/rt10test/patches/$p.patch"
done
cat > "$SCRATCH/rt10test/patches/patches.conf" <<'EOF'
002-needs-dep.patch:
IF_DEP=rt10dep
003-old-ver-only.patch:
IF_VER=<2.0
004-runs-last.patch:
AFTER=002-needs-dep.patch 001-base.patch
EOF
out=$(mp install rt10test 2>&1)
rc=$?
assert_exit0 "$rc" "$CUR_TEST" || return
assert_file_exists "$MP_PREFIX/rt10test-installed" "$CUR_TEST" || return
# a real AFTER cycle must fail loudly, not hang or silently drop patches.
cat > "$SCRATCH/rt10test/patches/patches.conf" <<'EOF'
001-base.patch:
AFTER=002-needs-dep.patch
002-needs-dep.patch:
AFTER=001-base.patch
EOF
out=$(cd /root/mpbuildtest && perl -I. -Implib -e '
use mplib::config qw($CFG load);
use mplib::resolve qw(init find_portdir apply_patch_manifest);
use mplib::portformat qw(resolve_port resolve_slot apply_use_patches);
load({ FORCE=>0, NODEPS=>0, UNMASK=>0, DRYRUN=>0, CLIOVERLAY=>[] });
init();
my $dir = find_portdir("rt10test");
my $pc = resolve_port($dir);
apply_use_patches($pc, $pc->{pkg_name});
apply_patch_manifest($pc, $pc->{pkg_name});
' 2>&1)
assert_contains "$out" "AFTER cycle" "$CUR_TEST" || return
t_pass
}
# use-<flag>/nouse-<flag> patch directories: with ssl enabled, exactly
# the use-ssl/ patches apply and the nouse-ssl/ ones do not.
test_use_flag_patch_dirs() {
t_begin "use_flag_patch_dirs"
reset_state
printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
mkdir -p "$SCRATCH/rt31test/patches/use-ssl" "$SCRATCH/rt31test/patches/nouse-ssl"
mkport rt31test <<'EOF'
pkg_name="rt31test"
pkg_ver="1.0"
pkg_use="ssl"
fetch:
mkdir -p rt31test
install:
touch $MP_PREFIX/rt31test-installed
remove:
rm -f $MP_PREFIX/rt31test-installed
EOF
printf -- '--- a/dummy\n+++ b/dummy\n@@ -0,0 +1 @@\n+use-ssl-applied\n' > "$SCRATCH/rt31test/patches/use-ssl/001.patch"
printf -- '--- a/dummy\n+++ b/dummy\n@@ -0,0 +1 @@\n+nouse-ssl-applied\n' > "$SCRATCH/rt31test/patches/nouse-ssl/002.patch"
cat >> "$CONF" <<'EOF'
rt31test:
USE=ssl
EOF
mp install rt31test >/tmp/rt31.out 2>&1
rc=$?
assert_exit0 "$rc" "$CUR_TEST" || return
dummy=$(cat "$WD/rt31test/rt31test/dummy" 2>/dev/null)
assert_contains "$dummy" "use-ssl-applied" "$CUR_TEST" || return
assert_not_contains "$dummy" "nouse-ssl-applied" "$CUR_TEST" || return
t_pass
}
# patches.conf IF_USE gating on a flat patches/*.patch list: the patch
# whose IF_USE matches the enabled flag applies; the one requiring an
# absent flag is dropped.
test_patches_conf_if_use() {
t_begin "patches_conf_if_use"
reset_state
printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
mkdir -p "$SCRATCH/rt32test/patches"
mkport rt32test <<'EOF'
pkg_name="rt32test"
pkg_ver="1.0"
pkg_use="ssl"
fetch:
mkdir -p rt32test
install:
touch $MP_PREFIX/rt32test-installed
remove:
rm -f $MP_PREFIX/rt32test-installed
EOF
printf -- '--- a/dummy\n+++ b/dummy\n@@ -0,0 +1 @@\n+always-applied\n' > "$SCRATCH/rt32test/patches/001-always.patch"
printf -- '--- a/dummy\n+++ b/dummy\n@@ -0,0 +1 @@\n+ssl-gated-applied\n' > "$SCRATCH/rt32test/patches/002-ssl.patch"
printf -- '--- a/dummy\n+++ b/dummy\n@@ -0,0 +1 @@\n+absent-gated-applied\n' > "$SCRATCH/rt32test/patches/003-absent.patch"
cat > "$SCRATCH/rt32test/patches/patches.conf" <<'EOF'
002-ssl.patch:
IF_USE=ssl
003-absent.patch:
IF_USE=zzzabsentflag
EOF
cat >> "$CONF" <<'EOF'
rt32test:
USE=ssl
EOF
mp install rt32test >/tmp/rt32.out 2>&1
rc=$?
assert_exit0 "$rc" "$CUR_TEST" || return
dummy=$(cat "$WD/rt32test/rt32test/dummy" 2>/dev/null)
assert_contains "$dummy" "always-applied" "$CUR_TEST" || return
assert_contains "$dummy" "ssl-gated-applied" "$CUR_TEST" || return
assert_not_contains "$dummy" "absent-gated-applied" "$CUR_TEST" || return
t_pass
}
# one patches.conf IF_* gate scenario: the manifest's keep/drop decision
# for a single patch under a given condition set.
patch_gate_case() {
# $1 name, $2 IF_ line (or -), $3 pkg_deps (or -), $4 pkg_ver,
# $5 enabled USE flag (or -), $6 expected ("kept"/"dropped")
t_begin "$1"
reset_state
printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
mkdir -p "$SCRATCH/${1}t/patches"
depstr=""
[ "$3" != "-" ] && depstr="pkg_deps_soft=\"$3\""
mkport "${1}t" <<EOF
pkg_name="${1}t"
pkg_ver="$4"
$depstr
fetch:
mkdir -p ${1}t
install:
touch \$MP_PREFIX/${1}t-installed
remove:
rm -f \$MP_PREFIX/${1}t-installed
EOF
printf -- '--- a/dummy\n+++ b/dummy\n@@ -0,0 +1 @@\n+%s-applied\n' "$1" > "$SCRATCH/${1}t/patches/001.patch"
if [ "$2" != "-" ]; then
printf '001.patch:\n\t%s\n' "$2" > "$SCRATCH/${1}t/patches/patches.conf"
fi
if [ "$5" != "-" ]; then
printf '%st:\n\tUSE=%s\n' "$1" "$5" >> "$CONF"
fi
mp install "${1}t" >/tmp/"$1".out 2>&1
dummy=$(cat "$WD/${1}t/${1}t/dummy" 2>/dev/null)
if [ "$6" = "kept" ]; then
assert_contains "$dummy" "$1-applied" "$CUR_TEST" || return
else
assert_not_contains "$dummy" "$1-applied" "$CUR_TEST" || return
fi
t_pass
}
run_patch_gate_matrix() {
patch_gate_case pg_ifdep_matches 'IF_DEP=pgdep' 'pgdep' 1.0 - kept
patch_gate_case pg_ifdep_absent 'IF_DEP=pgdep' 'otherdep' 1.0 - dropped
patch_gate_case pg_ifdep_negated 'IF_DEP=!pgdep' 'otherdep' 1.0 - kept
patch_gate_case pg_ifver_high 'IF_VER=>=2.0' - 2.5 - kept
patch_gate_case pg_ifver_low 'IF_VER=>=2.0' - 1.5 - dropped
patch_gate_case pg_ifuse_on 'IF_USE=ssl' - 1.0 'ssl' kept
patch_gate_case pg_ifuse_off 'IF_USE=ssl' - 1.0 'x11' dropped
patch_gate_case pg_ifuse_negated 'IF_USE=!ssl' - 1.0 'x11' kept
}
# patches.conf DEPS+=: a USE-gated patch's own DEPS+= pulls in an extra
# dependency exactly when that patch applies -- present with the flag
# on, absent (and its dep uninstalled) with the flag off.
test_patches_conf_deps_plus() {
t_begin "patches_conf_deps_plus"
reset_state
printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
mkport rt33extra <<'EOF'
pkg_name="rt33extra"
pkg_ver="1.0"
install:
touch $MP_PREFIX/rt33extra-installed
remove:
rm -f $MP_PREFIX/rt33extra-installed
EOF
mkdir -p "$SCRATCH/rt33test/patches/use-gui"
mkport rt33test <<'EOF'
pkg_name="rt33test"
pkg_ver="1.0"
pkg_use="gui"
fetch:
mkdir -p rt33test
install:
touch $MP_PREFIX/rt33test-installed
remove:
rm -f $MP_PREFIX/rt33test-installed
EOF
printf -- '--- a/dummy\n+++ b/dummy\n@@ -0,0 +1 @@\n+gui-backend-applied\n' > "$SCRATCH/rt33test/patches/use-gui/001.patch"
cat > "$SCRATCH/rt33test/patches/patches.conf" <<'EOF'
use-gui/001.patch:
DEPS+=rt33extra
EOF
cat >> "$CONF" <<'EOF'
rt33test:
USE=gui
EOF
mp install rt33test >/tmp/rt33.out 2>&1
rc=$?
assert_exit0 "$rc" "$CUR_TEST" || return
dummy=$(cat "$WD/rt33test/rt33test/dummy" 2>/dev/null)
assert_contains "$dummy" "gui-backend-applied" "$CUR_TEST" || return
assert_file_exists "$MP_PREFIX/rt33extra-installed" "$CUR_TEST" || return
db=$(cat "$WD/db")
assert_contains "$db" "rt33extra" "$CUR_TEST" || return
t_pass
}
# same port, USE=gui off this time: the patch never applies (directory
# convention), so its DEPS+= never contributes rt33extra either.
test_patches_conf_deps_plus_gated_off() {
t_begin "patches_conf_deps_plus_gated_off"
reset_state
printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
mkport rt34extra <<'EOF'
pkg_name="rt34extra"
pkg_ver="1.0"
install:
touch $MP_PREFIX/rt34extra-installed
remove:
rm -f $MP_PREFIX/rt34extra-installed
EOF
mkdir -p "$SCRATCH/rt34test/patches/use-gui"
mkport rt34test <<'EOF'
pkg_name="rt34test"
pkg_ver="1.0"
pkg_use="gui"
fetch:
mkdir -p rt34test
install:
touch $MP_PREFIX/rt34test-installed
remove:
rm -f $MP_PREFIX/rt34test-installed
EOF
printf -- '--- a/dummy\n+++ b/dummy\n@@ -0,0 +1 @@\n+gui-backend-applied\n' > "$SCRATCH/rt34test/patches/use-gui/001.patch"
cat > "$SCRATCH/rt34test/patches/patches.conf" <<'EOF'
use-gui/001.patch:
DEPS+=rt34extra
EOF
mp install rt34test >/tmp/rt34.out 2>&1
rc=$?
assert_exit0 "$rc" "$CUR_TEST" || return
assert_file_absent "$MP_PREFIX/rt34extra-installed" "$CUR_TEST" || return
db=$(cat "$WD/db")
assert_not_contains "$db" "rt34extra" "$CUR_TEST" || return
t_pass
}
run_patches_suite() {
test_patches_conf
test_use_flag_patch_dirs
test_patches_conf_if_use
run_patch_gate_matrix
test_patches_conf_deps_plus
test_patches_conf_deps_plus_gated_off
}