do not edit — generated by btf.
git.druid.rocksindexdruid520mptest/suites/plugins.sh

test/suites/plugins.sh


# suite: the port-authoring toolchain plugins (mp lint/new/devtest/
# doctor/depcheck) -- each check below mirrors a real bug that tool
# caught during its own development this session, not a hypothetical.
# mp fetchcheck is deliberately NOT covered here: it does a real network
# fetch per port by design, which this suite's other tests never do.
 
# mp lint: a synthetic cmake-shaped legacy port whose remove throws the
# manifest away with "rm -rf build" instead of using install_manifest.txt
# must be flagged [high]; the same port fixed to use install_manifest.txt
# must come back clean. mkport alone only writes pkg.conf (every other
# suite's own ports use the new phase-based grammar) -- this needs a real
# legacy add.sh/del.sh pair, so it writes $SCRATCH's files directly.
test_lint_cmake_uninstall() {
	t_begin "lint_cmake_uninstall"
	reset_state
	mkdir -p "$SCRATCH/rt60p"
	cat > "$SCRATCH/rt60p/pkg.conf" <<'EOF'
pkg_name="rt60p"
pkg_ver="1.0"
pkg_deps="cmake"
EOF
	cat > "$SCRATCH/rt60p/add.sh" <<'EOF'
set -e
git clone https://example.com/rt60.git
cd rt60
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$MP_PREFIX
make -j$MP_JOBS
make install
EOF
	cat > "$SCRATCH/rt60p/del.sh" <<'EOF'
set -e
cd rt60
rm -rf build
cd ..
rm -rf rt60
EOF
	out=$(mp lint rt60p 2>&1)
	assert_contains "$out" "[high]" "$CUR_TEST" || return
	assert_contains "$out" "install_manifest.txt" "$CUR_TEST" || return
 
	cat > "$SCRATCH/rt60p/del.sh" <<'EOF'
set -e
cd rt60/build
xargs rm -f < install_manifest.txt
cd ../..
rm -rf rt60
EOF
	out=$(mp lint rt60p 2>&1)
	assert_not_contains "$out" "[high]" "$CUR_TEST" || return
	assert_contains "$out" "0 finding(s)" "$CUR_TEST" || return
	t_pass
}
 
# mp lint: a remove phase that cd's into a directory name that doesn't
# match what install's own "git clone <url> [destdir]" would create is
# flagged [high] (init/runit's exact bug this session); fixing the name
# clears it.
test_lint_del_cd_mismatch() {
	t_begin "lint_del_cd_mismatch"
	reset_state
	mkdir -p "$SCRATCH/rt61p"
	cat > "$SCRATCH/rt61p/pkg.conf" <<'EOF'
pkg_name="rt61p"
pkg_ver="1.0"
EOF
	cat > "$SCRATCH/rt61p/add.sh" <<'EOF'
set -e
git clone https://example.com/rt61-1.2.3.git rt61
cd rt61
make PREFIX=$MP_PREFIX
make install PREFIX=$MP_PREFIX
EOF
	cat > "$SCRATCH/rt61p/del.sh" <<'EOF'
set -e
cd wrongname
make uninstall PREFIX=$MP_PREFIX
cd ..
rm -rf rt61
EOF
	out=$(mp lint rt61p 2>&1)
	assert_contains "$out" "[high]" "$CUR_TEST" || return
	assert_contains "$out" 'cd'"'"'s into "wrongname"' "$CUR_TEST" || return
 
	sed -i 's/cd wrongname/cd rt61/' "$SCRATCH/rt61p/del.sh"
	out=$(mp lint rt61p 2>&1)
	assert_not_contains "$out" "[high]" "$CUR_TEST" || return
	t_pass
}
 
# check_cflags_not_forwarded: a genuine bare "make" with no CFLAGS
# anywhere still flags; a build-specific override var (bmake's own
# EXTRA_CFLAGS=, found for real in this tree), a capitalized
# "./Configure" (perl5/OpenSSL's own real capture step, also found for
# real), and a real cmake build invoked via "make CMAKE_*=..." (neovim's
# own shape, also found for real) all used to be missed -- a leading \b
# before CFLAGS=, a case-sensitive configure/cmake match, and a
# trailing \b after cmake, respectively -- and must not flag anymore.
test_lint_cflags_forwarding() {
	t_begin "lint_cflags_forwarding"
	reset_state
	mkdir -p "$SCRATCH/rt66bare" "$SCRATCH/rt66suffix" "$SCRATCH/rt66capconf" "$SCRATCH/rt66cmake"
	cat > "$SCRATCH/rt66bare/pkg.conf" <<'EOF'
pkg_name="rt66bare"
pkg_ver="1.0"
EOF
	cat > "$SCRATCH/rt66bare/add.sh" <<'EOF'
set -e
git clone https://example.com/rt66.git rt66
cd rt66
make
make install PREFIX=$MP_PREFIX
EOF
	cp "$SCRATCH/rt66bare/pkg.conf" "$SCRATCH/rt66suffix/pkg.conf"
	sed 's/rt66bare/rt66suffix/' "$SCRATCH/rt66suffix/pkg.conf" > "$SCRATCH/rt66suffix/pkg.conf.new"
	mv "$SCRATCH/rt66suffix/pkg.conf.new" "$SCRATCH/rt66suffix/pkg.conf"
	cat > "$SCRATCH/rt66suffix/add.sh" <<'EOF'
set -e
git clone https://example.com/rt66.git rt66
cd rt66
make EXTRA_CFLAGS="$CFLAGS"
make install PREFIX=$MP_PREFIX
EOF
	sed 's/rt66bare/rt66capconf/' "$SCRATCH/rt66bare/pkg.conf" > "$SCRATCH/rt66capconf/pkg.conf"
	cat > "$SCRATCH/rt66capconf/add.sh" <<'EOF'
set -e
git clone https://example.com/rt66.git rt66
cd rt66
./Configure --prefix=$MP_PREFIX
make
make install
EOF
	sed 's/rt66bare/rt66cmake/' "$SCRATCH/rt66bare/pkg.conf" > "$SCRATCH/rt66cmake/pkg.conf"
	cat > "$SCRATCH/rt66cmake/add.sh" <<'EOF'
set -e
git clone https://example.com/rt66.git rt66
cd rt66
make CMAKE_BUILD_TYPE=RelWithDebInfo CMAKE_INSTALL_PREFIX=$MP_PREFIX
make install
EOF
	out=$(mp lint rt66bare 2>&1)
	assert_contains "$out" 'bare "make"' "$CUR_TEST (genuine bare make still flags)" || return
	out=$(mp lint rt66suffix 2>&1)
	assert_not_contains "$out" 'bare "make"' "$CUR_TEST (EXTRA_CFLAGS= no longer a false positive)" || return
	out=$(mp lint rt66capconf 2>&1)
	assert_not_contains "$out" 'bare "make"' "$CUR_TEST (./Configure, capital C, no longer a false positive)" || return
	out=$(mp lint rt66cmake 2>&1)
	assert_not_contains "$out" 'bare "make"' "$CUR_TEST (CMAKE_*= via make, no longer a false positive)" || return
	t_pass
}
 
# mp new: scaffolds a class-based port with no add.sh/del.sh at all (just
# pkg_fetch=+inherit=), and its own output passes mp lint clean.
test_new_scaffolds_class_port() {
	t_begin "new_scaffolds_class_port"
	reset_state
	mp new scratch/rt62p --class=cmake --url=https://example.com/rt62.git --license=mit --yes \
	    >/tmp/rt62.out 2>&1
	conf=$(cat "$SCRATCH/rt62p/pkg.conf" 2>/dev/null)
	assert_contains "$conf" 'pkg_name="rt62p"' "$CUR_TEST" || return
	assert_contains "$conf" 'pkg_license="mit"' "$CUR_TEST" || return
	assert_contains "$conf" 'inherit="cmake"' "$CUR_TEST" || return
	assert_contains "$conf" 'pkg_fetch="git:https://example.com/rt62.git"' "$CUR_TEST" || return
	assert_not_contains "$(ls "$SCRATCH/rt62p")" "add.sh" "$CUR_TEST" || return
	out=$(mp lint rt62p 2>&1)
	assert_contains "$out" "0 finding(s)" "$CUR_TEST" || return
	t_pass
}
 
# mp new --class=custom: the generated add.sh renames the checkout to the
# literal port name right after cloning, and del.sh's final "rm -rf" uses
# that exact same name -- not two independently-derived guesses that
# could drift apart (the real bug mp new's own first draft had).
test_new_custom_class_names_agree() {
	t_begin "new_custom_class_names_agree"
	reset_state
	mp new scratch/rt63p --class=custom --url=https://example.com/upstream-thing.git \
	    --license=isc --yes >/tmp/rt63.out 2>&1
	add=$(cat "$SCRATCH/rt63p/add.sh" 2>/dev/null)
	del=$(cat "$SCRATCH/rt63p/del.sh" 2>/dev/null)
	assert_contains "$add" "git clone --depth 1 https://example.com/upstream-thing.git rt63p" "$CUR_TEST" || return
	assert_contains "$add" "cd rt63p" "$CUR_TEST" || return
	assert_contains "$del" "cd rt63p" "$CUR_TEST" || return
	assert_contains "$del" "rm -rf rt63p" "$CUR_TEST" || return
	out=$(mp lint rt63p 2>&1)
	assert_contains "$out" "0 finding(s)" "$CUR_TEST" || return
	t_pass
}
 
# mp devtest: a working port passes end to end; a port whose remove exits
# 0 but genuinely leaves a file behind (ruby's exact bug this session) is
# caught -- not by the manifest disappearing (it always does once remove
# exits 0), but by checking the actual file is still on disk afterward.
# pkg_manifest_cleanup="no" here on purpose: mp's own remove now sweeps
# manifest leftovers by default (mplib::resolve::clean_manifest_files),
# so a default port genuinely CAN'T leave one behind for devtest to
# catch anymore -- this test needs the one real way left to reproduce
# ruby's exact bug, a port that opted out of that safety net.
test_devtest_catches_leftover_file() {
	t_begin "devtest_catches_leftover_file"
	reset_state
	mkport rt64p <<'EOF'
pkg_name="rt64p"
pkg_ver="1.0"
pkg_manifest_cleanup="no"
install:
	touch $MP_PREFIX/rt64p-installed
remove:
	true
EOF
	out=$(mp devtest rt64p --try= 2>&1)
	rc=$?
	assert_contains "$out" "clean: FAIL" "$CUR_TEST" || return
	[ "$rc" != 0 ] || { t_fail "$CUR_TEST: devtest should have exited nonzero"; return; }
	rm -f "$MP_PREFIX/rt64p-installed"
 
	mkport rt65p <<'EOF'
pkg_name="rt65p"
pkg_ver="1.0"
install:
	touch $MP_PREFIX/rt65p-installed
remove:
	rm -f $MP_PREFIX/rt65p-installed
EOF
	out=$(mp devtest rt65p --try= 2>&1)
	rc=$?
	assert_contains "$out" "devtest passed" "$CUR_TEST" || return
	[ "$rc" = 0 ] || { t_fail "$CUR_TEST: devtest should have exited 0 (got $rc)"; return; }
 
	# the composed case: SAME "remove: true" bug as rt64p, but WITHOUT the
	# opt-out -- mp's own manifest sweep should now catch what remove:
	# itself didn't, so devtest sees a genuinely clean disk and passes.
	mkport rt64p2 <<'EOF'
pkg_name="rt64p2"
pkg_ver="1.0"
install:
	touch $MP_PREFIX/rt64p2-installed
remove:
	true
EOF
	out=$(mp devtest rt64p2 --try= 2>&1)
	rc=$?
	assert_contains "$out" "devtest passed" "$CUR_TEST" || return
	assert_not_contains "$out" "clean: FAIL" "$CUR_TEST" || return
	[ "$rc" = 0 ] || { t_fail "$CUR_TEST: devtest should have exited 0 (got $rc)"; return; }
	t_pass
}
 
# mp doctor: a db entry with no manifest and nothing on disk is a ghost,
# reported and (--fix) safely cleared; an entry with no manifest but a
# real matching binary still on disk (mplib::resolve's own documented
# "installed before manifest tracking" case) is left alone even with
# --fix.
test_doctor_ghost_vs_real() {
	t_begin "doctor_ghost_vs_real"
	reset_state
	mkport rt66p <<'EOF'
pkg_name="rt66p"
pkg_ver="1.0"
install:
	touch $MP_PREFIX/rt66p-installed
remove:
	rm -f $MP_PREFIX/rt66p-installed
EOF
	mp install rt66p >/tmp/rt66.out 2>&1
	rm -f "$WD/manifest/rt66p" "$MP_PREFIX/rt66p-installed"
	mkdir -p "$MP_PREFIX/bin"
	touch "$MP_PREFIX/bin/rt66p"
 
	out=$(mp doctor 2>&1)
	assert_contains "$out" "rt66p" "$CUR_TEST" || return
	assert_contains "$out" "no manifest, something plausible on disk" "$CUR_TEST" || return
 
	rm -f "$MP_PREFIX/bin/rt66p"
	out=$(mp doctor --fix 2>&1)
	assert_contains "$out" "rt66p cleared" "$CUR_TEST" || return
	out=$(mp doctor 2>&1)
	assert_not_contains "$out" "rt66p" "$CUR_TEST" || return
	t_pass
}
 
# mp depcheck: a manifest with no ELF files at all is a clean, explicit
# no-op (not silently "0 findings" for the wrong reason).
test_depcheck_no_elf() {
	t_begin "depcheck_no_elf"
	reset_state
	mkport rt67p <<'EOF'
pkg_name="rt67p"
pkg_ver="1.0"
install:
	mkdir -p $MP_PREFIX/share/rt67
	echo "hello" > $MP_PREFIX/share/rt67/data.txt
	touch $MP_PREFIX/rt67p-installed
remove:
	rm -rf $MP_PREFIX/share/rt67
	rm -f $MP_PREFIX/rt67p-installed
EOF
	mp install rt67p >/tmp/rt67.out 2>&1
	out=$(mp depcheck rt67p 2>&1)
	assert_contains "$out" "no ELF binaries" "$CUR_TEST" || return
	t_pass
}
 
# --dir=: mp new/lint/devtest/depcheck can all be pointed at an
# arbitrary root instead of the configured ports tree -- searched the
# same way CUSTOM_PORTS_DIR already is (first, ahead of every
# configured repo) -- so a port can be scaffolded and fully round-
# tripped (lint, a real install/remove cycle, depcheck) before it's
# ever added to any repo at all.
test_dir_flag_out_of_tree() {
	t_begin "dir_flag_out_of_tree"
	reset_state
	printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
	OUTROOT="$WD/outoftree"
	rm -rf "$OUTROOT"
 
	mp new scratch/rt70p --dir="$OUTROOT" --yes --class=custom \
	    --url=https://example.com/rt70.git --license=mit >/tmp/rt70new.out 2>&1
	assert_file_exists "$OUTROOT/scratch/rt70p/pkg.conf" "$CUR_TEST (new writes under --dir)" || return
	assert_file_absent "$SCRATCH/rt70p" "$CUR_TEST (not written into the real tree)" || return
 
	# overwrite the scaffolded add.sh/del.sh with something trivial and
	# fast -- proving --dir= resolution works end to end needs no real
	# network fetch.
	cat > "$OUTROOT/scratch/rt70p/add.sh" <<'EOF'
set -e
touch $MP_PREFIX/rt70p-installed
EOF
	cat > "$OUTROOT/scratch/rt70p/del.sh" <<'EOF'
set -e
rm -f $MP_PREFIX/rt70p-installed
EOF
 
	out=$(mp lint scratch/rt70p --dir="$OUTROOT" 2>&1)
	assert_contains "$out" "1 port(s) checked" "$CUR_TEST (lint finds it via --dir)" || return
 
	out=$(mp devtest scratch/rt70p --dir="$OUTROOT" --keep 2>&1)
	assert_contains "$out" "install: ok" "$CUR_TEST (devtest installs via --dir)" || return
	assert_file_exists "$MP_PREFIX/rt70p-installed" "$CUR_TEST" || return
 
	out=$(mp depcheck scratch/rt70p --dir="$OUTROOT" 2>&1)
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST (depcheck via --dir)" || return
 
	# cleanup: remove_pkg resolves purely from the db (no pkg.conf/
	# portdir lookup at all), so this needs no --dir= of its own.
	mp remove --force scratch/rt70p >/dev/null 2>&1
	rm -rf "$OUTROOT"
	t_pass
}
 
run_plugins_suite() {
	test_lint_cmake_uninstall
	test_lint_del_cd_mismatch
	test_lint_cflags_forwarding
	test_new_scaffolds_class_port
	test_new_custom_class_names_agree
	test_devtest_catches_leftover_file
	test_doctor_ghost_vs_real
	test_depcheck_no_elf
	test_dir_flag_out_of_tree
}
powered by btf.