Skip to content

Commit

Permalink
Internal use commands fall back to POSIX version
Browse files Browse the repository at this point in the history
Workaround for Solaris 10 minimum configuration not including od command
  • Loading branch information
ko1nksm committed May 13, 2024
1 parent 088c98a commit 166e4f0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
2 changes: 2 additions & 0 deletions helper/ksh_workaround.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ ksh_workaround_loaded() {
shellspec_redefinable shellspec_fds_check
shellspec_redefinable shellspec_readfile_once
shellspec_redefinable shellspec_head
shellspec_redefinable shellspec_od
shellspec_redefinable shellspec_hexdump

# for ksh88 and busybox-1.1.3
# These shells do not allow built-in commands cannot be redefined
Expand Down
2 changes: 2 additions & 0 deletions lib/general.sh
Original file line number Diff line number Diff line change
Expand Up @@ -944,3 +944,5 @@ shellspec_mv() { "$SHELLSPEC_MV" "$@"; }
shellspec_rm() { "$SHELLSPEC_RM" "$@"; }
shellspec_chmod() { "$SHELLSPEC_CHMOD" "$@"; }
shellspec_sleep() { "$SHELLSPEC_SLEEP" "$@"; }
shellspec_od() { "$SHELLSPEC_OD" "$@"; }
shellspec_hexdump() { "$SHELLSPEC_HEXDUMP" "$@"; }
6 changes: 3 additions & 3 deletions lib/libexec/binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# busybox 1.1.3: `-A n`, `-t o1` not supported
# busybox 1.10.2: `od -b` not working properly
od_command() {
od -t o1 -v 2>/dev/null && return 0
[ $? -eq 127 ] && hexdump -b -v 2>/dev/null && return 0
od -b -v
shellspec_od -t o1 -v 2>/dev/null && return 0
[ $? -eq 127 ] && shellspec_hexdump -b -v 2>/dev/null && return 0
shellspec_od -b -v
}

octal_dump() {
Expand Down
11 changes: 6 additions & 5 deletions lib/libexec/shellspec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ current_shell() {

# shellcheck disable=SC2295
command_path() {
if [ $# -lt 2 ]; then
set -- "" "$1" "${PATH}${SHELLSPEC_PATHSEP}"
else
set -- "$1" "$2" "${PATH}${SHELLSPEC_PATHSEP}"
fi
case $# in
0 | 1) set -- "" "$1" ;;
*) set -- "$1" "$2" ;;
esac
set -- "$1" "$2" "$PATH" "$SHELLSPEC_POSIX_PATH" "$SHELLSPEC_PATHSEP"
set -- "$1" "$2" "${3}${4:+"$5"}${4}${5}"

case $2 in (*/*)
[ -x "$2" ] || return 1
Expand Down
8 changes: 8 additions & 0 deletions shellspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fi
export SHELLSPEC_VERSION='0.29.0-dev'
export SHELLSPEC_CWD="$PWD"
export SHELLSPEC_PATH=''
export SHELLSPEC_POSIX_PATH=''
export SHELLSPEC_GRAMMAR_DSLS=''
export SHELLSPEC_GRAMMAR_DIRECTIVES=''
export SHELLSPEC_GRAMMAR_BLOCKS=''
Expand Down Expand Up @@ -87,6 +88,10 @@ export SHELLSPEC_RM="rm"
export SHELLSPEC_LS="ls"
export SHELLSPEC_SORT="sort"
export SHELLSPEC_FIND="find"
export SHELLSPEC_OD="od"
export SHELLSPEC_HEXDUMP="hexdump"

SHELLSPEC_POSIX_PATH=$(getconf PATH 2>/dev/null) ||:

#shellcheck disable=SC2039,SC3028
export SHELLSPEC_HOSTNAME="${HOSTNAME:-localhost}"
Expand Down Expand Up @@ -229,6 +234,7 @@ abspath SHELLSPEC_PROJECT_ROOT "$SHELLSPEC_PROJECT_ROOT"
eval "set -- $params"
}

# shellcheck disable=SC2153
case $SHELLSPEC_MODE in (init)
SHELLSPEC_PROJECT_ROOT=${SHELLSPEC_PROJECT_ROOT:-$SHELLSPEC_CWD}
helperdir=$SHELLSPEC_HELPERDIR
Expand Down Expand Up @@ -402,6 +408,8 @@ fi
command_path SHELLSPEC_LS "ls" ||:
command_path SHELLSPEC_SORT "sort" ||:
command_path SHELLSPEC_FIND "find" ||:
command_path SHELLSPEC_OD "od" ||:
command_path SHELLSPEC_HEXDUMP "hexdump" ||:

if command_path "time" || [ "$SHELLSPEC_BUSYBOX_W32" ]; then
SHELLSPEC_TIME="time -p"
Expand Down
11 changes: 4 additions & 7 deletions spec/libexec/binary_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Describe "libexec/binary.sh"
Include "$SHELLSPEC_LIB/libexec/binary.sh"

Describe 'od_command()'
od() { echo "od"; }
hexdump() { echo "hexdump"; }
shellspec_od() { echo "od"; }
shellspec_hexdump() { echo "hexdump"; }

Context "when od command available"
It 'calls od command'
Expand All @@ -15,15 +15,15 @@ Describe "libexec/binary.sh"
End

Context "when od command not available"
od() { echo "od: command not found" >&2; return 127; }
shellspec_od() { echo "od: command not found" >&2; return 127; }
It 'calls hexdump command'
When call od_command
The stdout should eq 'hexdump'
End
End

Context "when tod command does not support -t option"
od() {
shellspec_od() {
[ "$1" = "-t" ] && return 1
echo "od" "$@"
}
Expand All @@ -35,9 +35,6 @@ Describe "libexec/binary.sh"
End

Describe 'octal_dump()'
od() { @od "$@"; }
hexdump() { @hexdump "$@"; }

It 'outputs as octal number'
Data "abc"
When call octal_dump
Expand Down

0 comments on commit 166e4f0

Please sign in to comment.