Skip to content

Commit

Permalink
MacOS: Porting and Test
Browse files Browse the repository at this point in the history
Need to install lots of tools via brew.

Tests not successful, as ZSH (and KSH) always call the old /bin/bash,
that is version 3.*.
Testing with BASH works.
  • Loading branch information
rakus committed Dec 9, 2023
1 parent d1f9945 commit 85987bf
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 54 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions dstore
Original file line number Diff line number Diff line change
Expand Up @@ -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'."
Expand Down
35 changes: 34 additions & 1 deletion qc-backend
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,46 @@

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

# Manual index file storing directory names and bookmarked directories. This
# 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

Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions qc-build-index
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)"
Expand Down
13 changes: 13 additions & 0 deletions test/defines.shinc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion test/shtest-index-qc.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/sh
#
# FILE: shtest-index-qc.sh
#
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
67 changes: 15 additions & 52 deletions test/test-invopt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 85987bf

Please sign in to comment.