From 10849847982ac0e2fdf72152eac5e9ef3bac2be7 Mon Sep 17 00:00:00 2001 From: Herby Gillot Date: Sat, 11 Apr 2026 12:09:14 -0400 Subject: [PATCH] tests: consolidate duplicated test setup code and config files 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 --- src/macports1.0/macports_test_autoconf.tcl.in | 1 + src/macports1.0/tests/init_tmp_prefix.tcl | 26 +++++-- src/macports1.0/tests/library.tcl | 65 ---------------- src/macports1.0/tests/macports.test | 18 +---- src/macports1.0/tests/macports_dlist.test | 17 +---- src/macports1.0/tests/mport_fetch_thread.test | 15 +--- src/macports1.0/tests/reclaim.test | 14 +--- .../tests/test_setup.tcl} | 31 +++++++- src/package1.0/package_test_autoconf.tcl.in | 1 + src/package1.0/tests/library.tcl | 76 ------------------- src/package1.0/tests/portarchivefetch.test | 15 +--- src/package1.0/tests/portdmg.test | 15 +--- src/package1.0/tests/portmdmg.test | 15 +--- src/package1.0/tests/portmpkg.test | 15 +--- src/package1.0/tests/portpkg.test | 15 +--- src/package1.0/tests/sources.conf | 27 ------- src/port1.0/port_test_autoconf.tcl.in | 1 + src/port1.0/tests/portactivate.test | 16 +--- src/port1.0/tests/portbuild.test | 16 +--- src/port1.0/tests/portbump.test | 14 +--- src/port1.0/tests/portchecksum.test | 16 +--- src/port1.0/tests/portclean.test | 16 +--- src/port1.0/tests/portdeactivate.test | 16 +--- src/port1.0/tests/portdepends.test | 16 +--- src/port1.0/tests/portdistcheck.test | 16 +--- src/port1.0/tests/portinstall.test | 16 +--- src/port1.0/tests/portlint.test | 16 +--- src/port1.0/tests/portlivecheck.test | 15 +--- src/port1.0/tests/portload.test | 16 +--- src/port1.0/tests/portmain.test | 18 +---- src/port1.0/tests/portpatch.test | 16 +--- src/port1.0/tests/portstartupitem.test | 16 +--- src/port1.0/tests/porttest.test | 16 +--- src/port1.0/tests/portuninstall.test | 16 +--- src/port1.0/tests/portutil.test | 32 +++----- src/port1.0/tests/sources.conf | 27 ------- tests/sources.conf | 6 +- tests/test-macports.conf | 7 +- tests/test/arch-test/test.tcl | 28 ++----- tests/test/library.tcl.in | 73 ++++++++++++------ 40 files changed, 154 insertions(+), 657 deletions(-) delete mode 100644 src/macports1.0/tests/library.tcl rename src/{port1.0/tests/library.tcl => macports1.0/tests/test_setup.tcl} (77%) delete mode 100644 src/package1.0/tests/sources.conf delete mode 100644 src/port1.0/tests/sources.conf diff --git a/src/macports1.0/macports_test_autoconf.tcl.in b/src/macports1.0/macports_test_autoconf.tcl.in index adfb9b37b..b80abc5d8 100644 --- a/src/macports1.0/macports_test_autoconf.tcl.in +++ b/src/macports1.0/macports_test_autoconf.tcl.in @@ -33,5 +33,6 @@ namespace eval macports::autoconf { variable prefix "@prefix@" variable os_platform "@OS_PLATFORM@" + variable test_tclsh "@TEST_TCLSH@" variable top_srcdir "@abs_top_srcdir@" } diff --git a/src/macports1.0/tests/init_tmp_prefix.tcl b/src/macports1.0/tests/init_tmp_prefix.tcl index dc1e8499e..8f59d2f5c 100644 --- a/src/macports1.0/tests/init_tmp_prefix.tcl +++ b/src/macports1.0/tests/init_tmp_prefix.tcl @@ -1,6 +1,21 @@ -# 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} { +# Create a throwaway MacPorts prefix at dstpath for unit testing. +# +# Generates a minimal macports.conf (pointing sources_conf at the +# single shared sources.conf in this directory), an empty +# variants.conf, and the directory layout that mportinit expects. +# Data files (pubkey, mtree specs, keys) are copied from the source +# tree so tests can run fully in-tree without an installed prefix. +# +# Sets PORTSRC so that a subsequent mportinit picks up the generated +# configuration. +# +# Shared by macports1.0, port1.0, and package1.0 test suites via +# test_setup.tcl. +# +# dstpath - Absolute path to the directory that will serve as the +# prefix. Created if it does not exist; callers should +# delete it when the test is finished. +proc init_tmp_prefix {dstpath} { global env umask 022 @@ -9,11 +24,13 @@ proc init_tmp_prefix {srcpath dstpath} { makeDirectory $dstpath/share/macports/install makeDirectory $dstpath/var/macports/registry makeDirectory $dstpath/var/macports/distfiles + set top $macports::autoconf::top_srcdir + set sources_conf [file join $top src macports1.0 tests sources.conf] 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 "sources_conf $sources_conf" puts $fd "applications_dir $dstpath/Applications" puts $fd "frameworks_dir $dstpath/Library/Frameworks" puts $fd "extra_env TCLLIBPATH" @@ -21,7 +38,6 @@ proc init_tmp_prefix {srcpath dstpath} { # 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/ diff --git a/src/macports1.0/tests/library.tcl b/src/macports1.0/tests/library.tcl deleted file mode 100644 index 0203d85cb..000000000 --- a/src/macports1.0/tests/library.tcl +++ /dev/null @@ -1,65 +0,0 @@ -## -# This is basically a copy of macports::worker_init, but without using -# sub-interpreters -proc macports_worker_init {} { - interp alias {} _cd {} cd - proc PortSystem {version} { - package require port $version - } - # Clearly separate slave interpreters and the master interpreter. - interp alias {} mport_exec {} mportexec - interp alias {} mport_open {} mportopen - interp alias {} mport_close {} mportclose - interp alias {} mport_lookup {} mportlookup - interp alias {} mport_info {} mportinfo - # Export some utility functions defined here. - interp alias {} macports_create_thread {} macports::create_thread - interp alias {} getportworkpath_from_buildpath {} macports::getportworkpath_from_buildpath - interp alias {} getportresourcepath {} macports::getportresourcepath - interp alias {} getportlogpath {} macports::getportlogpath - interp alias {} getdefaultportresourcepath {} macports::getdefaultportresourcepath - interp alias {} getprotocol {} macports::getprotocol - interp alias {} getportdir {} macports::getportdir - interp alias {} findBinary {} macports::findBinary - interp alias {} binaryInPath {} macports::binaryInPath - # New Registry/Receipts stuff - interp alias {} registry_new {} registry::new_entry - interp alias {} registry_open {} registry::open_entry - interp alias {} registry_write {} registry::write_entry - interp alias {} registry_prop_store {} registry::property_store - interp alias {} registry_prop_retr {} registry::property_retrieve - interp alias {} registry_exists {} registry::entry_exists - interp alias {} registry_exists_for_name {} registry::entry_exists_for_name - interp alias {} registry_activate {} portimage::activate - interp alias {} registry_deactivate {} portimage::deactivate - interp alias {} registry_deactivate_composite {} portimage::deactivate_composite - interp alias {} registry_uninstall {} registry_uninstall::uninstall - interp alias {} registry_register_deps {} registry::register_dependencies - interp alias {} registry_fileinfo_for_index {} registry::fileinfo_for_index - interp alias {} registry_fileinfo_for_file {} registry::fileinfo_for_file - interp alias {} registry_bulk_register_files {} registry::register_bulk_files - interp alias {} registry_active {} registry::active - interp alias {} registry_file_registered {} registry::file_registered - interp alias {} registry_port_registered {} registry::port_registered - interp alias {} registry_list_depends {} registry::list_depends - # deferred options processing. - interp alias {} getoption {} macports::getoption - # ping cache - interp alias {} get_pingtime {} macports::get_pingtime - interp alias {} set_pingtime {} macports::set_pingtime - # archive_sites.conf handling - interp alias {} get_archive_sites_conf_values {} macports::get_archive_sites_conf_values - foreach opt $macports::portinterp_options { - if {![info exists $opt]} { - global macports::$opt - set ::$opt macports::$opt - } - if {[info exists $opt]} { - set system_options($opt) $opt - set ::$opt $opt - } - } - - # We don't need to handle portinterp_deferred_options, they're - # automatically handled correctly. -} diff --git a/src/macports1.0/tests/macports.test b/src/macports1.0/tests/macports.test index ff090e5c2..dfbb9b431 100644 --- a/src/macports1.0/tests/macports.test +++ b/src/macports1.0/tests/macports.test @@ -7,26 +7,10 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../macports_test_autoconf.tcl +source $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl -# constraint for darwin platform -testConstraint darwin [expr {$macports::autoconf::os_platform eq "darwin"}] - -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 -# use a local, temporary prefix for testing -init_tmp_prefix $pwd $pwd/tmpdir - -# Debug options -array set ui_options {} -set ui_options(ports_noninteractive) yes -mportinit ui_options - test mportclose { Mport close unit test. diff --git a/src/macports1.0/tests/macports_dlist.test b/src/macports1.0/tests/macports_dlist.test index 943487927..3845c7d80 100644 --- a/src/macports1.0/tests/macports_dlist.test +++ b/src/macports1.0/tests/macports_dlist.test @@ -6,22 +6,7 @@ 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::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl source ../macports_dlist.tcl diff --git a/src/macports1.0/tests/mport_fetch_thread.test b/src/macports1.0/tests/mport_fetch_thread.test index 43d01f557..0c0867301 100644 --- a/src/macports1.0/tests/mport_fetch_thread.test +++ b/src/macports1.0/tests/mport_fetch_thread.test @@ -7,24 +7,11 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../macports_test_autoconf.tcl +source $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl -package require macports 1.0 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 -# use a local, temporary prefix for testing -init_tmp_prefix $pwd $pwd/tmpdir - -# Debug options -array set ui_options {} -set ui_options(ports_noninteractive) yes -mportinit ui_options - # portutil.tcl defines a Tcl chown proc (wrapping lchown + fs-traverse) # that overrides the Pextlib C chown command in port interpreters. # port1.0 is not loaded here, so define it for testing. diff --git a/src/macports1.0/tests/reclaim.test b/src/macports1.0/tests/reclaim.test index d81e5745f..79a063988 100644 --- a/src/macports1.0/tests/reclaim.test +++ b/src/macports1.0/tests/reclaim.test @@ -8,19 +8,7 @@ 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 - -array set ui_options {} -set ui_options(ports_noninteractive) yes -mportinit ui_options +source $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl set setup_testdir { set saved_portdbpath ${macports::portdbpath} diff --git a/src/port1.0/tests/library.tcl b/src/macports1.0/tests/test_setup.tcl similarity index 77% rename from src/port1.0/tests/library.tcl rename to src/macports1.0/tests/test_setup.tcl index 6355211dc..40e8a104b 100644 --- a/src/port1.0/tests/library.tcl +++ b/src/macports1.0/tests/test_setup.tcl @@ -1,6 +1,32 @@ +# Shared test initialization for macports1.0, port1.0, and package1.0 tests. +# +# Prerequisites before sourcing this file: +# package require tcltest 2 +# namespace import tcltest::* +# set pwd [file dirname [file normalize $argv0]] +# source ../XXX_test_autoconf.tcl ;# sets macports::autoconf::* + +package require macports 1.0 + +# Source shared test helpers from this directory. +set _test_setup_dir [file dirname [file normalize [info script]]] +source [file join $_test_setup_dir init_tmp_prefix.tcl] + +# Clean leftovers from interrupted tests and set up a temporary prefix. +file delete -force $pwd/tmpdir +init_tmp_prefix $pwd/tmpdir + +array set ui_options {} +set ui_options(ports_noninteractive) yes +mportinit ui_options + +# Constraint for darwin platform. +testConstraint darwin [expr {$tcl_platform(os) eq "Darwin"}] + ## -# This is basically a copy of macports::worker_init, but without using -# sub-interpreters +# Consolidated copy of macports::worker_init for testing, without using +# sub-interpreters. Superset of aliases needed by macports1.0, port1.0, +# and package1.0 test suites. proc macports_worker_init {} { interp alias {} _cd {} cd proc PortSystem {version} { @@ -24,6 +50,7 @@ proc macports_worker_init {} { interp alias {} getportdir {} macports::getportdir interp alias {} findBinary {} macports::findBinary interp alias {} binaryInPath {} macports::binaryInPath + interp alias {} shellescape {} macports::shellescape # New Registry/Receipts stuff interp alias {} registry_new {} registry::new_entry interp alias {} registry_open {} registry::open_entry diff --git a/src/package1.0/package_test_autoconf.tcl.in b/src/package1.0/package_test_autoconf.tcl.in index fc5c01fd4..e4a5f7795 100644 --- a/src/package1.0/package_test_autoconf.tcl.in +++ b/src/package1.0/package_test_autoconf.tcl.in @@ -32,6 +32,7 @@ namespace eval macports::autoconf { variable prefix "@prefix@" + variable test_tclsh "@TEST_TCLSH@" variable top_srcdir "@abs_top_srcdir@" } diff --git a/src/package1.0/tests/library.tcl b/src/package1.0/tests/library.tcl index ae5e57002..b6517c71f 100644 --- a/src/package1.0/tests/library.tcl +++ b/src/package1.0/tests/library.tcl @@ -42,79 +42,3 @@ proc env_init {} { } } -## -# This is basically a copy of macports::worker_init, but without using -# sub-interpreters -proc macports_worker_init {} { - interp alias {} _cd {} cd - - proc PortSystem {version} { - package require port $version - } - - # Clearly separate slave interpreters and the master interpreter. - interp alias {} mport_exec {} mportexec - interp alias {} mport_open {} mportopen - interp alias {} mport_close {} mportclose - interp alias {} mport_lookup {} mportlookup - interp alias {} mport_info {} mportinfo - - # Export some utility functions defined here. - interp alias {} macports_create_thread {} macports::create_thread - interp alias {} getportworkpath_from_buildpath {} macports::getportworkpath_from_buildpath - interp alias {} getportresourcepath {} macports::getportresourcepath - interp alias {} getportlogpath {} macports::getportlogpath - interp alias {} getdefaultportresourcepath {} macports::getdefaultportresourcepath - interp alias {} getprotocol {} macports::getprotocol - interp alias {} getportdir {} macports::getportdir - interp alias {} findBinary {} macports::findBinary - interp alias {} binaryInPath {} macports::binaryInPath - interp alias {} shellescape {} macports::shellescape - - # New Registry/Receipts stuff - interp alias {} registry_new {} registry::new_entry - interp alias {} registry_open {} registry::open_entry - interp alias {} registry_write {} registry::write_entry - interp alias {} registry_prop_store {} registry::property_store - interp alias {} registry_prop_retr {} registry::property_retrieve - interp alias {} registry_exists {} registry::entry_exists - interp alias {} registry_exists_for_name {} registry::entry_exists_for_name - interp alias {} registry_activate {} portimage::activate - interp alias {} registry_deactivate {} portimage::deactivate - interp alias {} registry_deactivate_composite {} portimage::deactivate_composite - interp alias {} registry_uninstall {} registry_uninstall::uninstall - interp alias {} registry_register_deps {} registry::register_dependencies - interp alias {} registry_fileinfo_for_index {} registry::fileinfo_for_index - interp alias {} registry_fileinfo_for_file {} registry::fileinfo_for_file - interp alias {} registry_bulk_register_files {} registry::register_bulk_files - interp alias {} registry_active {} registry::active - interp alias {} registry_file_registered {} registry::file_registered - interp alias {} registry_port_registered {} registry::port_registered - interp alias {} registry_list_depends {} registry::list_depends - - # deferred options processing. - interp alias {} getoption {} macports::getoption - - # ping cache - interp alias {} get_pingtime {} macports::get_pingtime - interp alias {} set_pingtime {} macports::set_pingtime - - # archive_sites.conf handling - interp alias {} get_archive_sites_conf_values {} macports::get_archive_sites_conf_values - - foreach opt $macports::portinterp_options { - if {![info exists $opt]} { - global macports::$opt - set ::$opt macports::$opt - } - if {[info exists $opt]} { - set system_options($opt) $opt - set ::$opt $opt - } - } - - # We don't need to handle portinterp_deferred_options, they're - # automatically handled correctly. -} - -testConstraint darwin [expr {$tcl_platform(os) eq "Darwin"}] diff --git a/src/package1.0/tests/portarchivefetch.test b/src/package1.0/tests/portarchivefetch.test index 70a3396a0..ed2121f76 100644 --- a/src/package1.0/tests/portarchivefetch.test +++ b/src/package1.0/tests/portarchivefetch.test @@ -6,21 +6,8 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../package_test_autoconf.tcl -package require macports 1.0 - +source $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl 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 macports_worker_init diff --git a/src/package1.0/tests/portdmg.test b/src/package1.0/tests/portdmg.test index 629240fab..27c32becd 100644 --- a/src/package1.0/tests/portdmg.test +++ b/src/package1.0/tests/portdmg.test @@ -6,21 +6,8 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../package_test_autoconf.tcl -package require macports 1.0 - +source $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl 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 diff --git a/src/package1.0/tests/portmdmg.test b/src/package1.0/tests/portmdmg.test index e159312d8..b6d6293bc 100644 --- a/src/package1.0/tests/portmdmg.test +++ b/src/package1.0/tests/portmdmg.test @@ -6,21 +6,8 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../package_test_autoconf.tcl -package require macports 1.0 - +source $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl 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 macports_worker_init diff --git a/src/package1.0/tests/portmpkg.test b/src/package1.0/tests/portmpkg.test index 442cd3046..55f391ab9 100644 --- a/src/package1.0/tests/portmpkg.test +++ b/src/package1.0/tests/portmpkg.test @@ -6,21 +6,8 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../package_test_autoconf.tcl -package require macports 1.0 - +source $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl 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 portmpkg 1.0 package require portpkg 1.0 diff --git a/src/package1.0/tests/portpkg.test b/src/package1.0/tests/portpkg.test index e2b0e0b18..6c6f20480 100644 --- a/src/package1.0/tests/portpkg.test +++ b/src/package1.0/tests/portpkg.test @@ -6,21 +6,8 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../package_test_autoconf.tcl -package require macports 1.0 - +source $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl 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 portmpkg 1.0 package require portpkg 1.0 diff --git a/src/package1.0/tests/sources.conf b/src/package1.0/tests/sources.conf deleted file mode 100644 index f4984b867..000000000 --- a/src/package1.0/tests/sources.conf +++ /dev/null @@ -1,27 +0,0 @@ -# MacPorts system-wide configuration file for ports tree sources. -# -# To change how MacPorts fetches base, see rsync_server and rsync_dir in -# macports.conf. -# To add a local source, add a "file://" entry. -# -# Example: file:///Users/landonf/misc/MacPorts/ports -# -# To prevent a source from synchronizing when `port sync` is used, -# append "[nosync]" at the end. -# -# Example: file:///Users/landonf/misc/MacPorts/ports [nosync] -# -# Note that MacPorts parses source URLs in order; when a port appears in -# multiple sources, it installs the first occurrence. For local sources -# to shadow remote ones, "file://" URLs must come before other URLs. -# A list of rsync mirrors is available at -# https://trac.macports.org/wiki/Mirrors#Portfiles. -# -# If an "rsync://" URL points to a .tar file, a signed .rmd160 file must -# exist in the same directory on the server and will be used to verify -# its integrity. -# -# For proper functionality of various resources (port groups, mirror -# sites, etc.), the primary MacPorts source must always be tagged -# "[default]", even if switched from the default "rsync://" URL. -rsync://rsync.macports.org/macports/release/tarballs/ports.tar [default] diff --git a/src/port1.0/port_test_autoconf.tcl.in b/src/port1.0/port_test_autoconf.tcl.in index 5f91fa699..23e120358 100644 --- a/src/port1.0/port_test_autoconf.tcl.in +++ b/src/port1.0/port_test_autoconf.tcl.in @@ -32,5 +32,6 @@ namespace eval macports::autoconf { variable prefix "@prefix@" + variable test_tclsh "@TEST_TCLSH@" variable top_srcdir "@abs_top_srcdir@" } diff --git a/src/port1.0/tests/portactivate.test b/src/port1.0/tests/portactivate.test index cce3b14dd..4b48a6936 100644 --- a/src/port1.0/tests/portactivate.test +++ b/src/port1.0/tests/portactivate.test @@ -6,21 +6,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl package require portactivate 1.0 package require registry 1.0 diff --git a/src/port1.0/tests/portbuild.test b/src/port1.0/tests/portbuild.test index 2d3483d80..ba539e221 100644 --- a/src/port1.0/tests/portbuild.test +++ b/src/port1.0/tests/portbuild.test @@ -6,21 +6,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl # Provide a stub for the port callback mechanism namespace eval port { diff --git a/src/port1.0/tests/portbump.test b/src/port1.0/tests/portbump.test index acadc04b4..984b87021 100644 --- a/src/port1.0/tests/portbump.test +++ b/src/port1.0/tests/portbump.test @@ -6,19 +6,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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_noninteractive) yes -mportinit ui_options +source $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl # Provide a stub for the port callback mechanism namespace eval port { diff --git a/src/port1.0/tests/portchecksum.test b/src/port1.0/tests/portchecksum.test index f8c99d0d6..60c636d2c 100644 --- a/src/port1.0/tests/portchecksum.test +++ b/src/port1.0/tests/portchecksum.test @@ -6,21 +6,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl package require portchecksum 1.0 diff --git a/src/port1.0/tests/portclean.test b/src/port1.0/tests/portclean.test index 960f8aae2..4ff02ad98 100644 --- a/src/port1.0/tests/portclean.test +++ b/src/port1.0/tests/portclean.test @@ -6,21 +6,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl package require portclean 1.0 source ../port_autoconf.tcl diff --git a/src/port1.0/tests/portdeactivate.test b/src/port1.0/tests/portdeactivate.test index 24f80536c..2f6074f25 100644 --- a/src/port1.0/tests/portdeactivate.test +++ b/src/port1.0/tests/portdeactivate.test @@ -6,21 +6,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl package require portdeactivate 1.0 package require registry 1.0 diff --git a/src/port1.0/tests/portdepends.test b/src/port1.0/tests/portdepends.test index 59a01929f..19f8633d1 100644 --- a/src/port1.0/tests/portdepends.test +++ b/src/port1.0/tests/portdepends.test @@ -6,21 +6,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl package require portdepends 1.0 diff --git a/src/port1.0/tests/portdistcheck.test b/src/port1.0/tests/portdistcheck.test index 679e0e5ee..8c4695048 100644 --- a/src/port1.0/tests/portdistcheck.test +++ b/src/port1.0/tests/portdistcheck.test @@ -6,21 +6,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl package require portdistcheck 1.0 macports_worker_init diff --git a/src/port1.0/tests/portinstall.test b/src/port1.0/tests/portinstall.test index c231072db..9ecfe3ddb 100644 --- a/src/port1.0/tests/portinstall.test +++ b/src/port1.0/tests/portinstall.test @@ -6,21 +6,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl package require portinstall 1.0 source ../../registry2.0/portuninstall.tcl diff --git a/src/port1.0/tests/portlint.test b/src/port1.0/tests/portlint.test index 517e64343..7a074dad6 100644 --- a/src/port1.0/tests/portlint.test +++ b/src/port1.0/tests/portlint.test @@ -6,21 +6,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl package require portlint 1.0 diff --git a/src/port1.0/tests/portlivecheck.test b/src/port1.0/tests/portlivecheck.test index 202fe024f..d90281fb9 100644 --- a/src/port1.0/tests/portlivecheck.test +++ b/src/port1.0/tests/portlivecheck.test @@ -6,22 +6,9 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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_noninteractive) yes -mportinit ui_options +source $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl package require portlivecheck 1.0 -source ./library.tcl macports_worker_init # --------------------------------------------------------------------------- diff --git a/src/port1.0/tests/portload.test b/src/port1.0/tests/portload.test index 32485efb5..dcc0f592d 100644 --- a/src/port1.0/tests/portload.test +++ b/src/port1.0/tests/portload.test @@ -6,21 +6,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl set os_platform darwin set os_version 20.0.1 diff --git a/src/port1.0/tests/portmain.test b/src/port1.0/tests/portmain.test index 9264ae48c..6b9418eae 100644 --- a/src/port1.0/tests/portmain.test +++ b/src/port1.0/tests/portmain.test @@ -6,21 +6,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl macports_worker_init package require portmain 1.0 @@ -35,7 +21,7 @@ set portpath . set portbuildpath ./build set macports::portdbpath . -set test_tclsh [file normalize [file join $macports::autoconf::top_srcdir tests test-tclsh]] +set test_tclsh $macports::autoconf::test_tclsh set port_script [file normalize [file join $pwd .. .. port port.tcl]] testConstraint portClientAvailable [expr {[file executable $test_tclsh] && [file readable $port_script]}] diff --git a/src/port1.0/tests/portpatch.test b/src/port1.0/tests/portpatch.test index e27f549ad..de7ba3b0c 100644 --- a/src/port1.0/tests/portpatch.test +++ b/src/port1.0/tests/portpatch.test @@ -6,21 +6,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl package require portpatch source ../port_autoconf.tcl diff --git a/src/port1.0/tests/portstartupitem.test b/src/port1.0/tests/portstartupitem.test index f1e3c0a88..767b7578d 100644 --- a/src/port1.0/tests/portstartupitem.test +++ b/src/port1.0/tests/portstartupitem.test @@ -7,21 +7,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl macports_worker_init diff --git a/src/port1.0/tests/porttest.test b/src/port1.0/tests/porttest.test index 2c42d61e1..9ce3d6c73 100644 --- a/src/port1.0/tests/porttest.test +++ b/src/port1.0/tests/porttest.test @@ -6,21 +6,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl macports_worker_init package require port 1.0 diff --git a/src/port1.0/tests/portuninstall.test b/src/port1.0/tests/portuninstall.test index 640f69a3a..18f1e1328 100644 --- a/src/port1.0/tests/portuninstall.test +++ b/src/port1.0/tests/portuninstall.test @@ -6,21 +6,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl package require portinstall 1.0 source ../../registry2.0/portuninstall.tcl diff --git a/src/port1.0/tests/portutil.test b/src/port1.0/tests/portutil.test index 2814f2538..59ed3c3b5 100644 --- a/src/port1.0/tests/portutil.test +++ b/src/port1.0/tests/portutil.test @@ -7,21 +7,7 @@ namespace import tcltest::* set pwd [file dirname [file normalize $argv0]] source ../port_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 $macports::autoconf::top_srcdir/src/macports1.0/tests/test_setup.tcl macports_worker_init @@ -269,7 +255,7 @@ test reinplace { set macportsuser macports set_ui_prefix - set root "/tmp/macports-portutil-reinplace" + set root "$pwd/work-reinplace" file delete -force $root set workpath $root @@ -329,7 +315,7 @@ test reinplace { test delete { Delete unit test. } -setup { - set root "/tmp/macports-portutil-delete" + set root "$pwd/work-delete" file delete -force $root mtree $root { @@ -374,11 +360,11 @@ test delete { test touch { Touch unit test. } -setup { - set dir "/tmp" - set file "macports-portutil-touch" - set file2 "macports-portutil-touch2" - set root "/tmp/macports-portutil-touch" - set root2 "/tmp/macports-portutil-touch2" + set dir $pwd + set file "work-touch" + set file2 "work-touch2" + set root "$pwd/work-touch" + set root2 "$pwd/work-touch2" file delete -force $root file delete -force $root2 } -body { @@ -428,7 +414,7 @@ test ln { ln unit test. } -setup { set oldpwd [pwd] - set root "/tmp/macports-portutil-ln" + set root "$pwd/work-ln" file delete -force $root file mkdir $root } -body { diff --git a/src/port1.0/tests/sources.conf b/src/port1.0/tests/sources.conf deleted file mode 100644 index f4984b867..000000000 --- a/src/port1.0/tests/sources.conf +++ /dev/null @@ -1,27 +0,0 @@ -# MacPorts system-wide configuration file for ports tree sources. -# -# To change how MacPorts fetches base, see rsync_server and rsync_dir in -# macports.conf. -# To add a local source, add a "file://" entry. -# -# Example: file:///Users/landonf/misc/MacPorts/ports -# -# To prevent a source from synchronizing when `port sync` is used, -# append "[nosync]" at the end. -# -# Example: file:///Users/landonf/misc/MacPorts/ports [nosync] -# -# Note that MacPorts parses source URLs in order; when a port appears in -# multiple sources, it installs the first occurrence. For local sources -# to shadow remote ones, "file://" URLs must come before other URLs. -# A list of rsync mirrors is available at -# https://trac.macports.org/wiki/Mirrors#Portfiles. -# -# If an "rsync://" URL points to a .tar file, a signed .rmd160 file must -# exist in the same directory on the server and will be used to verify -# its integrity. -# -# For proper functionality of various resources (port groups, mirror -# sites, etc.), the primary MacPorts source must always be tagged -# "[default]", even if switched from the default "rsync://" URL. -rsync://rsync.macports.org/macports/release/tarballs/ports.tar [default] diff --git a/tests/sources.conf b/tests/sources.conf index efe1feb8c..6792a29a9 100644 --- a/tests/sources.conf +++ b/tests/sources.conf @@ -1,3 +1,3 @@ -# To enable your local ports repository, uncomment and customize the -# following line to point at your local ports directory -file:///tmp/macports-tests/ports [default] +# Ports tree source for the test suite. +# @TEST_ROOT@ is substituted at test time with the actual temp directory. +file://@TEST_ROOT@/ports [default] diff --git a/tests/test-macports.conf b/tests/test-macports.conf index 48f1fc9ed..f20aee680 100644 --- a/tests/test-macports.conf +++ b/tests/test-macports.conf @@ -1,13 +1,14 @@ # MacPorts system wide configuration file, tests module +# @TEST_ROOT@ is substituted at test time with the actual temp directory. # Set the directory in which to install ports -prefix /tmp/macports-tests/opt/local +prefix @TEST_ROOT@/opt/local # Where to store MacPorts working data -portdbpath /tmp/macports-tests/opt/local/var/macports +portdbpath @TEST_ROOT@/opt/local/var/macports # Where to find the sources list. -sources_conf /tmp/macports-tests/opt/local/etc/macports/sources.conf +sources_conf @TEST_ROOT@/opt/local/etc/macports/sources.conf # Extra environment variables to keep. Any variables listed here are added # to the list of variables that are not removed from the environment used diff --git a/tests/test/arch-test/test.tcl b/tests/test/arch-test/test.tcl index edac9ef0d..6b74ebca5 100644 --- a/tests/test/arch-test/test.tcl +++ b/tests/test/arch-test/test.tcl @@ -14,53 +14,41 @@ set_dir port_index proc noarch_good_test {} { - global output_file path portsrc bindir + global output_file path portsrc test_tclsh top_srcdir port_clean $path - set string "export PORTSRC=${portsrc}; " - append string "${bindir}/port -q test +declare_noarch +be_noarch" - - exec -ignorestderr sh -c $string > /dev/null 2> $output_file + exec -ignorestderr env PORTSRC=${portsrc} ${test_tclsh} ${top_srcdir}/src/port/port.tcl -q test +declare_noarch +be_noarch > /dev/null 2> $output_file set line [get_line $path/$output_file "*Mach-O files*"] return $line } proc noarch_bad_test {} { - global output_file path portsrc bindir + global output_file path portsrc test_tclsh top_srcdir port_clean $path - set string "export PORTSRC=${portsrc}; " - append string "${bindir}/port -q test +declare_noarch" - - exec -ignorestderr sh -c $string > /dev/null 2> $output_file + exec -ignorestderr env PORTSRC=${portsrc} ${test_tclsh} ${top_srcdir}/src/port/port.tcl -q test +declare_noarch > /dev/null 2> $output_file set line [get_line $path/$output_file "*Mach-O files*"] return $line } proc arch_good_test {} { - global output_file path portsrc bindir + global output_file path portsrc test_tclsh top_srcdir port_clean $path - set string "export PORTSRC=${portsrc}; " - append string "${bindir}/port -q test" - - exec -ignorestderr sh -c $string > /dev/null 2> $output_file + exec -ignorestderr env PORTSRC=${portsrc} ${test_tclsh} ${top_srcdir}/src/port/port.tcl -q test > /dev/null 2> $output_file set line [get_line $path/$output_file "*Mach-O files*"] return $line } proc arch_bad_test {} { - global output_file path portsrc bindir + global output_file path portsrc test_tclsh top_srcdir port_clean $path - set string "export PORTSRC=${portsrc}; " - append string "${bindir}/port -q test +be_noarch" - - exec -ignorestderr sh -c $string > /dev/null 2> $output_file + exec -ignorestderr env PORTSRC=${portsrc} ${test_tclsh} ${top_srcdir}/src/port/port.tcl -q test +be_noarch > /dev/null 2> $output_file set line [get_line $path/$output_file "*Mach-O files*"] return $line } diff --git a/tests/test/library.tcl.in b/tests/test/library.tcl.in index 51c118818..04463f8c6 100644 --- a/tests/test/library.tcl.in +++ b/tests/test/library.tcl.in @@ -13,26 +13,37 @@ set work_dir "work" set test_tclsh "@TEST_TCLSH@" set top_srcdir "@abs_top_srcdir@" +# Dynamic temporary root for integration tests. file tempfile generates +# a unique path under TMPDIR (or the platform default), avoiding +# collisions even with parallel or repeated runs. +close [file tempfile test_root] +file delete $test_root + # Set of procs used for testing. # Sets variables from autoconf for in-tree testing proc load_variables {pwd} { - global datadir portsrc cpwd test_tclsh top_srcdir + global portsrc cpwd test_tclsh top_srcdir test_root set cpwd [file dirname [file dirname $pwd]] - set datadir "@prefix@/share" - set portsrc ${cpwd}/test-macports.conf + set portsrc ${test_root}/macports.conf } proc cleanup {} { - global cpwd + global cpwd test_root - file delete -force /tmp/macports-tests + file delete -force $test_root file delete -force ${cpwd}/PortIndex ${cpwd}/PortIndex.quick } +# Always run cleanup at the end of cleanupTests, so $test_root is +# removed even if a test forgets the trailing `cleanup` call. +proc ::tcltest::cleanupTestsHook {} { + cleanup +} + proc without_darwintrace_env {script} { set darwintrace_env_vars { DYLD_INSERT_LIBRARIES @@ -80,32 +91,48 @@ proc with_portsrc {portsrc script} { # Sets initial directories proc set_dir {} { - global datadir cpwd top_srcdir + global cpwd top_srcdir test_root cleanup - file mkdir /tmp/macports-tests/ports \ - /tmp/macports-tests/opt/local/etc/macports \ - /tmp/macports-tests/opt/local/share \ - /tmp/macports-tests/opt/local/var/macports/receipts \ - /tmp/macports-tests/opt/local/var/macports/registry \ - /tmp/macports-tests/opt/local/var/macports/build + set prefix ${test_root}/opt/local + + file mkdir ${test_root}/ports \ + ${prefix}/etc/macports \ + ${prefix}/share \ + ${prefix}/var/macports/receipts \ + ${prefix}/var/macports/registry \ + ${prefix}/var/macports/build # Populate share/macports from the source tree instead of the prefix - file mkdir /tmp/macports-tests/opt/local/share/macports/install - file copy $top_srcdir/macports-pubkey.pem /tmp/macports-tests/opt/local/share/macports/ - file copy $top_srcdir/setupenv.bash /tmp/macports-tests/opt/local/share/macports/ - file copy $top_srcdir/doc/base.mtree /tmp/macports-tests/opt/local/share/macports/install/ - file copy $top_srcdir/doc/prefix.mtree /tmp/macports-tests/opt/local/share/macports/install/ - file copy $top_srcdir/doc/macosx.mtree /tmp/macports-tests/opt/local/share/macports/install/ - file copy $top_srcdir/keys /tmp/macports-tests/opt/local/share/macports/ - file copy ${cpwd}/sources.conf /tmp/macports-tests/opt/local/etc/macports/ - file link -symbolic /tmp/macports-tests/ports/test $cpwd/test + file mkdir ${prefix}/share/macports/install + file copy $top_srcdir/macports-pubkey.pem ${prefix}/share/macports/ + file copy $top_srcdir/setupenv.bash ${prefix}/share/macports/ + file copy $top_srcdir/doc/base.mtree ${prefix}/share/macports/install/ + file copy $top_srcdir/doc/prefix.mtree ${prefix}/share/macports/install/ + file copy $top_srcdir/doc/macosx.mtree ${prefix}/share/macports/install/ + file copy $top_srcdir/keys ${prefix}/share/macports/ + + # Copy config files, substituting the dynamic test root + foreach {src dst} [list \ + ${cpwd}/sources.conf ${prefix}/etc/macports/sources.conf \ + ${cpwd}/test-macports.conf ${test_root}/macports.conf \ + ] { + set fd [open $src r] + set content [read $fd] + close $fd + set content [string map [list @TEST_ROOT@ $test_root] $content] + set fd [open $dst w] + puts -nonewline $fd $content + close $fd + } + + file link -symbolic ${test_root}/ports/test $cpwd/test } # Run portindex proc port_index {} { - global cpwd portsrc test_tclsh top_srcdir + global cpwd portsrc test_tclsh top_srcdir test_root # Move up 2 level to run portindex. set path [pwd] @@ -121,7 +148,7 @@ proc port_index {} { } } - file copy ${cpwd}/PortIndex ${cpwd}/PortIndex.quick /tmp/macports-tests/ports/ + file copy ${cpwd}/PortIndex ${cpwd}/PortIndex.quick ${test_root}/ports/ cd $path }