! Tests the DEFAULT command
!
! @author  J. Czechowski IV
!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  res expectedText "INFO: EXP*LAIN;SYS        I,2     ,NAME=EXPLAIN"
  res expectedTextForExplain "INFO: EXP*LAIN;SYS        I,2     ,NAME=EXPLAIN,SECTION=,"
  call test_output_on_explain
  call test_warn_on_bogus_cmd

  if interAct then
    res inst "You should see the defaults for EXPLAIN (^{expectedTextForExplain}) listed four times."

    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" "^inst" 24 10 /title

      shellgui/id=idshellgui/attach
      say ""
      say "nM> DEFA EXPLAIN;SYS"
      DEFA EXPLAIN;SYS
      say ""
      say "nM> DEFAULT EXPL;SYS"
      DEFAULT EXPL;SYS
      say ""
      say "nM> DEFAULTS EXPLAIN"
      DEFAULTS EXPLAIN
      say ""
      say "nM> DEFAULTS NAME=EXPLAIN OPT=SYS"
      DEFAULTS NAME=EXPLAIN OPT=SYS
      say ""
    pipe off
  endif
  
endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the ENDMACRO.
!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN"
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop
  elseif msg.name eqs "TEXT" then
    archive/echo=on off
    assert/text="^reg.main.name: Output contains ^{expectedText}." msg.data EQSS expectedText
    archive/echo=off off
  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed, unless it is expected
!******************************************************************************!
procedure processException m:emsg
  if expectedException REXISTS then
    assert/text="^reg.main.name: Expected ERROR starts with: ^{expectedException}" expectedException EQSS emsg.data.message
    remove expectedException
  else
    assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
    if "Trace" SUBS ENV.DEBUG then invoke ,, emsg.data.printStackTrace()
  endif
return

!******************************************************************************!
! Test output of defa explain;sys
!******************************************************************************!
procedure test_output_on_explain
  ! archive messages to main macro (this)
  archive to MAIN
  defa explain;sys
  archive off
return

!******************************************************************************!
! Test executing "DEFAULT" with a command that does not exist Bug 2996
!******************************************************************************!
procedure test_warn_on_bogus_cmd
  ! archive messages to main macro (this)
  archive to MAIN
  res expectedText "WARN: No command dictionary entry matching NAME=NotExistCmd"
  DEFAULTS NotExistCmd
  archive off
return
