!******************************************************************************!
! Tests the loading of a NeXtMidas default debug flag.
!
! Arguments: None
!
! @issue    NXM-3887 Midas default behavior change causes undesirable
!                    change for some operational uses
! @since    NeXtMidas 4.1.4
! @author:  Zachary Matthews
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)

  if interAct then
    if ENV.OSNAME EQSS "Windows" then
      info "^reg.main.name: Skipping since this test currently can't be run on Windows."
    else
      set instructions "Run the following in a separate OS terminal:\n\n&
                        1. cd ^{env.nmroot}\n&
                        2. Set NMROOT and JAVA_HOME\n&
                        3. ./nxm/sys/test/test_debug_default.sh\n\n&
                        Expected results:\n&
                        1. Two NeXtMidas startups\n&
                        2. The first startup should be followed by an ERROR with NO stack trace.\n&
                        3. The second startup should followed by an ERROR WITH a stack trace.\n\n&
                        If everything ran as expected, please PASS this test."

      pipe on
        panel/msgid=MAIN/setup/controls=gc
        gcontrol label macro "Test MACRO"
        gcontrol menu  main "Exit with Status =" "PASS,FAIL" TABLE={ItemColors={PASS="GREEN",FAIL="RED"}} /tleft

        gcontrol text  idtext "Instructions" "^{instructions}" 24 12 /title

      pipe off
    endif
  endif
endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the ENDMACRO.
!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop
  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
