Generate the Java main method for the test Java class.
(atj-gen-test-main-method tests$ java-class$ no-aij-types$) → method
This is generated only if the
This method initializes the ACL2 environment and then calls each test method. It also prints a message saying whether all tests passed or not.
If
If no argument is passed to this method (the argument normally comes from the command line, when the generated code is called as a Java application), then the test methods are called with 0 as the repetition parameter: that is, no time information is printed. Otherwise, there must exactly one argument that must parse to a positive integer, which is passed as the repetition parameter to the test methods.
Note that we generate an expression name for
Function:
(defun atj-gen-test-main-method (tests$ java-class$ no-aij-types$) (declare (xargs :guard (and (atj-test-listp tests$) (stringp java-class$) (booleanp no-aij-types$)))) (let ((__function__ 'atj-gen-test-main-method)) (declare (ignorable __function__)) (b* ((method-param (make-jparam :final? nil :type (jtype-array (jtype-class "String")) :name "args")) (method-body (append (jblock-locvar (jtype-int) "n" (jexpr-literal-0)) (jblock-if (jexpr-binary (jbinop-eq) (jexpr-name "args.length") (jexpr-literal-1)) (jblock-asg (jexpr-name "n") (jexpr-smethod (jtype-class "Integer") "parseInt" (list (jexpr-array (jexpr-name "args") (jexpr-literal-0)))))) (jblock-if (jexpr-binary (jbinop-gt) (jexpr-name "args.length") (jexpr-literal-1)) (jblock-throw (jexpr-newclass (jtype-class "IllegalArgumentException") (list (jexpr-literal-string "There must be 0 or 1 arguments."))))) (and (not no-aij-types$) (jblock-smethod (jtype-class java-class$) "initialize" nil)) (atj-gen-run-tests tests$) (jblock-ifelse (jexpr-name "failures") (append (jblock-imethod (jexpr-name "System.out") "println" (list (atj-gen-jstring "Some tests failed."))) (jblock-imethod (jexpr-name "System.out") "println" nil) (jblock-smethod (jtype-class "System") "exit" (list (jexpr-literal-1)))) (append (jblock-imethod (jexpr-name "System.out") "println" (list (atj-gen-jstring "All tests passed."))) (jblock-imethod (jexpr-name "System.out") "println" nil) (jblock-smethod (jtype-class "System") "exit" (list (jexpr-literal-0)))))))) (make-jmethod :access (jaccess-public) :abstract? nil :static? t :final? nil :synchronized? nil :native? nil :strictfp? nil :result (jresult-void) :name "main" :params (list method-param) :throws (and (not no-aij-types$) (list *aij-class-undef-pkg-exc*)) :body method-body))))
Theorem:
(defthm jmethodp-of-atj-gen-test-main-method (b* ((method (atj-gen-test-main-method tests$ java-class$ no-aij-types$))) (jmethodp method)) :rule-classes :rewrite)