test_preflight.sh #2

  • //
  • test-install_sdp/
  • dev/
  • test_preflight.sh
  • View
  • Commits
  • Open Download .zip Download (3 KB)
#!/bin/bash
set -u

declare -i ErrorCount=0
declare -i TestCount=0
declare DevHome=
declare DevRoot=
declare TmpFile=
declare Dir=

function msg () { echo -e "$*"; }
function errmsg () { msg "\\nError: ${1:-Unknown Error}\\n"; ErrorCount+=1; }
function bail () { errmsg "${1:-Unknown Error}"; exit "$ErrorCount"; }

source ./dev_env.sh
DevHome=${DEV_HOME}
DevRoot=${DevHome%/*}
TmpFile=$(mktemp)

for Dir in "$DevHome" "${DevRoot}/sdp"; do
   TestCount+=1
   cd "$Dir" || bail "Could not do: cd \"$Dir\""

   TestCount+=1
   if p4 login -s > /dev/null 2>&1; then
      msg "Verified: Local login in $PWD OK."
   else
      errmsg "Local login in $PWD is bad."
   fi

   TestCount+=1
   if p4 -ztag -F %localFile% status > "$TmpFile" 2>&1; then
      TestCount+=1
      if [[ -s "$TmpFile" ]]; then
         errmsg "The 'p4 status' in $PWD was NOT clean; these files were reported:\\n$(cat "$TmpFile")\\n"
      else
         msg "Verified: The 'p4 status' in $PWD is clean."
      fi
   else
      errmsg "Error in $PWD doing: p4 status"
   fi

   TestCount+=1
   if p4 -ztag -F %depotFile% opened > "$TmpFile" 2>&1; then
      TestCount+=1
      if [[ -s "$TmpFile" ]]; then
         errmsg "The 'p4 opened' in $PWD was NOT clean; these files were reported:\\n$(cat "$TmpFile")\\n"
      else
         msg "Verified: The 'p4 opened' in $PWD is clean."
      fi
   else
      errmsg "Error in $PWD doing: p4 opened"
   fi

   TestCount+=1
   if p4 fetch -n > "$TmpFile" 2>&1; then
      TestCount+=1
      if grep -q 'No changes to fetch' "$TmpFile" || grep -q '0 change(s)' "$TmpFile"; then
         msg "Verified: The 'p4 fetch -n' in $PWD is clean."
      else
         errmsg "The 'p4 fetch -n' in $PWD was not clean:\\n$(cat "$TmpFile")\\n"
      fi
   else
      errmsg "Error in $PWD doing: p4 fetch -n:\\n$(cat "$TmpFile")\\n"
   fi

   TestCount+=1
   if [[ "$(p4 -ztag -F %userName% info 2>/dev/null)" == ftp ]]; then
      # Basic/read-only clones (P4USER=ftp) never have push permission; that's
      # expected, not a failure, so skip this check rather than erroring on it.
      msg "Skipped: 'p4 push -n' in $PWD (read-only 'ftp' clone has no push access)."
   elif p4 push -n > "$TmpFile" 2>&1; then
      TestCount+=1
      if grep -q 'No changes to push' "$TmpFile" || grep -q '0 change(s)' "$TmpFile"; then
         msg "Verified: The 'p4 push -n' in $PWD is clean."
      else
         errmsg "The 'p4 push -n' in $PWD was not clean:\\n$(cat "$TmpFile")\\n"
      fi
   else
      errmsg "Error in $PWD doing: p4 push -n:\\n$(cat "$TmpFile")\\n"
   fi
done

rm -f "$TmpFile"

if [[ "$ErrorCount" -eq 0 ]]; then
   msg "\\nSUCCESS: All $TestCount tests PASSED."
else
   msg "\\nFAIL: $TestCount tests were executed, with $ErrorCount errors."
fi

exit "$ErrorCount"
# Change User Description Committed
#2 33166 Claude (AI Agent by Anthropic) Fix test_preflight.sh (and thus the uat alias) to work in Basic/read-only mode: p4 push -n always fails with a permission error for the ftp user, which previously made test_preflight.sh (and uat, which chains test_preflight.sh && r) permanently unusable for Basic-mode clones.
Caught on the r9x86_64 canary during Task 1.3. Now skips the push check (with a clear message) when P4USER is ftp, since lacking push access is expected there, not a failure.

Agent: Claude Code, Model: Claude Sonnet 5 (claude-sonnet-5), operating as bot_Claude_Anthropic.
#1 33144 C. Thomas Tyler Initialized //test-install_sdp/dev with p4 populate -b test-install_sdp_Classic_to_Streams
//guest/tom_tyler/sw/main/install_sdp/dev/bin/test_preflight.sh
#2 31776 C. Thomas Tyler Better handling of variable push/fetch output.
#1 31775 C. Thomas Tyler Added preflight script to use before running tests.