# file      : tests/common.testscript
# license   : MIT; see accompanying LICENSE file

# Commonly-used variables setup and driver command line.
#

# Use the same build system driver as the one running the tests (as opposed
# to one that may or may not be found via PATH).
#
build = $recall($build.path)

# Disable loading the user's default options files (that may affect the test
# commands execution) for bpkg and build2.
#
# Note that this works without quoting on Windows because of the effective
# escaping during the command line re-parse.
#
options_guard = $~/.build2
+mkdir $options_guard

+echo '--no-default-options' >=$options_guard/b.options
+echo '--no-default-options' >=$options_guard/bpkg.options

test.options += --default-options $options_guard \
--build $build --build-option "--default-options=$options_guard"

# Helper commands that can be used by tests to prepare the testing environment
# or validate an outcome of the command being tested. They are likely to get
# additional options and redirects appended prior to use. A common approach
# will be to redirect output to the null device for commands that are used for
# test setup, and to match it for commands being tested or performing teardown
# (for example, to make sure that configuration post-test state is valid and is
# as expected).
#
# Disable the use of the system package manager for the pkg-build command.
#
cfg_create    = [cmdline] $* cfg-create
cfg_info      = [cmdline] $* cfg-info
cfg_link      = [cmdline] $* cfg-link
cfg_unlink    = [cmdline] $* cfg-unlink
pkg_build     = [cmdline] $* pkg-build --sys-no-query
pkg_checkout  = [cmdline] $* pkg-checkout
pkg_configure = [cmdline] $* pkg-configure
pkg_disfigure = [cmdline] $* pkg-disfigure
pkg_drop      = [cmdline] $* pkg-drop
pkg_fetch     = [cmdline] $* pkg-fetch
pkg_purge     = [cmdline] $* pkg-purge
pkg_status    = [cmdline] $* pkg-status
pkg_unpack    = [cmdline] $* pkg-unpack
pkg_update    = [cmdline] $* pkg-update
rep_add       = [cmdline] $* rep-add
rep_create    = [cmdline] $* rep-create
rep_fetch     = [cmdline] $* rep-fetch
rep_info      = [cmdline] $* rep-info
rep_list      = [cmdline] $* rep-list
rep_remove    = [cmdline] $* rep-remove

# All testscripts are named after bpkg commands, for example
# pkg-verify.testscript. So the testscript scope id is a name of the command
# being tested.
#
cmd = [string] $@
test.arguments = $cmd

# Each testscript has an associated repository source directory. Its
# subdirectories are copied by tests to manipulate locally and throw away upon
# completion.
#
src = [dir_path] "$src_base/$@"
