Skip to content

Commit

Permalink
Add support for ksh.
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhujer committed May 1, 2024
1 parent 1fb3a21 commit f7e542e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 26 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ You could name functions like `HeapTest_beforeAll()`, `HeapTest_beforeEach()`, a
## Prerequisites
AceUnit needs the following things to work:
* `bash` version 5 or `zsh`.
* `bash` version 5, `ksh`, or `zsh`.
This doesn't affect your work.
For your work you can continue to use any shell you like.
Just the aceunit script itself needs `bash` version 5 or `zsh` to run.
Package maintainers on systems that do not support one-of-n dependencies should choose the one that's more likely to be present, for example, bash 5 on Linux or zsh on macOS.
Just the aceunit script itself needs `bash` version 5, `ksh`, or `zsh` to run.
Package maintainers on systems that do not support one-of-n dependencies should choose the one that's more likely to be present, for example, bash 5 on Linux, ksh on Solaris, or zsh on macOS.
* A tool that can extract a symbol table from an object file, like `nm`, `objdump`, or `readelf`.
Package maintainers on systems that do not support one-of-n dependencies should choose the tool that's most likely to be present.
* A C compiler suite.
Expand Down Expand Up @@ -99,15 +99,15 @@ The following compilers are planned to be tested soon:
* `s390x-linux-gnu`
* `x86-dos` (bcc - Bruce's C Compiler, tested using dosbox)
* `x86_64-unknown-linux-gnu`
* `x86_64-apple-darwin` (Mac OS X; use `aceunit.zsh` instead of `aceunit`, see `.github/workflows/clang-macos.yml`)
* `x86_64-apple-darwin` (Mac OS X; run ./configure first to switch aceunit to zsh, see `.github/workflows/clang-macos.yml`)
* `x86_64-unknown-freebsd13.1`
* `x86_64-unknown-haiku`
* `x86_64-unknown-netbsd9.0` (NetBSD 9.3)
> [!NOTE]
> Users on macOS should either change the interpreter in `bin/aceunit` from `bash` to `zsh` or install a newer `bash`, as `/bin/bash` in macOS is extremely old and does not support the needed constructs.
> The `./configure.sh` script does exactly that, it looks at your OS and available shells, and patches a supported shell into `bin/aceunit`.
> The shell script in `bin/aceunit` works for both, `bash` and `zsh`, but requires Bash 5 when using `bash`.
> The shell script in `bin/aceunit` works for `bash`, `ksh`, and `zsh`, but requires Bash 5 when using `bash`.
> [!NOTE]
> If you use `bcc` for `x86-dos`, run `aceunit` with the flags `-t nm -b nm86 -s _`.
Expand Down Expand Up @@ -278,7 +278,7 @@ If you see the following error:
./aceunit: line 3: declare: -g: invalid option
```
It means that you're running the aceunit shell script with an unsupported shell.
AceUnit requires Bash 5 or zsh 5.
AceUnit requires Bash 5, ksh, or zsh 5.
If you're using macOS, open the `aceunit` shell script and replace `#!/usr/bin/env bash` with `#!/usr/bin/env zsh`.
You can either do that replacement yourself, or you can use the `./configure.sh` shell script to do that.

Expand Down
46 changes: 31 additions & 15 deletions bin/aceunit
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/usr/bin/env bash

declare -g prefix
declare -g strip
declare -g binary
declare -g tool
declare -g name
declare -g -A beforeAll afterAll beforeEach afterEach testcases
declare -g symbols
declare -g fixtures
declare -g -A tools
#!/usr/bin/env ksh

typeset prefix
typeset strip
typeset binary
typeset tool
typeset name
typeset -A beforeAll afterAll beforeEach afterEach testcases
typeset symbols
typeset fixtures
typeset -A tools

tool=objdump
name=fixtures

PROG=$0

if [ -n "$ZSH_VERSION" ]; then
setopt shwordsplit

PROG=$ZSH_SCRIPT

loadToolPlugins() {
for ac in $(cd "$(dirname "$PROG")" ; pwd -P)/../share/aceunit/*.ac ; do
source $ac
Expand All @@ -36,8 +36,6 @@ if [ -n "$ZSH_VERSION" ]; then
echo ${(k)tools}
}
elif [ -n "$BASH_VERSION" ]; then
PROG=$0

loadToolPlugins() {
for ac in $(readlink -f $(dirname $PROG)/../share/aceunit)/*.ac ; do
source $ac
Expand All @@ -52,6 +50,24 @@ elif [ -n "$BASH_VERSION" ]; then
fi
}

supportedTools() {
echo ${!tools[@]}
}
elif [ -n "$KSH_VERSION" ]; then
loadToolPlugins() {
for ac in $(cd "$(dirname "$PROG")" ; pwd -P)/../share/aceunit/*.ac ; do
source $ac
done
}

isToolSupported() {
if typeset -f getSymbols_${tool} >/dev/null ; then
return 0
else
return 1
fi
}

supportedTools() {
echo ${!tools[@]}
}
Expand Down
2 changes: 1 addition & 1 deletion configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ case "$1" in
SHELL_TO_SET=bash
fi
;;
bash|zsh)
bash|ksh|zsh)
SHELL_TO_SET=$1
;;
*)
Expand Down
2 changes: 1 addition & 1 deletion share/aceunit/nm.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tools[nm]=nm

function getSymbols_nm() {
getSymbols_nm() {
$binary "$1" | grep -E ' T ' | sed -e 's/.* '$strip'//' | grep '^\('$2'\)'
}
2 changes: 1 addition & 1 deletion share/aceunit/objdump.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tools[objdump]=objdump

function getSymbols_objdump() {
getSymbols_objdump() {
$binary -t "$1" | grep -E ' g [F ] [^ ]+[ ]+' | sed -e 's/.* '$strip'//' | grep '^\('$2'\)'
}
2 changes: 1 addition & 1 deletion share/aceunit/readelf.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tools[readelf]=readelf

function getSymbols_readelf() {
getSymbols_readelf() {
$binary -s "$1" | grep -E ' FUNC GLOBAL DEFAULT ' | sed -e 's/.* '$strip'//' | grep '^\('$2'\)'
}
2 changes: 1 addition & 1 deletion test/generatorTests/ZOM/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test_unknown_option: export SHELLOPTS:=$(if $(SHELLOPTS),$(SHELLOPTS):)pipefail:
.ONESHELL: test_unknown_option
# diff <<<"$(ACEUNIT): illegal option -- x${NL}Usage: $(ACEUNIT) [OPTION]... OBJECT_FILE..." - <(LC_ALL=C $(ACEUNIT) -x 2>&1 >/dev/null)
test_unknown_option:
echo $$(LC_ALL=C $(ACEUNIT) -x 2>&1 >/dev/null) | grep '$(ACEUNIT):\([0-9]\+:\)\? \(bad\|illegal\) option:\? -\(- \)\?x'
echo $$(LC_ALL=C $(ACEUNIT) -x 2>&1 >/dev/null) | grep '$(ACEUNIT):\([0-9]\+:\)\? \(\(bad\|illegal\) option:\? -\(- \)\?x\|-x: unknown option\)'
diff /dev/null <($(ACEUNIT) -x 2>/dev/null)
! $(ACEUNIT) -x $^ 2>/dev/null

Expand Down

0 comments on commit f7e542e

Please sign in to comment.