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

  ! Skip tests when run in a thinned NeXtMidas - 4.0.0
  invoke optionExists reg.shell.M.dictionary.isDictionaryEntry(OPTION)
  invoke panelExists reg.shell.M.dictionary.isDictionaryEntry(PANEL)

  ! save previous path, as this test does not run properly when unbuilt option trees
  ! are on the PATH
  res savepath opt.path
  PATH SET SYS

  if optionExists then
    ! test BUG 2394
    set expText "defaults given. Please run"
    ! 1. archive messages to main macro (this)
    archive to MAIN
    ! 2. trigger warning
    FILE NAME optDir (^{env.nmroot},nxm,sys,test,nmopts,nxm,testopt_bad_command) "" ""
    OPT testopt_bad_command optDir
    PATH ADD testopt_bad_command
    PATH REMOVE testopt_bad_command
    ! 5. turn echo ON (back to normal) and so we can see output of next ASSERT
    archive/echo=on off
    OPT/DELETE testopt_bad_command
  else
    info "^reg.main.name: Skipping tests since OPTION command does not exist in LIBNXM NeXtMidas"
  endif

  if interAct AND panelExists then
    res synExpl "EXPLAIN;SYS <NAME> <SECTION>"
    res synPlot "PLOT;SYS <FILE> ..."

    res inst "You should see the syntax for EXPLAIN (^synExpl) and PLOT (^synPlot) listed.\n\n&
              When running from a standard jar file:\n&
              You should also see a warning message in the main terminal:\n&
              \"The INVALIDARGS command takes...\""

    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> SYN EXP"
      SYN EXP
      say ""
      say "nM> SYNTAX PLOT"
      SYNTAX PLOT
    pipe off
  endif

  ! restore previous path
  path set ^savepath

endmacro

!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="Tests for DEFAULT" msg.data eqss "PASS"
    pipe stop
  elseif msg.name eqs "TEXT" then
    ! test BUG 2394
    ! 2012-06-01: NTN: only check warning messages, otherwise INFO messages can make this test case fail
    if msg.data eqss "WARN: " then
      if ^{env.NMROOT} NEQS "classpath:" then
        ! 3. need to turn OFF archive with echo ON so that we get output of ASSERT
        archive/echo=on off
        assert/text="^reg.main.name: Got 'TEXT' message with correct data" expText SUBS msg.data
        ! 4. turn off echo so that info message does NOT get printed
        archive/echo=off off
      endif
    endif
  else
    ! do nothing
    say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid dats: ^msg.data"
  endif
return
