# Source the generated environment file if it's present.
if [ -f "${BT_TESTS_BUILDDIR}/utils/env.sh" ]; then
- # shellcheck source=./env.sh
+ # shellcheck disable=SC1091
. "${BT_TESTS_BUILDDIR}/utils/env.sh"
fi
"$BT_TESTS_SED_BIN" -i'' -e 's/\r//g' "$1"
}
+bt_remove_cr_inline() {
+ "$BT_TESTS_SED_BIN" 's/\r//g' "$1"
+}
+
# Run the Babeltrace CLI, redirecting stdout and stderr to specified files.
#
# $1: file to redirect stdout to
# Strip any \r present due to Windows (\n -> \r\n).
# "diff --string-trailing-cr" is not used since it is not present on
# Solaris.
- bt_remove_cr "$actual_file"
-
- diff -u "$expected_file" "$actual_file" 1>&2
+ diff -u <(bt_remove_cr_inline "$expected_file") <(bt_remove_cr_inline "$actual_file") 1>&2
return $?
}
return $ret
}
+# Run the grep binary configured for the tests.
+bt_grep() {
+ "$BT_TESTS_GREP_BIN" "$@"
+}
+
+# ok() with the test name `$3` on the result of bt_grep() matching the
+# pattern `$1` within the file `$2`.
+bt_grep_ok() {
+ local pattern=$1
+ local file=$2
+ local test_name=$3
+
+ bt_grep --silent "$pattern" "$file"
+
+ local ret=$?
+
+ if ! ok $ret "$test_name"; then
+ {
+ echo "Pattern \`$pattern\` doesn't match the contents of \`$file\`:"
+ echo '--- 8< ---'
+ cat "$file"
+ echo '--- >8 ---'
+ } >&2
+ fi
+
+ return $ret
+}
### Functions ###
# existing ASAN_OPTIONS, such that we override the user's value if it
# contains detect_leaks=1.
if [ "${BT_TESTS_ENABLE_ASAN:-}" = "1" ]; then
- if ${BT_TESTS_CC_BIN} --version | head -n 1 | grep -q '^gcc'; then
+ if ${BT_TESTS_CC_BIN} --version | head -n 1 | bt_grep -q '^gcc'; then
lib_asan="$(${BT_TESTS_CC_BIN} -print-file-name=libasan.so)"
local -x LD_PRELOAD="${lib_asan}${LD_PRELOAD:+:}${LD_PRELOAD:-}"
fi