+# Removes the CR characters from the file having the path `$1`.
+#
+# This is sometimes needed on Windows with text files.
+#
+# We can't use the `--string-trailing-cr` option of `diff` because
+# Solaris doesn't have it.
+bt_remove_cr() {
+ "$BT_TESTS_SED_BIN" -i'' -e 's/\r//g' "$1"
+}
+
+# Prints `$1` without CR characters.
+bt_remove_cr_inline() {
+ "$BT_TESTS_SED_BIN" 's/\r//g' "$1"
+}
+
+# Runs the `$BT_TESTS_BT2_BIN` command within an environment which can
+# import the `bt2` Python package, redirecting the standard output to
+# the `$1` file and the standard error to the `$2` file.
+#
+# The remaining arguments are forwarded to the `$BT_TESTS_BT2_BIN`
+# command.
+#
+# Returns the exit status of the executed `$BT_TESTS_BT2_BIN`.
+bt_cli() {
+ local -r stdout_file="$1"
+ local -r stderr_file="$2"
+ shift 2
+ local -r args=("$@")
+
+ echo "Running: $BT_TESTS_BT2_BIN ${args[*]}" >&2
+ run_python_bt2 "$BT_TESTS_BT2_BIN" "${args[@]}" 1>"$stdout_file" 2>"$stderr_file"
+}
+
+# Checks the differences between:
+#
+# • The (expected) contents of the file having the path `$1`.
+#
+# • The contents of another file having the path `$2`.
+#
+# Both files are passed through bt_remove_cr_inline() to remove CR
+# characters.
+#
+# Returns 0 if there's no difference, or not zero otherwise.
+bt_diff() {
+ local -r expected_file="$1"
+ local -r actual_file="$2"
+ local ret=0
+
+ diff -u <(bt_remove_cr_inline "$expected_file") <(bt_remove_cr_inline "$actual_file") 1>&2
+
+ return $?
+}