diff options
author | Bryan Drewery <bryan@shatow.net> | 2018-02-13 02:42:32 +0300 |
---|---|---|
committer | Bryan Drewery <bryan@shatow.net> | 2018-02-13 02:45:39 +0300 |
commit | 1a971e8d5401d4007ad38e3c8422524079a24cec (patch) | |
tree | 68473a32b2c12dc3b3be3c6fa8c839045a1f77ff /test | |
parent | 3b9299c665ff308373df40b90833f9ad76e2a730 (diff) |
decode_args is quite slow due to forking
Diffstat (limited to 'test')
-rw-r--r-- | test/encode_args.sh | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/encode_args.sh b/test/encode_args.sh index 954b96b8..be7774f8 100644 --- a/test/encode_args.sh +++ b/test/encode_args.sh @@ -44,6 +44,12 @@ assert '"1"'"${ENCODE_SEP}${ENCODE_SEP}" "${data}" "encode 1 argument double-quo # Test embedded spaces encode_args data "1" "2 3" assert "1${ENCODE_SEP}2 3" "${data}" "encode 2 argument" +set -- +oldIFS="${IFS}"; IFS="${ENCODE_SEP}"; set -- ${data}; IFS="${oldIFS}"; unset oldIFS +assert 2 $# "decode 2 argument argcnt" +assert "1" "$1" "decode 2 argument argument 1" +assert "2 3" "$2" "decode 2 argument argument 2" +set -- eval $(decode_args data) assert 2 $# "decode 2 argument argcnt" assert "1" "$1" "decode 2 argument argument 1" @@ -53,6 +59,11 @@ assert "2 3" "$2" "decode 2 argument argument 2" TMP=$(mktemp -ut encoded_args) encode_args data "\$(touch ${TMP})" assert "\$(touch ${TMP})" "${data}" "encoded cmdsubst" +set -- +oldIFS="${IFS}"; IFS="${ENCODE_SEP}"; set -- ${data}; IFS="${oldIFS}"; unset oldIFS +[ -f "${TMP}" ] +assert 1 $? "decoding cmdsubst should not fire: ${TMP}" +set -- eval $(decode_args data) [ -f "${TMP}" ] assert 1 $? "decoding cmdsubst should not fire: ${TMP}" @@ -60,6 +71,12 @@ assert 1 $? "decoding cmdsubst should not fire: ${TMP}" # Test 1 trailing empty arguments encode_args data "1" "" assert "1${ENCODE_SEP}${ENCODE_SEP}" "${data}" "encode 1 trailing args" +set -- +oldIFS="${IFS}"; IFS="${ENCODE_SEP}"; set -- ${data}; IFS="${oldIFS}"; unset oldIFS +assert 2 $# "decode 1 trailing arguments argcnt" +assert "1" "$1" "decode 1 trailing arguments argument 1" +assert "" "$2" "decode 1 trailing arguments argument 2" +set -- eval $(decode_args data) assert 2 $# "decode 1 trailing arguments argcnt" assert "1" "$1" "decode 1 trailing arguments argument 1" @@ -68,6 +85,14 @@ assert "" "$2" "decode 1 trailing arguments argument 2" # Test trailing empty arguments encode_args data "1" "" "" "" assert "1${ENCODE_SEP}${ENCODE_SEP}${ENCODE_SEP}${ENCODE_SEP}" "${data}" "encode 3 trailing args" +set -- +oldIFS="${IFS}"; IFS="${ENCODE_SEP}"; set -- ${data}; IFS="${oldIFS}"; unset oldIFS +assert 4 $# "decode 3 trailing arguments argcnt" +assert "1" "$1" "decode 3 trailing arguments argument 1" +assert "" "$2" "decode 3 trailing arguments argument 2" +assert "" "$3" "decode 3 trailing arguments argument 3" +assert "" "$4" "decode 3 trailing arguments argument 4" +set -- eval $(decode_args data) assert 4 $# "decode 3 trailing arguments argcnt" assert "1" "$1" "decode 3 trailing arguments argument 1" @@ -78,6 +103,14 @@ assert "" "$4" "decode 3 trailing arguments argument 4" # Test trailing empty arguments with data encode_args data "1" "" "" "x" assert "1${ENCODE_SEP}${ENCODE_SEP}${ENCODE_SEP}x" "${data}" "encode 3 trailing args x" +set -- +oldIFS="${IFS}"; IFS="${ENCODE_SEP}"; set -- ${data}; IFS="${oldIFS}"; unset oldIFS +assert 4 $# "decode 3 trailing arguments x argcnt" +assert "1" "$1" "decode 3 trailing arguments x argument 1" +assert "" "$2" "decode 3 trailing arguments x argument 2" +assert "" "$3" "decode 3 trailing arguments x argument 3" +assert "x" "$4" "decode 3 trailing arguments x argument 4" +set -- eval $(decode_args data) assert 4 $# "decode 3 trailing arguments x argcnt" assert "1" "$1" "decode 3 trailing arguments x argument 1" @@ -92,6 +125,11 @@ tmpfile=$(mktemp -ut poudriere_encode_args) encode_args data "\$(touch ${tmpfile})" [ -f "${tmpfile}" ] assert_not 0 $? "File should not exist when encoded" +set -- +oldIFS="${IFS}"; IFS="${ENCODE_SEP}"; set -- ${data}; IFS="${oldIFS}"; unset oldIFS +[ -f "${tmpfile}" ] +assert_not 0 $? "File should not exist when decoded" +set -- eval $(decode_args data) [ -f "${tmpfile}" ] assert_not 0 $? "File should not exist when decoded" |