Skip to content

Commit

Permalink
MacOS: Porting and Test
Browse files Browse the repository at this point in the history
Need to install the following tools via brew.
 - bash
 - gnu-getopt
 - coreutils
 - findutils
 - grep
 - gnu-sed
 - fd

Tests not successful, as ZSH (and KSH) always call the old /bin/bash,
that is version 3.*. Don't understand why.
Testing with BASH works.
  • Loading branch information
rakus committed Dec 9, 2023
1 parent d1f9945 commit 4f771d4
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 52 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,26 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE
- uses: actions/checkout@v3

- name: Where is bash
shell: bash
run: find /usr/local -name bash

- name: Run Tests
shell: bash
run: |
test/run.sh all
test-macos:

runs-on: macos-latest

steps:
- uses: actions/checkout@v3

- name: Install GNU Tools
run: brew install bash gnu-getopt coreutils findutils grep gnu-sed fd

- 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
9 changes: 9 additions & 0 deletions qc-build-index
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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: 7 additions & 0 deletions test/shtest-index-qc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ script_dir="$(cd "$(dirname "$0")" && pwd)" || exit 1
set -u

if [ -n "${BASH_VERSION:-}" ]; then
# shellcheck disable=SC3044 # only executed in bash
shopt -s expand_aliases
fi

Expand Down Expand Up @@ -96,6 +97,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 +122,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 4f771d4

Please sign in to comment.