https://github.com/jrincayc/ucblogo-code
Raw File
Tip revision: 33bc65673ca25089c9acaf8a9eb44bb780686105 authored by Joshua Cogliati on 30 December 2020, 15:37:02 UTC
Merge pull request #85 from jrincayc/release_6_2_work
Tip revision: 33bc656
UnitTests-Macros.lg
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                        ;;
;;             BERKELEY LOGO              ;;
;;            Macro Unit Tests            ;;
;;                                        ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


InstallSuite [Macros] [Tests.Macro.Setup]



;; The list of all Macro unit tests
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

MAKE "Tests.Macro [
  ;list tests here
  Tests.Macro.OutputStopWorksAsExpected
  Tests.Macro.PlainStopErrorsAsExpected
  Tests.Macro.FunctionStopErrorsAsExpected
]

;; Test Suite setup procedure, main entry
;; point for all tests in this suite
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to Tests.Macro.Setup
  RunTests :Tests.Macro
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                 ;;
;; HELPERS, MISC                   ;;
;;                                 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

.MACRO Tests.Macro._OutputStopMacro
  OUTPUT [ STOP ]
END

TO Tests.Macro._CallOutputStop
  Tests.Macro._OutputStopMacro
  OUTPUT 1
END

.MACRO Tests.Macro._PlainStopMacro
  STOP
END

TO Tests.Macro._StopFunction
  STOP
END

TO Tests.Macro._CallStopFunction
  OUTPUT Tests.Macro._StopFunction
END


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                 ;;
;; ADD INDIVIDUAL UNIT TESTS BELOW ;;
;;                                 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;all tests must return T/F indicating success/failure

TO Tests.Macro.OutputStopWorksAsExpected
  LOCALMAKE "result RUNRESULT [ Tests.Macro._CallOutputStop ]

  OUTPUT EMPTY? :result
END

TO Tests.Macro.PlainStopErrorsAsExpected
  CATCH "Error [ Tests.Macro._PlainStopMacro ]
  LOCALMAKE "err ERROR

  ; Message 29 is "Macro returned %s instead of a list"
  OUTPUT (AND [NOT EMPTY? :err]
              [EQUAL? FIRST :err 29])
END


;; Not strictly a macro test; but, the functionality to handle this error
;; is closely related to the functionality to catch a macro directly
;; calling stop

TO Tests.Macro.FunctionStopErrorsAsExpected
  CATCH "Error [ Tests.Macro._CallStopFunction ]
  LOCALMAKE "err ERROR

  ; Message 5 is "%p didn't output to %p"
  OUTPUT (AND [NOT EMPTY? :err]
              [EQUAL? FIRST :err 5])
END
back to top