Skip to content

Commit

Permalink
[test/gold] Copy some more backtick test cases from issue #1449
Browse files Browse the repository at this point in the history
Run like this:

    test/gold.sh test-autoconf-backtick

And then see _tmp/shebang.txt and _tmp/osh.txt.  (This reminds me the
test/gold.sh harness is a little wonky)
  • Loading branch information
Andy C committed Jan 15, 2023
1 parent f41335d commit a80f56d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/gold.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ test-parse-help() {
_compare $dir/excerpt.sh _parse_help ls
}

test-autoconf-backtick() {
# https://github.com/oilshell/oil/issues/1449
_compare $GOLD_DIR/autoconf-backtick.sh
}

# Gah, bash gets this from compile-time configuration generated with autoconf,
# not uname(). It looks like 'linux-gnu' on Ubuntu. In Alpine, it's
# 'linux-musl'.
Expand Down
50 changes: 50 additions & 0 deletions test/gold/autoconf-backtick.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#! /bin/sh

# From https://github.com/oilshell/oil/issues/1449

set -e

nargs () {
n_args=$#
return 0
}

check () {
if [ "$1" = "$2" ]; then
printf 'ok: %s\n' "$3"
else
printf 'FAIL: %s: got "%s" expected "%s"\n' "$3" "$1" "$2"
status=1
fi
}

a="a b"

nargs $a
check $n_args 2 'nargs $a'

nargs "$a"
check $n_args 1 'nargs "$a"'

nargs "$a" $a
check $n_args 3 'nargs "$a" $a'

n_args=`nargs "$a"; echo $n_args`
check $n_args 1 '`nargs "$a"`'

n_args=`nargs "$a" $a; echo $n_args`
check $n_args 3 '`nargs "$a" $a`'

eval "nargs \"$a\""
check $n_args 1 'eval "nargs \"$a\""'

eval "nargs \"$a\" $a"
check $n_args 3 'eval "nargs \"$a\" $a"'

n_args=`eval "nargs \"$a\""; echo $n_args`
check $n_args 1 'eval "nargs \"$a\""'

n_args=`eval "nargs \"$a\" $a"; echo $n_args`
check $n_args 3 'eval "nargs \"$a\" $a"'

exit $status

0 comments on commit a80f56d

Please sign in to comment.