blob: 37c385adfb1b6841127efa2297b35c2077fee52c [file] [log] [blame]
#!/bin/bash
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
### runs tests using bash_test_framework.sh
## Usage: fx run-shell-test [--help] <test_script_name> [--test-options...]
##
## Command options include:
## --help
## Print this message.
##
## Test options include:
## --test TEST_name
## Run only the specified test.
## --help
## Print test options.
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/vars.sh \
|| exit $?
fx-config-read
usage() {
fx-command-help
}
main() {
if (( $# == 0 )) || [[ "$1" == "--help" ]]; then
usage
return 0
fi
test_script_name="$1"; shift
local -r test_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../test" >/dev/null 2>&1 && pwd)"
local -r test_framework_dir="${test_dir}/lib"
local -r test_script_path="${test_dir}/${test_script_name}"
if [[ ! -f "${test_script_path}" ]]; then
fx-error "Test script '${test_script_path}' not found. Aborting."
return 1
fi
# propagate certain bash flags if present
shell_flags=()
if [[ $- == *x* ]]; then
shell_flags+=( -x )
fi
# Start a clean environment, load the bash_test_framework.sh,
# then start the test script.
local launch_script="$(cat << EOF
source "${test_framework_dir}/bash_test_framework.sh" || exit \$?
source "${test_script_path}" || exit \$?
EOF
)"
/usr/bin/env -i \
USER="${USER}" \
HOME="${HOME}" \
"${SHELL}" "${shell_flags[@]}" \
-c "${launch_script}" "${test_script_path}" "$@"
}; main "$@"