From 695ae02aa5f349204e9ed850fc224a7a0c7bbbe7 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Sun, 5 Jan 2025 20:37:47 +0100 Subject: [PATCH] Delete sh test driver --- tests/filter-control-sequences.fish | 14 ---- tests/interactive.fish | 96 ------------------------- tests/test.fish | 71 ------------------- tests/test_driver.sh | 106 ---------------------------- tests/test_env.sh | 82 --------------------- tests/test_util.fish | 67 ------------------ 6 files changed, 436 deletions(-) delete mode 100755 tests/filter-control-sequences.fish delete mode 100755 tests/interactive.fish delete mode 100644 tests/test.fish delete mode 100755 tests/test_driver.sh delete mode 100755 tests/test_env.sh delete mode 100644 tests/test_util.fish diff --git a/tests/filter-control-sequences.fish b/tests/filter-control-sequences.fish deleted file mode 100755 index 3ed2ab5db..000000000 --- a/tests/filter-control-sequences.fish +++ /dev/null @@ -1,14 +0,0 @@ -# Remove the sorts of escape sequences interactive fish prints. - -# First the enable sequences, then a "|" combiner and then the disable ones -set -l escapes "\e\[\?2004h"\ -"\e\[>4;1m"\ -"\e\[>5u"\ -"\e="\ -"|"\ -"\e\[\?2004l"\ -"\e\[>4;0m"\ -"\e\[<1u"\ -"\e>" - -cat | string replace -ra -- $escapes '' diff --git a/tests/interactive.fish b/tests/interactive.fish deleted file mode 100755 index 18121f64c..000000000 --- a/tests/interactive.fish +++ /dev/null @@ -1,96 +0,0 @@ -#! /bin/echo "interactive.fish must be run via the test driver!" -# -# Interactive tests using `pexpect` - -# Set this var to modify behavior of the code being tests. Such as avoiding running -# `fish_update_completions` when running tests. -set -gx FISH_UNIT_TESTS_RUNNING 1 - -# Save the directory containing this script -# Do not *cd* here, otherwise you'll ruin our nice tmpdir setup!!! -set -l scriptdir (status dirname) - -# Test files specified on commandline, or all pexpect files. -if set -q argv[1] && test -n "$argv[1]" - set pexpect_files_to_test $scriptdir/pexpects/$argv -else if set -q FISH_PEXPECT_FILES - set pexpect_files_to_test (string replace -r '^.*/(?=pexpects/)' '' -- $FISH_PEXPECT_FILES) -else - say -o cyan "Testing interactive functionality" - set pexpect_files_to_test $scriptdir/pexpects/*.py -end - -source $scriptdir/test_util.fish || exit -cat $scriptdir/interactive.config >>$XDG_CONFIG_HOME/fish/config.fish -set -lx --prepend PYTHONPATH (realpath $scriptdir) - -function test_pexpect_file - set -l file $argv[1] - echo -n "Testing file $file:" - - begin - set starttime (timestamp) - set -lx TERM dumb - - # Help the script find the pexpect_helper module in our parent directory. - set -q FISHDIR - or set -l FISHDIR ../test/root/bin/ - set -lx fish $FISHDIR/fish - set -lx fish_key_reader $FISHDIR/fish_key_reader - path is -fx -- $FISHDIR/fish_test_helper - and set -lx fish_test_helper $FISHDIR/fish_test_helper - - # Note we require Python3. - python3 $file - end - - set -l exit_status $status - if test "$exit_status" -eq 0 - set test_duration (delta $starttime) - say green "ok ($test_duration $unit)" - else if test "$exit_status" -eq 127 - say blue "SKIPPED" - set exit_status 0 - end - return $exit_status -end - -set failed - -# The test here looks wrong, but False sets exit status to 0, which is what we want -if python3 -c 'import sys; exit(sys.version_info > (3, 5))' - say red "pexpect tests disabled: python3 is too old" - set pexpect_files_to_test -end -if not python3 -c 'import pexpect' - say red "pexpect tests disabled: `python3 -c 'import pexpect'` failed" - set pexpect_files_to_test -end -for i in $pexpect_files_to_test - if not test_pexpect_file $i - # Retry pexpect tests under CI twice, as they are timing-sensitive and CI resource - # contention can cause tests to spuriously fail. - if set -qx CI - say yellow "Trying $i for a second time" - if not test_pexpect_file $i - set failed $failed $i - end - else - set failed $failed $i - end - end -end - -set failed (count $failed) -if test $failed -eq 0 - if test (count $pexpect_files_to_test) -gt 1 - say green "All interactive tests completed successfully" - else - say green "$pexpect_files_to_test completed successfully" - end - exit 0 -else - set plural (test $failed -eq 1; or echo s) - say red "$failed test$plural failed" - exit 1 -end diff --git a/tests/test.fish b/tests/test.fish deleted file mode 100644 index 1298b1b6c..000000000 --- a/tests/test.fish +++ /dev/null @@ -1,71 +0,0 @@ -# Fishscript tests -# -# There is no shebang line because you shouldn't be running this by hand. You -# should be running it via `make test` to ensure the environment is properly -# setup. - -# Set this var to modify behavior of the code being tests. Such as avoiding running -# `fish_update_completions` when running tests. -set -x FISH_UNIT_TESTS_RUNNING 1 - -# Save the directory containing this script -# Do not *cd* here, otherwise you'll ruin our nice tmpdir setup!!! -set -l scriptdir (status dirname) - -# Test files specified on commandline, or all checks. -set -l files_to_test -if set -q argv[1] - set files_to_test $scriptdir/checks/$argv.fish -else - set files_to_test $scriptdir/checks/*.fish -end - -# Be less verbose when running tests one-by-one -if test (count $files_to_test) -gt 1 - say -o cyan "Testing high level script functionality" -end - -set -g python (__fish_anypython) -or begin - say red "Python is not installed. These tests require python." - exit 125 -end - -set -q FISHDIR -or set -l FISHDIR ../test/root/bin - -# Test littlecheck files. -set -l skipped 0 -set -l failed 0 -if set -q files_to_test[1] - set -l force_color - test "$FISH_FORCE_COLOR" = 1 - and set force_color --force-color - - $python -S $scriptdir/littlecheck.py \ - --progress $force_color \ - -s fish=$FISHDIR/fish \ - -s fish_test_helper=$fish_test_helper \ - -s filter-control-sequences="$scriptdir/filter-control-sequences.fish" \ - $files_to_test - - set -l littlecheck_status $status - if test "$littlecheck_status" -eq 125 - # 125 indicates that all tests executed were skipped. - set skipped (count $files_to_test) - else - # The return code indicates the number of tests that failed - set failed $littlecheck_status - end -end - -if test $failed -eq 0 && test $skipped -gt 0 - test (count $files_to_test) -gt 1 && say blue (count $files_to_test)" tests skipped" - exit 125 -else if test $failed -eq 0 - test (count $files_to_test) -gt 1 && say green "All high level script tests completed successfully" - exit 0 -else - test (count $files_to_test) -gt 1 && say red "$failed tests failed" - exit 1 -end diff --git a/tests/test_driver.sh b/tests/test_driver.sh deleted file mode 100755 index 86a84a002..000000000 --- a/tests/test_driver.sh +++ /dev/null @@ -1,106 +0,0 @@ -#!/bin/sh -# vim: set ts=4 sw=4 tw=100 et: - -# POSIX sh test driver to reduce dependency on fish in tests. -# Executes the specified *fish script* with the provided arguments, after setting up a clean test -# environment (see `test_env.sh`) and then importing the fish-related helper functions and -# performing some state initialization required by the various fish tests. Each payload script is -# executed in its own environment, this script waits for fish to exit then cleans up the target -# environment and bubbles up the fish exit code. - -# macOS has really weird default IFS behavior that splits output in random places, and the trailing -# backspace is to prevent \n from being gobbled up by the subshell output substitution. -# Folks, this is why you should use fish! -IFS="$(printf "\n\b")" - -# If CDPATH is set, `cd foo` will print the directory. -unset CDPATH - -# The first argument is the path to the script to launch; all remaining arguments are forwarded to -# the script. -# Resolve the script now because we are going to `cd` later. -fish_script="$(realpath $1)" -shift 1 - -die() { - if test "$#" -ge 0; then - printf "%s\n" "$@" 1>&2 - fi - exit 1 -} - -# To keep things sane and to make error messages comprehensible, do not use relative paths anywhere -# in this script. Instead, make all paths relative to one of these or the new $HOME ($homedir)." -TESTS_ROOT="$(cd $(dirname "$0") && pwd -P)" -BUILD_ROOT="$(cd $(dirname "$TESTS_ROOT") && pwd -P)" - -if test -z "$FISHDIR"; then - die "Please set \$FISHDIR to a directory that contains fish, fish_indent and fish_key_reader" -fi - -FISHDIR=$(realpath -- "$FISHDIR") -fish="${FISHDIR}/fish" - -if ! test -x "$fish" || ! test -f "$fish"; then - printf '%s\n' "'$fish' is not an executable fish." \ - "Please set \$FISHDIR to a directory that contains fish, fish_indent and fish_key_reader" >&2 - exit 7 -fi - -if ! test -z "$__fish_is_running_tests"; then - echo "Recursive test invocation detected!" 1>&2 - exit 10 -fi - -# Set up the test environment. Does not change the current working directory. -. ${TESTS_ROOT}/test_env.sh - -test -n "$homedir" || die "Failed to set up home" - -# Compile our fish_test_helper program now. -# This takes about 50ms. -if command -v cc >/dev/null ; then - cc "$TESTS_ROOT/fish_test_helper.c" -o "$homedir/fish_test_helper" -else - echo "Cannot find a C compiler. Skipping tests that require fish_test_helper" >&2 -fi - -# These are used read-only so it's OK to symlink instead of copy -rm -f "$XDG_CONFIG_HOME/fish/functions" -ln -s "${TESTS_ROOT}/test_functions" "$XDG_CONFIG_HOME/fish/functions" || die "Failed to symlink" - -# Set the function path at startup, referencing the default fish functions and the test-specific -# functions. -fish_init_cmd="set fish_function_path '${XDG_CONFIG_HOME}/fish/functions' '${BUILD_ROOT}/share/functions'" - -__fish_is_running_tests="$homedir" -export __fish_is_running_tests - -# Set a marker to indicate whether colored output should be suppressed (used in `test_util.fish`) -suppress_color="" -if ! tty 0>&1 > /dev/null; then - suppress_color="yes" -fi -export suppress_color - -# Source test util functions at startup -fish_init_cmd="${fish_init_cmd} && source ${TESTS_ROOT}/test_util.fish"; - -# Indicate that the fish panic handler shouldn't wait for input to prevent tests from hanging -FISH_FAST_FAIL=1 -export FISH_FAST_FAIL - -# Run the test script, but don't exec so we can clean up after it succeeds/fails. Each test is -# launched directly within its TMPDIR, so that the fish tests themselves do not need to refer to -# TMPDIR (to ensure their output as displayed in case of failure by littlecheck is reproducible). -if test -n "${@}"; then - (cd $TMPDIR && env HOME="$homedir" fish_test_helper="$homedir/fish_test_helper" "$fish" \ - --init-command "${fish_init_cmd}" "$fish_script" "${@}") -else - (cd $TMPDIR && env HOME="$homedir" fish_test_helper="$homedir/fish_test_helper" "$fish" \ - --init-command "${fish_init_cmd}" "$fish_script") -fi -test_status="$?" - -rm -rf "$homedir" -exit "$test_status" diff --git a/tests/test_env.sh b/tests/test_env.sh deleted file mode 100755 index 18bea82f5..000000000 --- a/tests/test_env.sh +++ /dev/null @@ -1,82 +0,0 @@ -# vim: set ts=4 sw=4 tw=100 et: - -# This script sets up a clean environment for a script or executable to execute in/under. It creates -# (and sets) $TMPDIR initialized to a clean & unique temporary directory, creates a new $HOME, sets -# the relevant XDG_* directories to point to subdirectories of that $HOME, cleans up any potentially -# problematic environment variables, executes the provided command, waits for it to exit, then -# cleans up the newly created environment before bubbling up the exit code. $PWD is not changed. -# If sourced instead of executed, sets up the environment as before but does not execute any payload -# and does not destroy the newly created environment. - -# macOS has really weird default IFS behavior that splits output in random places, and the trailing -# backspace is to prevent \n from being gobbled up by the subshell output substitution. -# Folks, this is why you should use fish! -IFS="$(printf "\n\b")" -# set -ex - -die() { - if test "$#" -ge 0; then - printf "%s\n" "$@" 1>&2 - fi - exit 1 -} - -# Set up a test environment to run the specified target under. We do not share environments -# whatsoever between tests, so each test driver run sets up a new profile altogether. - -# macOS 10.10 requires an explicit template for `mktemp` and will create the folder in the -# current directory unless told otherwise. Linux isn't guaranteed to have $TMPDIR set. -homedir="$(mktemp -d 2>/dev/null || mktemp -d "${TMPDIR}tmp.XXXXXXXXXX")" -export HOME="$homedir" - -XDG_DATA_HOME="$homedir/xdg_data_home" -export XDG_DATA_HOME -mkdir -p $XDG_DATA_HOME/fish || die - -XDG_CONFIG_HOME="$homedir/xdg_config_home" -export XDG_CONFIG_HOME -mkdir -p $XDG_CONFIG_HOME/fish || die - -XDG_RUNTIME_DIR="$homedir/xdg_runtime_dir" -export XDG_RUNTIME_DIR -mkdir -p $XDG_RUNTIME_DIR/fish || die -chmod 700 "$XDG_RUNTIME_DIR" - -XDG_CACHE_HOME="$homedir/xdg_cache_home" -export XDG_CACHE_HOME -mkdir -p $XDG_CACHE_HOME/fish || die - -# Create a temp/scratch directory for tests to use, if they want (tests shouldn't write to a -# shared temp folder). -TMPDIR="$homedir/temp" -mkdir ${TMPDIR} -export TMPDIR - -# Set locale information for consistent tests. Fish should work with a lot of locales but the -# tests assume an english UTF-8 locale unless they explicitly override this default. We do not -# want the users locale to affect the tests since they might, for example, change the wording of -# logged messages. -# -# TODO: set LANG to en_US.UTF-8 so we test the locale message conversions (i.e., gettext). -unset LANGUAGE -# Remove "LC_" env vars from the test environment -for key in $(env | grep -E "^LC_"| grep -oE "^[^=]+"); do - unset "$key" -done -# Set the desired lang/locale tests are hard-coded against -export LANG="C" -export LC_CTYPE="en_US.UTF-8" - -# These env vars should not be inherited from the user environment because they can affect the -# behavior of the tests. So either remove them or set them to a known value. -# See also tests/interactive.fish. -export TERM=xterm -unset COLORTERM -unset KONSOLE_PROFILE_NAME -unset KONSOLE_VERSION -unset PANTHEON_TERMINAL_ID -unset LC_TERMINAL -unset LC_TERMINAL_VERSION -unset TERM_PROGRAM -unset TERM_PROGRAM_VERSION -unset VTE_VERSION diff --git a/tests/test_util.fish b/tests/test_util.fish deleted file mode 100644 index f5fa338ee..000000000 --- a/tests/test_util.fish +++ /dev/null @@ -1,67 +0,0 @@ -# vim: set ts=4 sw=4 tw=100 et: -# Utilities for the test runners - -function die - set -q argv[1]; and echo $argv[1] >&2 - exit 1 -end - -# $suppress_color is set by `test_driver.sh` (via import of exported variables) -function say -V suppress_color - set -l color_flags - set -l suppress_newline - while set -q argv[1] - switch $argv[1] - case -b -o -u - set color_flags $color_flags $argv[1] - case -n - set suppress_newline 1 - case -- - set -e argv[1] - break - case -\* - continue - case \* - break - end - set -e argv[1] - end - - if not set -q argv[2] - echo 'usage: say [flags] color string [string...]' >&2 - return 1 - end - - if begin - test -n "$suppress_color"; or set_color $color_flags $argv[1] - end - printf '%s' $argv[2..-1] - test -z "$suppress_color"; and set_color normal - if test -z "$suppress_newline" - echo - end - end -end - -# lame timer -for program in {g,}date - if command -q $program && $program --version 1>/dev/null 2>/dev/null - set -g milli $program - set -g unit ms - break - else - set -g unit sec - end -end - -function timestamp - set -q milli[1] - and $milli +%s%3N - or date +%s -end - -function delta - set -q milli[1] - and math "( "($milli +%s%3N)" - $argv[1])" - or math (date +%s) - $argv[1] -end