Files
macports-base/src/macports1.0/tests/init_tmp_prefix.tcl
T
Herby Gillot 227a37b749 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>
2026-04-11 03:39:35 +02:00

36 lines
1.4 KiB
Tcl

# 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
}