test_preflight.sh #2

  • //
  • guest/
  • tom_tyler/
  • sw/
  • main/
  • install_sdp/
  • dev/
  • bin/
  • test_preflight.sh
  • View
  • Commits
  • Open Download .zip Download (2 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 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 31776 C. Thomas Tyler Better handling of variable push/fetch output.
#1 31775 C. Thomas Tyler Added preflight script to use before running tests.