Extract the shared boilerplate (macports init, tmp prefix setup,
mportinit, macports_worker_init) from 27 test files into a single
test_setup.tcl sourced by all unit test suites. Merge the three
divergent copies of macports_worker_init into one consolidated
superset. Fixes#73828.
Eliminate the duplicate sources.conf files in port1.0/tests/ and
package1.0/tests/ by having init_tmp_prefix derive the path from
top_srcdir, leaving a single copy in macports1.0/tests/. Fixes
#73827.
Expose the test tclsh path as macports::autoconf::test_tclsh so
tests can reference it without recomputing the path from
top_srcdir.
Replace the hardcoded /tmp/macports-tests path in the integration
test infrastructure with a unique temporary directory created via
`file tempfile`, which respects TMPDIR and avoids collisions
between parallel or repeated runs. Move macports.conf and
sources.conf content into static template files with @TEST_ROOT@
substitution so the config structure is visible on disk rather
than generated inline.
Install a ::tcltest::cleanupTestsHook in the integration test
library so the temporary directory is removed via cleanupTests
even if a test omits its trailing explicit `cleanup` call.
Fix tests/test/arch-test/test.tcl, which invoked ${bindir}/port
via `sh -c` but never had bindir defined anywhere, to run
port.tcl directly through the test interpreter.
Replace hardcoded /tmp paths in portutil.test with $pwd-relative
paths.
Fixes: https://trac.macports.org/ticket/73828
Fixes: https://trac.macports.org/ticket/73827
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Attempting to normalize the userhome of the macports user might not work
if the user has not yet been created while running tests from within the
source tree, so don't do that unless running as root (where the test
that triggers this is skipped).
Additionally, the SIP workaround path for darwintrace needs to be
configurable, because the path in the installation directory might not
exist yet (CI may not have yet run make install). This path then also
needs to be added to the various sandboxes we configure.
This also means darwintrace.dylib needs to be picked up from the source
tree, so add another variable to test-tclsh.in (and pass that variable
through by modifying test-macports.conf) and check for its existence in
porttrace.tcl.
This also means we no longer need to reinplace the macports user's
username into the test file, so there's no longer a need to generate it
using configure.
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>
Strip inherited darwintrace DYLD and DARWINTRACE environment variables
from the shared non-trace test helpers before invoking portindex and
most port commands, and replace a couple of shell/env helper calls with
Tcl-native setup.
Also clean up the negative darwintrace environment tests so they do not
leave injected DYLD state behind for later tests.
This is an attempted fix for the macOS 15 CI failures where the
site-tags test aborts while portindex is running.
For now, there's just one test, which checks that the files in the
destroot have the archs that the port is supposed to be building for.
More can be added in future.
Running 'port test' on a port that doesn't set 'test.run yes' will no
longer error, but will run the built-in tests only. Ports that do set
test.run will run both the built-in tests and the ones defined by the
Portfile.
Closes: https://trac.macports.org/ticket/45010