+# Check the differences between two files (typically some expected output vs
+# some actual output). If there are differences, print the diff to stderr.
+#
+# $1: file 1 (expected)
+# $2: file 2 (actual)
+#
+# Return 0 if there's no difference, and non-zero if there are.
+#
+# Note that this function modifies the actual output file ($2) _in-place_ to
+# remove any \r character.
+
+bt_diff() {
+ local expected_file="$1"
+ local actual_file="$2"
+ local ret=0
+
+ # 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
+
+ return $?
+}
+
+# Checks the difference between:
+#
+# 1. What the CLI outputs on its standard output when given the arguments
+# "$@" (excluding the first two arguments).
+# 2. The file with path "$1".
+#
+# And the difference between:
+#
+# 1. What the CLI outputs on its standard error when given the arguments
+# "$@" (excluding the first two arguments).
+# 2. The file with path "$2".