Files
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

54 lines
1.3 KiB
Tcl

package require tcltest 2
namespace import tcltest::*
source [file dirname $argv0]/../library.tcl
set path [file dirname [file normalize $argv0]]
makeFile "" "Portfile"
exec -ignorestderr sed "s/@option@//" $path/Portfile.in > Portfile
makeFile "" $output_file
makeDirectory $work_dir
# Initial setup
load_variables $path
set_dir
port_index
proc univ_test {opt} {
global output_file path portsrc test_tclsh top_srcdir
# Modify Porfile.in for variants.
if {$opt ne "yes"} {
# No universal variant
exec -ignorestderr sed "s/@option@/universal_variant\ no/" $path/Portfile.in > Portfile
} else {
# Add universal variant
exec -ignorestderr sed "s/@option@/default_variants\ +universal/" $path/Portfile.in > Portfile
}
port_clean $path
exec -ignorestderr env PORTSRC=${portsrc} ${test_tclsh} ${top_srcdir}/src/port/port.tcl info --variants > output 2>@1
set var "variants:*"
set line [get_line $path/$output_file $var]
return $line
}
test universal {
Regression test for universal variant.
} -constraints {
darwin
} -body {
univ_test "yes"
} -result "variants: universal"
test nouniversal {
Regression test for no universal variant.
} -body {
univ_test "no"
} -result "variants: "
cleanup
cleanupTests