mirror of
https://github.com/ipfs/kubo.git
synced 2025-10-25 02:16:56 +08:00
Let's first add a comment to explain why the wrapper printf() is needed. Then let's replace the last instructions by quotes inside the wrapper printf() first argument, and let's also put there the eventual space so that we can remove the printf on the above line. License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
38 lines
865 B
Bash
38 lines
865 B
Bash
# Generic test functions for go-ipfs
|
|
|
|
# Echo the args, run the cmd, and then also fail,
|
|
# making sure a test case fails.
|
|
test_fsh() {
|
|
echo "> $@"
|
|
eval "$@"
|
|
echo ""
|
|
false
|
|
}
|
|
|
|
# Same as sharness' test_cmp but using test_fsh (to see the output).
|
|
# We have to do it twice, so the first diff output doesn't show unless it's
|
|
# broken.
|
|
test_cmp() {
|
|
diff -q "$@" >/dev/null || test_fsh diff -u "$@"
|
|
}
|
|
|
|
# Same as test_cmp above, but we sort files before comparing them.
|
|
test_sort_cmp() {
|
|
sort "$1" >"$1_sorted" &&
|
|
sort "$2" >"$2_sorted" &&
|
|
test_cmp "$1_sorted" "$2_sorted"
|
|
}
|
|
|
|
# Quote arguments for sh eval
|
|
shellquote() {
|
|
_space=''
|
|
for _arg
|
|
do
|
|
# On Mac OS, sed adds a newline character.
|
|
# With a printf wrapper the extra newline is removed.
|
|
printf "$_space'%s'" "$(printf "%s" "$_arg" | sed -e "s/'/'\\\\''/g;")"
|
|
_space=' '
|
|
done
|
|
printf '\n'
|
|
}
|