tests: run test suite fully in-tree without depending on prefix

Add a test-specific tclsh wrapper (`tests/test-tclsh`) that extends the
vendor tclsh wrapper with all `src/` package directories on `TCLLIBPATH`,
allowing the test suite to find in-tree packages without anything
installed at the configured prefix.

Switch all test Makefiles from `$(TCLSH)` to `$(TEST_TCLSH)` so unit and
integration tests use the in-tree interpreter. Replace all references
to `${bindir}/port` and `${bindir}/portindex` with direct invocations of
the in-tree `src/port/port.tcl` and `src/port/portindex.tcl` via the test
tclsh wrapper.

Add `init_tmp_prefix` to all test files that call `mportinit`, creating a
throwaway prefix with `macports.conf`, `sources.conf`, and `share/macports`
data populated from the source tree rather than the installed prefix.
Set `extra_env TCLLIBPATH` in test `macports.conf` files so that
`mportinit`'s environment scrub does not strip `TCLLIBPATH`, which threads
need to resolve packages.

Reorder CI workflows to run `make test` before `make install`, since the
test suite no longer requires an installed prefix.

See: https://trac.macports.org/ticket/56016

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Herby Gillot
2026-03-21 05:48:52 -04:00
committed by Clemens Lang
parent a4e03e33b8
commit 227a37b749
54 changed files with 413 additions and 104 deletions
+4 -4
View File
@@ -33,14 +33,14 @@ jobs:
run: |
set -eu
make -j$(sysctl -n hw.activecpu)
- name: Install MacPorts Base
run: |
set -eu
sudo make install
- name: Test MacPorts Base
run: |
set -eu
LLVM_PROFILE_FILE="$PWD/cov-%p.profraw" make test
- name: Install MacPorts Base
run: |
set -eu
sudo make install
- name: Report Coverage
run: |
set -eu
+4 -4
View File
@@ -56,15 +56,15 @@ jobs:
Linux) make -j$(nproc)
;;
esac
- name: Install MacPorts Base
run: |
set -eu
sudo make install
- name: Test MacPorts Base
if: startsWith(matrix.os,'macos')
run: |
set -eu
make test
- name: Install MacPorts Base
run: |
set -eu
sudo make install
- name: Deploy man pages to web
if: vars.MP_RELEASE_BRANCH == github.ref_name && startsWith(matrix.os,'ubuntu')
env:
+1
View File
@@ -40,6 +40,7 @@ src/**/*.dylib
src/**/*.dSYM
tests/test.tcl
tests/test-tclsh
tests/test/library.tcl
tests/test/trace/test.tcl
+1
View File
@@ -35,6 +35,7 @@ LN_S = @LN_S@
XCODEBUILD = @XCODEBUILD@
INTREE_TCLSH = @INTREE_TCLSH@
TEST_TCLSH = @TEST_TCLSH@
TCLSH = @TCLSH@
TCL_PACKAGE_PATH = @TCL_PACKAGE_PATH@
TCL_PREFIX = @TCL_PREFIX@
Vendored
+7
View File
@@ -632,6 +632,7 @@ LIBOBJS
SQLITE3_LIBNAME
SQLITE3_CPPFLAGS
INCLUDES
TEST_TCLSH
INTREE_TCLSH
TCLSH
TCL_PACKAGE_PATH
@@ -10197,6 +10198,7 @@ SHLIB_CFLAGS=${TCL_SHLIB_CFLAGS}
SHLIB_SUFFIX=${TCL_SHLIB_SUFFIX}
TCLSH=${TCL_EXEC_PREFIX}/bin/tclsh${TCL_VERSION}
INTREE_TCLSH=`(cd vendor; pwd)`/tclsh
TEST_TCLSH=`(cd tests; pwd)`/test-tclsh
TCL_PACKAGE_PATH="$macports_libexec_dir/lib"
@@ -10212,6 +10214,7 @@ TCL_PACKAGE_PATH="$macports_libexec_dir/lib"
INCLUDES="-I.. -I. $INCLUDES"
@@ -10243,6 +10246,8 @@ ac_config_files="$ac_config_files Doxyfile Makefile Mk/macports.autoconf.mk doc/
ac_config_files="$ac_config_files vendor/tclsh"
ac_config_files="$ac_config_files tests/test-tclsh"
ac_config_files="$ac_config_files src/cxx_stdlib_overridden.tcl"
ac_config_files="$ac_config_files src/dedup_portfiles.tcl"
@@ -10939,6 +10944,7 @@ do
"vendor/critcl/lib/critcl/Config") CONFIG_FILES="$CONFIG_FILES vendor/critcl/lib/critcl/Config" ;;
"vendor/signify-osx/autoconf.mk") CONFIG_FILES="$CONFIG_FILES vendor/signify-osx/autoconf.mk" ;;
"vendor/tclsh") CONFIG_FILES="$CONFIG_FILES vendor/tclsh" ;;
"tests/test-tclsh") CONFIG_FILES="$CONFIG_FILES tests/test-tclsh" ;;
"src/cxx_stdlib_overridden.tcl") CONFIG_FILES="$CONFIG_FILES src/cxx_stdlib_overridden.tcl" ;;
"src/dedup_portfiles.tcl") CONFIG_FILES="$CONFIG_FILES src/dedup_portfiles.tcl" ;;
"src/images_to_archives.tcl") CONFIG_FILES="$CONFIG_FILES src/images_to_archives.tcl" ;;
@@ -11501,6 +11507,7 @@ printf '%s\n' "$as_me: $ac_file is unchanged" >&6;}
case $ac_file$ac_mode in
"vendor/tclsh":F) chmod +x vendor/tclsh ;;
"tests/test-tclsh":F) chmod +x tests/test-tclsh ;;
"src/cxx_stdlib_overridden.tcl":F) chmod +x src/cxx_stdlib_overridden.tcl ;;
"src/dedup_portfiles.tcl":F) chmod +x src/dedup_portfiles.tcl ;;
"src/images_to_archives.tcl":F) chmod +x src/images_to_archives.tcl ;;
+3
View File
@@ -546,6 +546,7 @@ SHLIB_CFLAGS=${TCL_SHLIB_CFLAGS}
SHLIB_SUFFIX=${TCL_SHLIB_SUFFIX}
TCLSH=${TCL_EXEC_PREFIX}/bin/tclsh${TCL_VERSION}
INTREE_TCLSH=`(cd vendor; pwd)`/tclsh
TEST_TCLSH=`(cd tests; pwd)`/test-tclsh
TCL_PACKAGE_PATH="$macports_libexec_dir/lib"
AC_SUBST(SHLIB_LD)
@@ -560,6 +561,7 @@ AC_SUBST(TCL_SRC_DIR)
AC_SUBST(TCL_BIN_DIR)
AC_SUBST(TCLSH)
AC_SUBST(INTREE_TCLSH)
AC_SUBST(TEST_TCLSH)
INCLUDES="-I.. -I. $INCLUDES"
AC_SUBST(INCLUDES)
@@ -618,6 +620,7 @@ AC_CONFIG_FILES([
])
AC_CONFIG_FILES([vendor/tclsh], [chmod +x vendor/tclsh])
AC_CONFIG_FILES([tests/test-tclsh], [chmod +x tests/test-tclsh])
AC_CONFIG_FILES([src/cxx_stdlib_overridden.tcl], [chmod +x src/cxx_stdlib_overridden.tcl])
AC_CONFIG_FILES([src/dedup_portfiles.tcl], [chmod +x src/dedup_portfiles.tcl])
AC_CONFIG_FILES([src/images_to_archives.tcl], [chmod +x src/images_to_archives.tcl])
+1 -1
View File
@@ -47,7 +47,7 @@ distclean:: clean
rm -f Makefile
test:: $(BINS)
$(foreach test,$(TESTS),DARWINTRACE_SIP_WORKAROUND_PATH=@DARWINTRACE_SIP_WORKAROUND_PATH@ LC_ALL=C $(TCLSH) "$(srcdir)/$(test)";)
$(foreach test,$(TESTS),DARWINTRACE_SIP_WORKAROUND_PATH=@DARWINTRACE_SIP_WORKAROUND_PATH@ LC_ALL=C $(TEST_TCLSH) "$(srcdir)/$(test)";)
ifeq (,$(findstring clean,$(MAKECMDGOALS)))
# Include dependency information
+1 -1
View File
@@ -25,7 +25,7 @@ SHLIB_LDFLAGS+= -install_name ${INSTALLDIR}/${SHLIB_NAME}
endif
test::
$(TCLSH) $(srcdir)/../tests/test.tcl -nocolor
$(TEST_TCLSH) $(srcdir)/../tests/test.tcl -nocolor
distclean:: clean
rm -f macports_autoconf.tcl macports_test_autoconf.tcl ${SHLIB_NAME}
@@ -33,4 +33,5 @@
namespace eval macports::autoconf {
variable prefix "@prefix@"
variable os_platform "@OS_PLATFORM@"
variable top_srcdir "@abs_top_srcdir@"
}
+35
View File
@@ -0,0 +1,35 @@
# Set up a custom environment with its own configuration.
# Shared by macports1.0, port1.0, and package1.0 test suites.
proc init_tmp_prefix {srcpath dstpath} {
global env
umask 022
# use custom macports.conf and sources.conf
makeDirectory $dstpath
makeDirectory $dstpath/share/macports/install
makeDirectory $dstpath/var/macports/registry
makeDirectory $dstpath/var/macports/distfiles
set fd [open $dstpath/macports.conf w+]
puts $fd "portdbpath $dstpath/var/macports"
puts $fd "prefix $dstpath"
puts $fd "variants_conf $dstpath/variants.conf"
puts $fd "sources_conf $srcpath/sources.conf"
puts $fd "applications_dir $dstpath/Applications"
puts $fd "frameworks_dir $dstpath/Library/Frameworks"
puts $fd "extra_env TCLLIBPATH"
close $fd
# Populate share/macports from the source tree instead of the
# installed prefix, so tests can run fully in-tree.
set top $macports::autoconf::top_srcdir
file copy $top/macports-pubkey.pem $dstpath/share/macports/
file copy $top/setupenv.bash $dstpath/share/macports/
file copy $top/doc/base.mtree $dstpath/share/macports/install/
file copy $top/doc/prefix.mtree $dstpath/share/macports/install/
file copy $top/doc/macosx.mtree $dstpath/share/macports/install/
file copy $top/keys $dstpath/share/macports/
close [open $dstpath/variants.conf w+]
set env(PORTSRC) $dstpath/macports.conf
}
-24
View File
@@ -63,27 +63,3 @@ proc macports_worker_init {} {
# We don't need to handle portinterp_deferred_options, they're
# automatically handled correctly.
}
# Set up a custom environment with its own configuration
proc init_tmp_prefix {srcpath dstpath} {
global env
umask 022
# use custom macports.conf and sources.conf
makeDirectory $dstpath
makeDirectory $dstpath/share
makeDirectory $dstpath/var/macports/registry
makeDirectory $dstpath/var/macports/distfiles
set fd [open $dstpath/macports.conf w+]
puts $fd "portdbpath $dstpath/var/macports"
puts $fd "prefix $dstpath"
puts $fd "variants_conf $dstpath/variants.conf"
puts $fd "sources_conf $srcpath/sources.conf"
puts $fd "applications_dir $dstpath/Applications"
puts $fd "frameworks_dir $dstpath/Library/Frameworks"
close $fd
file link -symbolic $dstpath/share/macports $macports::autoconf::prefix/share/macports
close [open $dstpath/variants.conf w+]
set env(PORTSRC) $dstpath/macports.conf
}
+1
View File
@@ -15,6 +15,7 @@ package require macports 1.0
package require Thread
source ./library.tcl
source ./init_tmp_prefix.tcl
# clean leftovers from interrupted tests
file delete -force $pwd/tmpdir
+11
View File
@@ -3,13 +3,24 @@
package require tcltest 2
namespace import tcltest::*
set pwd [file dirname [file normalize $argv0]]
source ../macports_test_autoconf.tcl
package require macports 1.0
source ./library.tcl
source ./init_tmp_prefix.tcl
# clean leftovers from interrupted tests
file delete -force $pwd/tmpdir
# use a local, temporary prefix for testing
init_tmp_prefix $pwd $pwd/tmpdir
# Debug options
array set ui_options {}
#set ui_options(ports_debug) yes
#set ui_options(ports_verbose) yes
set ui_options(ports_noninteractive) yes
mportinit ui_options
source ../macports_dlist.tcl
@@ -13,6 +13,7 @@ package require Thread
package require Pextlib 1.0
source ./library.tcl
source ./init_tmp_prefix.tcl
# clean leftovers from interrupted tests
file delete -force $pwd/tmpdir
+1
View File
@@ -11,6 +11,7 @@ source ../macports_test_autoconf.tcl
package require macports 1.0
source ./library.tcl
source ./init_tmp_prefix.tcl
# clean leftovers from interrupted tests
file delete -force $pwd/tmpdir
+1 -1
View File
@@ -21,7 +21,7 @@ distclean:: clean
rm -f Makefile
test::
$(TCLSH) $(srcdir)/../tests/test.tcl -nocolor
$(TEST_TCLSH) $(srcdir)/../tests/test.tcl -nocolor
install:: all
$(INSTALL) -d -o "${DSTUSR}" -g "${DSTGRP}" -m "${DSTMODE}" "${DESTDIR}${INSTALLDIR}"
@@ -32,6 +32,7 @@
namespace eval macports::autoconf {
variable prefix "@prefix@"
variable top_srcdir "@abs_top_srcdir@"
}
namespace eval portutil::autoconf {
+9 -1
View File
@@ -8,12 +8,20 @@ set pwd [file dirname [file normalize $argv0]]
source ../package_test_autoconf.tcl
package require macports 1.0
source ./library.tcl
source $macports::autoconf::top_srcdir/src/macports1.0/tests/init_tmp_prefix.tcl
# clean leftovers from interrupted tests
file delete -force $pwd/tmpdir
# use a local, temporary prefix for testing
init_tmp_prefix $pwd $pwd/tmpdir
array set ui_options {}
#set ui_options(ports_debug) yes
#set ui_options(ports_verbose) yes
set ui_options(ports_noninteractive) yes
mportinit ui_options
source ./library.tcl
macports_worker_init
package require portarchivefetch 1.0
+9 -1
View File
@@ -8,14 +8,22 @@ set pwd [file dirname [file normalize $argv0]]
source ../package_test_autoconf.tcl
package require macports 1.0
source ./library.tcl
source $macports::autoconf::top_srcdir/src/macports1.0/tests/init_tmp_prefix.tcl
# clean leftovers from interrupted tests
file delete -force $pwd/tmpdir
# use a local, temporary prefix for testing
init_tmp_prefix $pwd $pwd/tmpdir
array set ui_options {}
#set ui_options(ports_debug) yes
#set ui_options(ports_verbose) yes
set ui_options(ports_noninteractive) yes
mportinit ui_options
package require portdmg 1.0
package require portpkg 1.0
source ./library.tcl
macports_worker_init
+9 -1
View File
@@ -8,12 +8,20 @@ set pwd [file dirname [file normalize $argv0]]
source ../package_test_autoconf.tcl
package require macports 1.0
source ./library.tcl
source $macports::autoconf::top_srcdir/src/macports1.0/tests/init_tmp_prefix.tcl
# clean leftovers from interrupted tests
file delete -force $pwd/tmpdir
# use a local, temporary prefix for testing
init_tmp_prefix $pwd $pwd/tmpdir
array set ui_options {}
#set ui_options(ports_debug) yes
#set ui_options(ports_verbose) yes
set ui_options(ports_noninteractive) yes
mportinit ui_options
source ./library.tcl
macports_worker_init
package require portmdmg

Some files were not shown because too many files have changed in this diff Show More