mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 12:41:08 +08:00
Revert "tests/invocation.sh: Port to sh (from bash)"
This reverts commit 9aa8740c36
, which broke on macOS.
If anyone wants to try, feel free to do so!
This commit is contained in:
parent
9aa8740c36
commit
fc5e8f9fec
|
@ -1,4 +1,4 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
##
|
||||
# Test that the invocation of the fish executable works as we hope.
|
||||
#
|
||||
|
@ -57,6 +57,13 @@
|
|||
# Errors will be fatal
|
||||
set -e
|
||||
|
||||
# If any command in the pipeline fails report the rc of the first fail.
|
||||
set -o pipefail
|
||||
|
||||
# If nothing matches a glob expansion, return nothing (not the glob
|
||||
# itself)
|
||||
shopt -s nullglob
|
||||
|
||||
# The directory this script is in (as everything is relative to here)
|
||||
here="$(cd "$(dirname "$0")" && pwd -P)"
|
||||
cd "$here"
|
||||
|
@ -64,6 +71,9 @@ cd "$here"
|
|||
# The temporary directory to use
|
||||
temp_dir="$here/../test"
|
||||
|
||||
# The files we're going to execute are in the 'invocation' directory.
|
||||
files_to_test=($(echo invocation/*.invoke))
|
||||
|
||||
# The fish binary we are testing - for manual testing, may be overridden
|
||||
fish_exe="${fish_exe:-../test/root/bin/fish}"
|
||||
fish_dir="$(dirname "${fish_exe}")"
|
||||
|
@ -79,7 +89,7 @@ system_name="$(uname -s)"
|
|||
|
||||
# Check whether we have the 'colordiff' tool - if not, we'll revert to
|
||||
# boring regular 'diff'.
|
||||
if command -v colordiff >/dev/null 2>&1; then
|
||||
if [ "$(type -t colordiff)" != '' ] ; then
|
||||
difftool='colordiff'
|
||||
else
|
||||
difftool='diff'
|
||||
|
@ -89,7 +99,7 @@ fi
|
|||
##
|
||||
# Set variables to known values so that they will not affect the
|
||||
# execution of the test.
|
||||
clean_environment() {
|
||||
function clean_environment() {
|
||||
|
||||
# Reset the terminal variables to a known type.
|
||||
export TERM=xterm
|
||||
|
@ -109,41 +119,27 @@ clean_environment() {
|
|||
|
||||
##
|
||||
# Fail completely :-(
|
||||
fail() {
|
||||
say "$term_red" "FAIL: $*" >&2
|
||||
function fail() {
|
||||
say red "FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
##
|
||||
# Coloured output
|
||||
#
|
||||
# Use like `say "$term_green" "message".
|
||||
say() {
|
||||
echo "$1$2$term_reset"
|
||||
function say() {
|
||||
local color_name="$1"
|
||||
local msg="$2"
|
||||
local color_var="term_${color_name}"
|
||||
local color="${!color_var}"
|
||||
|
||||
echo "$color$msg$term_reset"
|
||||
}
|
||||
|
||||
run_rc() {
|
||||
# Write the return code on to the end of the stderr, so that it can be
|
||||
# checked like anything else.
|
||||
eval "$*" || echo "RC: $?" >&2
|
||||
}
|
||||
|
||||
filter() {
|
||||
# In some cases we want to check only a part of the output.
|
||||
# For those we filter the output through grep'd matches.
|
||||
if [ -f "$1" ] ; then
|
||||
# grep '-o', '-E' and '-f' are supported by the tools in modern GNU
|
||||
# environments, and on OS X.
|
||||
grep -oE -f "$1"
|
||||
else
|
||||
cat
|
||||
fi
|
||||
}
|
||||
|
||||
##
|
||||
# Actual testing of a .invoke file.
|
||||
test_file() {
|
||||
function test_file() {
|
||||
local file="$1"
|
||||
local dir="$(dirname "$file")"
|
||||
local base="$(basename "$file" .invoke)"
|
||||
|
@ -154,7 +150,7 @@ test_file() {
|
|||
local grep_stdout="${dir}/${base}.grep"
|
||||
local want_stderr="${dir}/${base}.err"
|
||||
local empty="${dir}/${base}.empty"
|
||||
local filter
|
||||
local -a filter
|
||||
local rc=0
|
||||
local test_args_literal
|
||||
local test_args
|
||||
|
@ -195,6 +191,16 @@ test_file() {
|
|||
rm -f "${temp_dir}/home/fish/config.fish"
|
||||
fi
|
||||
|
||||
# In some cases we want to check only a part of the output.
|
||||
# For those we filter the output through grep'd matches.
|
||||
if [ -f "$grep_stdout" ] ; then
|
||||
# grep '-o', '-E' and '-f' are supported by the tools in modern GNU
|
||||
# environments, and on OS X.
|
||||
filter=('grep' '-o' '-E' '-f' "$grep_stdout")
|
||||
else
|
||||
filter=('cat')
|
||||
fi
|
||||
|
||||
echo -n "Testing file $file ${system_specific:+($system_name specific) }... "
|
||||
|
||||
# The hoops we are jumping through here, with changing directory are
|
||||
|
@ -204,13 +210,20 @@ test_file() {
|
|||
# We disable the exit-on-error here, so that we can catch the return
|
||||
# code.
|
||||
set +e
|
||||
run_rc "cd \"$fish_dir\" && \"./$fish_leaf\" $test_args" \
|
||||
eval "cd \"$fish_dir\" && \"./$fish_leaf\" $test_args" \
|
||||
2> "$test_stderr" \
|
||||
< /dev/null \
|
||||
| filter "$grep_stdout" \
|
||||
| ${filter[*]} \
|
||||
> "$test_stdout"
|
||||
rc="$?"
|
||||
set -e
|
||||
|
||||
if [ "$rc" != '0' ] ; then
|
||||
# Write the return code on to the end of the stderr, so that it can be
|
||||
# checked like anything else.
|
||||
echo "RC: $rc" >> "${test_stderr}"
|
||||
fi
|
||||
|
||||
# If the wanted output files are not present, they are assumed empty.
|
||||
if [ ! -f "$want_stdout" ] ; then
|
||||
want_stdout="$empty"
|
||||
|
@ -225,9 +238,9 @@ test_file() {
|
|||
# However, fish will also have helpfully translated the home directory
|
||||
# into '~/' in the error report. Consequently, we need to perform a
|
||||
# small fix-up so that we can replace the string sanely.
|
||||
xdg_config_in_home="${XDG_CONFIG_HOME#$HOME}"
|
||||
if [ "${#xdg_config_in_home}" -lt "${#XDG_CONFIG_HOME}" ]; then
|
||||
xdg_config_in_home="~$xdg_config_in_home"
|
||||
xdg_config_in_home="$XDG_CONFIG_HOME"
|
||||
if [ "${xdg_config_in_home:0:${#HOME}}" = "${HOME}" ] ; then
|
||||
xdg_config_in_home="~/${xdg_config_in_home:${#HOME}+1}"
|
||||
fi
|
||||
# 'sed -i' (inplace) has different syntax on BSD and GNU versions of
|
||||
# the tool, so cannot be used here, hence we write to a separate file,
|
||||
|
@ -245,20 +258,20 @@ test_file() {
|
|||
|
||||
if [ "$out_status" = '0' ] && \
|
||||
[ "$err_status" = '0' ] ; then
|
||||
say "$term_green" "ok"
|
||||
say green "ok"
|
||||
# clean up tmp files
|
||||
rm -f "${test_stdout}" "${test_stderr}" "${empty}"
|
||||
rc=0
|
||||
else
|
||||
say "$term_red" "fail"
|
||||
say "$term_blue" "$test_args_literal" | sed 's/^/ /'
|
||||
say red "fail"
|
||||
say blue "$test_args_literal" | sed 's/^/ /'
|
||||
|
||||
if [ "$out_status" != '0' ] ; then
|
||||
say "$term_yellow" "Output differs for file $file. Diff follows:"
|
||||
say yellow "Output differs for file $file. Diff follows:"
|
||||
"$difftool" -u "${test_stdout}" "${want_stdout}"
|
||||
fi
|
||||
if [ "$err_status" != '0' ] ; then
|
||||
say "$term_yellow" "Error output differs for file $file. Diff follows:"
|
||||
say yellow "Error output differs for file $file. Diff follows:"
|
||||
"$difftool" -u "${test_stderr}" "${want_stderr}"
|
||||
fi
|
||||
rc=1
|
||||
|
@ -299,11 +312,11 @@ if command -v tput >/dev/null 2>&1; then
|
|||
term_reset="$(tput sgr0)"
|
||||
fi
|
||||
|
||||
say "$term_cyan" "Testing shell invocation functionality"
|
||||
say cyan "Testing shell invocation functionality"
|
||||
|
||||
passed=0
|
||||
failed=0
|
||||
for file in invocation/*.invoke; do
|
||||
for file in ${files_to_test[*]} ; do
|
||||
if ! test_file "$file" ; then
|
||||
failed=$(( failed + 1 ))
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue
Block a user