Make external and internal unittest.bash identical, with the goal of eventually unifying them.

PiperOrigin-RevId: 292191792
diff --git a/src/test/shell/unittest.bash b/src/test/shell/unittest.bash
index dbefe6d..ad23fe6 100644
--- a/src/test/shell/unittest.bash
+++ b/src/test/shell/unittest.bash
@@ -80,10 +80,10 @@
 [ -n "$BASH_VERSION" ] ||
   { echo "unittest.bash only works with bash!" >&2; exit 1; }
 
-DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
-
 export BAZEL_SHELL_TEST=1
 
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+
 #### Configuration variables (may be overridden by testenv.sh or the suite):
 
 # This function may be called by testenv.sh or a test suite to enable errexit
@@ -298,6 +298,7 @@
   TEST_script="$(pwd)/$0"
 fi
 
+
 #### Internal functions
 
 function __show_log() {
@@ -485,6 +486,18 @@
     return 1
 }
 
+# Usage: expect_query_targets <arguments>
+# Checks that log file contains exactly the targets in the argument list.
+function expect_query_targets() {
+  for arg in $@; do
+    expect_log_once "^$arg$"
+  done
+
+# Checks that the number of lines started with '//' equals to the number of
+# arguments provided.
+  expect_log_n "^//[^ ]*$" $#
+}
+
 # Usage: expect_log_with_timeout <regexp> <timeout> [error-message]
 # Waits for the given regexp in the $TEST_log for up to timeout seconds.
 # Prints the contents of $TEST_log and the specified (optional)
@@ -758,7 +771,7 @@
 # Calls exit with zero on success, non-zero otherwise.
 function run_suite() {
     local message="$1"
-    # The name of the suite should be the script being run, under Bazel that
+    # The name of the suite should be the script being run, which
     # will be the filename with the ".sh" extension removed.
     local suite_name="$(basename $0)"
 
@@ -779,7 +792,7 @@
       TESTS=$(declare -F | awk '{print $3}' | grep ^test_)
     elif [ -n "${TEST_WARNINGS_OUTPUT_FILE:-}" ]; then
       if grep -q "TESTS=" "$TEST_script" ; then
-        echo "TESTS variable overridden in Bazel sh_test. Please remove before submitting" \
+        echo "TESTS variable overridden in sh_test. Please remove before submitting" \
           >> "$TEST_WARNINGS_OUTPUT_FILE"
       fi
     fi