2020-01-06 15:35:23 +08:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2021-01-02 15:10:28 +08:00
|
|
|
# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
|
2020-01-06 15:35:23 +08:00
|
|
|
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
|
|
|
|
|
|
|
#
|
|
|
|
# This script tests that Spack's tab completion scripts work.
|
|
|
|
#
|
|
|
|
# The tests are portable to bash, zsh, and bourne shell, and can be run
|
|
|
|
# in any of these shells.
|
|
|
|
#
|
|
|
|
|
|
|
|
export QA_DIR=$(dirname "$0")
|
|
|
|
export SHARE_DIR=$(cd "$QA_DIR/.." && pwd)
|
|
|
|
export SPACK_ROOT=$(cd "$QA_DIR/../../.." && pwd)
|
|
|
|
|
|
|
|
. "$QA_DIR/test-framework.sh"
|
|
|
|
|
|
|
|
# Fail on undefined variables
|
|
|
|
set -u
|
|
|
|
|
|
|
|
# Source setup-env.sh before tests
|
|
|
|
. "$SHARE_DIR/setup-env.sh"
|
|
|
|
. "$SHARE_DIR/spack-completion.$_sp_shell"
|
|
|
|
|
|
|
|
title "Testing spack-completion.$_sp_shell with $_sp_shell"
|
|
|
|
|
|
|
|
# Spack command is now available
|
|
|
|
succeeds which spack
|
|
|
|
|
|
|
|
title 'Testing all subcommands'
|
2020-12-19 09:26:15 +08:00
|
|
|
# read line into an array portably
|
|
|
|
READ="read -ra line"
|
|
|
|
if [ -n "${ZSH_VERSION:-}" ]; then
|
|
|
|
READ=(read -rA line)
|
|
|
|
fi
|
|
|
|
while IFS=' ' $READ
|
2020-01-06 15:35:23 +08:00
|
|
|
do
|
|
|
|
# Test that completion with no args works
|
2020-12-19 09:26:15 +08:00
|
|
|
succeeds _spack_completions "${line[@]}" ''
|
2020-01-06 15:35:23 +08:00
|
|
|
|
|
|
|
# Test that completion with flags works
|
2020-12-19 09:26:15 +08:00
|
|
|
contains '-h --help' _spack_completions "${line[@]}" -
|
2020-01-06 15:35:23 +08:00
|
|
|
done <<- EOF
|
|
|
|
$(spack commands --aliases --format=subcommands)
|
|
|
|
EOF
|
|
|
|
|
|
|
|
title 'Testing for correct output'
|
|
|
|
contains 'compiler' _spack_completions spack ''
|
|
|
|
contains 'install' _spack_completions spack inst
|
|
|
|
contains 'find' _spack_completions spack help ''
|
|
|
|
contains 'hdf5' _spack_completions spack list ''
|
|
|
|
contains 'py-numpy' _spack_completions spack list py-
|
|
|
|
contains 'mpi' _spack_completions spack providers ''
|
|
|
|
contains 'builtin' _spack_completions spack repo remove ''
|
|
|
|
contains 'packages' _spack_completions spack config edit ''
|
|
|
|
contains 'python' _spack_completions spack extensions ''
|
|
|
|
contains 'hdf5' _spack_completions spack -d install --jobs 8 ''
|
|
|
|
contains 'hdf5' _spack_completions spack install -v ''
|
|
|
|
|
|
|
|
# XFAIL: Fails for Python 2.6 because pkg_resources not found?
|
spack test (#15702)
Users can add test() methods to their packages to run smoke tests on
installations with the new `spack test` command (the old `spack test` is
now `spack unit-test`). spack test is environment-aware, so you can
`spack install` an environment and then run `spack test run` to run smoke
tests on all of its packages. Historical test logs can be perused with
`spack test results`. Generic smoke tests for MPI implementations, C,
C++, and Fortran compilers as well as specific smoke tests for 18
packages.
Inside the test method, individual tests can be run separately (and
continue to run best-effort after a test failure) using the `run_test`
method. The `run_test` method encapsulates finding test executables,
running and checking return codes, checking output, and error handling.
This handles the following trickier aspects of testing with direct
support in Spack's package API:
- [x] Caching source or intermediate build files at build time for
use at test time.
- [x] Test dependencies,
- [x] packages that require a compiler for testing (such as library only
packages).
See the packaging guide for more details on using Spack testing support.
Included is support for package.py files for virtual packages. This does
not change the Spack interface, but is a major change in internals.
Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
Co-authored-by: wspear <wjspear@gmail.com>
Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
2020-11-18 18:39:02 +08:00
|
|
|
#contains 'compilers.py' _spack_completions spack unit-test ''
|
2020-01-06 15:35:23 +08:00
|
|
|
|
2020-12-19 09:26:15 +08:00
|
|
|
_test_debug_functions() {
|
|
|
|
title 'Testing debugging functions'
|
|
|
|
|
|
|
|
if [ -n "${ZSH_VERSION:-}" ]; then
|
|
|
|
emulate -L sh
|
|
|
|
fi
|
|
|
|
|
|
|
|
# This is a particularly tricky case that involves the following situation:
|
|
|
|
# `spack -d [] install `
|
|
|
|
# Here, [] represents the cursor, which is in the middle of the line.
|
|
|
|
# We should tab-complete optional flags for `spack`, not optional flags for
|
|
|
|
# `spack install` or package names.
|
|
|
|
COMP_LINE='spack -d install '
|
|
|
|
COMP_POINT=9
|
|
|
|
COMP_WORDS=(spack -d install)
|
|
|
|
COMP_CWORD=2
|
|
|
|
COMP_KEY=9
|
|
|
|
COMP_TYPE=64
|
|
|
|
|
|
|
|
_bash_completion_spack
|
|
|
|
contains "--all-help" echo "${COMPREPLY[@]}"
|
|
|
|
|
|
|
|
contains "['spack', '-d', 'install', '']" _pretty_print COMP_WORDS[@]
|
|
|
|
|
|
|
|
# Set the rest of the intermediate variables manually
|
|
|
|
COMP_WORDS_NO_FLAGS=(spack install)
|
|
|
|
COMP_CWORD_NO_FLAGS=1
|
|
|
|
subfunction=_spack
|
|
|
|
cur=
|
|
|
|
|
|
|
|
list_options=true
|
|
|
|
contains "'True'" _test_vars
|
|
|
|
list_options=false
|
|
|
|
contains "'False'" _test_vars
|
|
|
|
}
|
|
|
|
_test_debug_functions
|