!
!  Tests out use of intrinsic HOMEPATH within a macro, stopping
!  the macro if anything unexpected happens.
!
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE
  switch DEBUG       debug    GET DEF=FALSE SDEF=TRUE

  !  save the current value of AUX.HOMEPATH
  result originalhome "^AUX.HOMEPATH"

  !  change the homepath to be something different
  info "It is fine to see a warning below that 'Specified HomePath does not exist'"
  homepath /home/mydirectory/file1
  result answer "/home/mydirectory/file1/"
  if debug then say "^reg.main.name: changed aux.home to ^AUX.HOMEPATH"
  assert/text="HOMEPATH set aux.homepath = ^{aux.homepath}"/stat=status "^{aux.homepath}" EQS "^answer"
  if status NEQS "PASS" and debug then say "AUX.HOMEPATH = ^{aux.homepath}, answer = ^answer"

  !  make sure the results variable 'OLDHOMEPATH' was
  !  created by the system to remember the old homepath
  if debug then say "^reg.main.name:  old home path = '^oldhomepath'"
  assert/text="OLDHOMEPATH set"/stat=status ^oldhomepath EQS ^originalhome
  if status NEQS "PASS" and debug then say "OLDHOMEPATH = ^oldhomepath, originalhome = ^originalhome"

  !  restore the original homepath
  home restore
  if debug then say "^reg.main.name: restored, home ='^AUX.HOMEPATH' , original ^originalhome"
  assert/text="HOMEPATH restore"/stat=status aux.homepath EQS originalhome
  if status NEQS "PASS" and debug then say "AUX.HOMEPATH = ^{aux.homepath}, originalhome = ^originalhome"

  ! make sure the HOME RESTORE removed the OLDHOMEPATH results variable
  assert/text="OLDHOMEPATH removal" OLDHOMEPATH NREXISTS

  if interAct then
    set instructions "See what to verify in SHELL terminal."
    set badpath "/bogusPath/"
    pipe on
      panel/msgid=MAIN/setup/controls=gc

      gcontrol label macro "MACRO"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
      gcontrol text idtext "Instructions" instructions 24 7 /title

      shellgui/id=idshellgui/attach
      ! test case for BUG 2328 HOMEPATH should display new home path in interactive terminal
      say ""
      info "Should see that HomePath has been set to AUX.HOME = ^{aux.home}"
      say "nM> HOMEPATH/verbose aux.home
      HOMEPATH/verbose aux.home

      say ""
      info "Should see a warning that HomePath does not exist below:"
      say "nM> HOMEPATH ^badpath
      HOMEPATH badpath

      say ""
      info "Should see another warning that HomePath does not exist:"
      say "nM> HOMEPATH
      HOMEPATH

    pipe off

    ! restore original HomePath
    home originalhome

    %test_homepath_cwd  ! Bug 2481

  endif

endmacro

!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: user indicated" msg.data eqs "PASS"
    pipe stop
  endif
return
