diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e148a2e..42aec7e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,3 +57,30 @@ jobs: shell: bash run: | test/run.sh all + + test-macos: + + runs-on: macos-latest + + continue-on-error: true + + steps: + # Checks-out your repository under $GITHUB_WORKSPACE + - uses: actions/checkout@v3 + + - name: Install Shells & Shellcheck (macos only) + run: brew install bash shellcheck gnu-getopt coreutils findutils fd grep gnu-sed + + - name: Prepare .zshenv + shell: bash + run: | + echo "export PATH=\"/usr/local/bin:\$PATH\"" >> "$HOME/.zshenv" + cat "$HOME/.zshenv" + + - name: Run test-args2regex + shell: bash + run: zsh -i test/shtest-index-qc.sh + + - name: Run All Tests + shell: bash + run: test/run.sh all diff --git a/dstore b/dstore index 460074d..22cde6a 100755 --- a/dstore +++ b/dstore @@ -20,6 +20,15 @@ qc_version=2.0 # file is managed using the command 'dstore'. QC_DSTORE_INDEX=$QC_DIR/index.dstore +if [ "$(uname)" == "Darwin" ]; then + PATH="/usr/local/opt/gnu-getopt/bin:$PATH" + PATH="/usr/local/opt/findutils/libexec/gnubin:$PATH" + PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" + PATH="/usr/local/opt/grep/libexec/gnubin:$PATH" + PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH" + export PATH +fi + show_help() { echo "Manually manage content of $QC_DSTORE_INDEX for usage with 'qc'." diff --git a/qc-backend b/qc-backend index 61455f1..fb9f8c1 100755 --- a/qc-backend +++ b/qc-backend @@ -9,6 +9,30 @@ qc_version=2.0 +{ + $BASH --version + echo "===================" + /usr/bin/env -vvv | grep -i PATH + echo "===================" + echo "BASH: '$BASH'" + echo "BASHOPTS: '$BASHOPTS'" + echo "BASHPID: '$BASHPID'" + echo "BASHRCSOURCED: '$BASHRCSOURCED'" + echo "BASH_ARGC: '$BASH_ARGC'" + echo "BASH_ARGV: '$BASH_ARGV'" + echo "BASH_ARGV0: '$BASH_ARGV0'" + echo "BASH_CMDS: '$BASH_CMDS'" + echo "BASH_COMMAND: '$BASH_COMMAND'" + echo "BASH_COMPLETION_VERSINFO: '$BASH_COMPLETION_VERSINFO'" + echo "BASH_LINENO: '$BASH_LINENO'" + echo "BASH_LOADABLES_PATH: '$BASH_LOADABLES_PATH'" + echo "BASH_REMATCH: '$BASH_REMATCH'" + echo "BASH_SOURCE: '$BASH_SOURCE'" + echo "BASH_SUBSHELL: '$BASH_SUBSHELL'" + echo "BASH_VERSINFO: '$BASH_VERSINFO'" + echo "BASH_VERSION: '$BASH_VERSION'" +} >&2 + # Directory for qc index files [ -z "${QC_DIR:-}" ] && QC_DIR=$HOME/.qc @@ -16,6 +40,15 @@ qc_version=2.0 # file is managed using the command 'dstore'. QC_DSTORE_INDEX=$QC_DIR/index.dstore +if [ "$(uname)" = "Darwin" ]; then + PATH="/usr/local/opt/gnu-getopt/bin:$PATH" + PATH="/usr/local/opt/findutils/libexec/gnubin:$PATH" + PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" + PATH="/usr/local/opt/grep/libexec/gnubin:$PATH" + PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH" + export PATH +fi + # error on unset variable set -u @@ -401,7 +434,7 @@ updateIndex() typeset PATH="$QC_DIR:$PATH" if command -v qc-build-index &>/dev/null; then echo "Updating index ..." - typeset -a ARGS + typeset -a ARGS=() typeset d for d in "$@"; do if [ "$d" = "-E" ]; then diff --git a/qc-build-index b/qc-build-index index fcce4e1..d36d9ab 100755 --- a/qc-build-index +++ b/qc-build-index @@ -24,6 +24,26 @@ script_dir="$(cd "$(dirname "$0")" && pwd)" || exit 1 script_name="$(basename "$0")" script_file="$script_dir/$script_name" +{ + echo "BASH: '$BASH'" + echo "BASHOPTS: '$BASHOPTS'" + echo "BASHPID: '$BASHPID'" + echo "BASHRCSOURCED: '$BASHRCSOURCED'" + echo "BASH_ARGC: '$BASH_ARGC'" + echo "BASH_ARGV: '$BASH_ARGV'" + echo "BASH_ARGV0: '$BASH_ARGV0'" + echo "BASH_CMDS: '$BASH_CMDS'" + echo "BASH_COMMAND: '$BASH_COMMAND'" + echo "BASH_COMPLETION_VERSINFO: '$BASH_COMPLETION_VERSINFO'" + echo "BASH_LINENO: '$BASH_LINENO'" + echo "BASH_LOADABLES_PATH: '$BASH_LOADABLES_PATH'" + echo "BASH_REMATCH: '$BASH_REMATCH'" + echo "BASH_SOURCE: '$BASH_SOURCE'" + echo "BASH_SUBSHELL: '$BASH_SUBSHELL'" + echo "BASH_VERSINFO: '$BASH_VERSINFO'" + echo "BASH_VERSION: '$BASH_VERSION'" +} >&2 + set -u qc_version=2.0 @@ -35,6 +55,15 @@ CFG="$QC_DIR/qc-index.cfg" typeset -a TMP_FILES=() +if [ "$(uname)" = "Darwin" ]; then + PATH="/usr/local/opt/gnu-getopt/bin:$PATH" + PATH="/usr/local/opt/findutils/libexec/gnubin:$PATH" + PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" + PATH="/usr/local/opt/grep/libexec/gnubin:$PATH" + PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH" + export PATH +fi + # Detect the fd executable name. On Debian/Ubuntu the executable is named # 'fdfind' to prevent a name clash with another tool (package fdclone). FD_CMD="$(command -v fdfind)" diff --git a/test/defines.shinc b/test/defines.shinc index 76112f6..0910ebf 100644 --- a/test/defines.shinc +++ b/test/defines.shinc @@ -4,6 +4,15 @@ export __QC_TEST__=true set -u +if [ "$(uname)" = "Darwin" ]; then + PATH="/usr/local/opt/gnu-getopt/bin:$PATH" + PATH="/usr/local/opt/findutils/libexec/gnubin:$PATH" + PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" + PATH="/usr/local/opt/grep/libexec/gnubin:$PATH" + PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH" + export PATH +fi + if [ -z "${script_dir:-}" ]; then echo "" echo "ERROR: required variable \$script_dir\" is not set" @@ -126,6 +135,10 @@ trap "onExit" EXIT TEST_DIRECTORY="/tmp/qc-testDirectory" [ -d "$TEST_DIRECTORY" ] && rm -rf "$TEST_DIRECTORY" + +mkdir -p "$TEST_DIRECTORY" +TEST_DIRECTORY="$(readlink -e "/tmp/qc-testDirectory")" + mkdir -p "$TEST_DIRECTORY/.qc" export QC_DIR="$TEST_DIRECTORY"/.qc diff --git a/test/shtest-index-qc.sh b/test/shtest-index-qc.sh index 330c92b..aded4ba 100755 --- a/test/shtest-index-qc.sh +++ b/test/shtest-index-qc.sh @@ -1,4 +1,3 @@ -#!/bin/sh # # FILE: shtest-index-qc.sh # @@ -96,6 +95,9 @@ if [ $expected_cnt -eq "$(wc -l < "$TEST_DIRECTORY/.qc/test.index")" ]; then OK else ERROR + echo "------------------" + cat "$TEST_DIRECTORY/.qc/test.index" + echo "------------------" fi printf "test.index.hidden exists" @@ -118,6 +120,9 @@ if [ $expected_cnt -eq "$(wc -l < "$TEST_DIRECTORY/.qc/test.index.hidden")" ]; t OK else ERROR + echo "------------------" + cat "$TEST_DIRECTORY/.qc/test.index" + echo "------------------" fi printf "index.dstore exists" diff --git a/test/test-invopt.sh b/test/test-invopt.sh index d1c59ff..beb30f9 100755 --- a/test/test-invopt.sh +++ b/test/test-invopt.sh @@ -18,60 +18,23 @@ set -u # shellcheck source=./defines.shinc . "${script_dir}/defines.shinc" -# -# Adjust to different versions of /bin/getopt -# Maybe it is a bad idea to check for this error messages -# -if getopt "o" -D 2>&1 | grep -q invalid; then - # "newer version e.g 2.37.4 - invShortOpt="invalid option -- '%c'" - invLongOpt="unrecognized option '--%s'" -else - invShortOpt="unknown option -- %c" - invLongOpt="unknown option -- %s" -fi - - - +check_inv_opt_detected() +{ + printf "%s " "$@" + if "$@" 2>&1 | grep -q "Try '[^ ]* --help' for more information."; then + OK + else + ERROR + fi +} startTest "Invalid option detection" -printf "qc -Z" -if qc-backend -Z 2>&1 | grep -q "$(printf "$invShortOpt" Z)"; then - OK -else - ERROR -fi -printf "dstore -Z" -if dstore -Z 2>&1 | grep -q "$(printf "$invShortOpt" Z)"; then - OK -else - ERROR -fi -printf "qc-build-index -Z" -if qc-build-index -Z 2>&1 | grep -q "$(printf "$invShortOpt" Z)"; then - OK -else - ERROR -fi - -printf "qc --wrong" -if qc-backend --wrong 2>&1 | grep -q "$(printf "$invLongOpt" wrong)"; then - OK -else - ERROR -fi -printf "dstore --wrong" -if dstore --wrong 2>&1 | grep -q "$(printf "$invLongOpt" wrong)"; then - OK -else - ERROR -fi -printf "qc-build-index --wrong" -if qc-build-index --wrong 2>&1 | grep -q "$(printf "$invLongOpt" wrong)"; then - OK -else - ERROR -fi +check_inv_opt_detected qc-backend -Z +check_inv_opt_detected dstore -Z +check_inv_opt_detected qc-build-index -Z +check_inv_opt_detected qc-backend --wrong +check_inv_opt_detected dstore --wrong +check_inv_opt_detected qc-build-index --wrong endTest