+;;;###autoload
+(defun test-simple-run (&rest command-line-formats)
+ "Register command line to run tests non-interactively and bind key to run test.
+After calling this function, you can run test by key specified by `test-simple-runner-key'.
+
+It is preferable to write at the first line of test files as a comment, e.g,
+;;;; (test-simple-run \"emacs -batch -L %s -l %s\" (file-name-directory (locate-library \"test-simple.elc\")) buffer-file-name)
+
+Calling this function interactively, COMMAND-LINE-FORMATS is set above."
+ (interactive)
+ (setq command-line-formats
+ (or command-line-formats
+ (list "emacs -batch -L %s -l %s"
+ (file-name-directory (locate-library "test-simple.elc"))
+ buffer-file-name)))
+ (let ((func (lambda ()
+ (interactive)
+ (funcall test-simple-runner-interface
+ (apply 'format command-line-formats)))))
+ (global-set-key (kbd test-simple-runner-key) func)
+ (funcall func)))
+
+(defun test-simple-noninteractive-kill-emacs-hook ()
+ "Emacs exits abnormally when noninteractive test fails."
+ (when (and noninteractive test-simple-info
+ (<= 1 (test-info-failure-count test-simple-info)))
+ (let (kill-emacs-hook)
+ (kill-emacs 1))))
+(when noninteractive
+ (add-hook 'kill-emacs-hook 'test-simple-noninteractive-kill-emacs-hook))
+
+