"Status from server.
Local to the process buffer.")
+(defvar riece-ruby-output-queue-alist nil
+ "An alist mapping from program name to output data.")
(defvar riece-ruby-output-handler-alist nil
"An alist mapping from program name to output handler.
Output handlers are called every time \"# output\" line arrives.
(progn
(setq riece-ruby-escaped-data nil
riece-ruby-response
- (list 'ERR (string-to-number (match-string 2))
+ (list 'ERR (string-to-number (match-string 1))
(match-string 3))
riece-ruby-lock nil))
(if (looking-at "D \\(.*\\)\r")
(riece-ruby-run-exit-handler
(cdr (car riece-ruby-status-alist)))))
(if (looking-at "# output \\([^ ]*\\) \\(.*\\)\r")
- (let ((entry (assoc (match-string 1)
- riece-ruby-output-handler-alist)))
- (if entry
- (riece-debug-with-backtrace
- (funcall (cdr entry) (car entry) (match-string 2)))))
+ (riece-ruby-run-output-handler (match-string 1)
+ (match-string 2))
(if (looking-at "# exit \\(.*\\)\r")
(riece-ruby-run-exit-handler (match-string 1))))))))
(forward-line))
(defun riece-ruby-run-exit-handler (name)
(let ((entry (assoc name riece-ruby-exit-handler-alist)))
- (if entry
- (progn
- (setq riece-ruby-exit-handler-alist
- (delq entry riece-ruby-exit-handler-alist))
- (riece-debug-with-backtrace
- (funcall (cdr entry) (car entry)))
- (riece-ruby-clear name)))))
+ (when entry
+ (setq riece-ruby-exit-handler-alist
+ (delq entry riece-ruby-exit-handler-alist))
+ (riece-funcall-ignore-errors name (cdr entry) (car entry))
+ (riece-ruby-clear name))))
+
+(defun riece-ruby-run-output-handler (name output)
+ (let ((handler-entry (assoc name riece-ruby-output-handler-alist))
+ (entry (assoc name riece-ruby-output-queue-alist)))
+ (if handler-entry
+ (riece-funcall-ignore-errors name (cdr handler-entry) name output)
+ (if entry
+ (setcdr entry (cons output (cdr entry)))
+ (setq riece-ruby-output-queue-alist
+ (cons (list name output)
+ riece-ruby-output-queue-alist))))))
(defun riece-ruby-sentinel (process status)
(kill-buffer (process-buffer process)))
`output' method in the Ruby program.
An output-handler is called with two argument. The first argument is
the same as NAME. The second argument is output string."
- (let ((entry (assoc name riece-ruby-output-handler-alist)))
+ (let ((entry (assoc name riece-ruby-output-handler-alist))
+ queue-entry pointer)
(if handler
(progn
+ (when (setq queue-entry (assoc name riece-ruby-output-queue-alist))
+ (setq pointer (nreverse (cdr queue-entry))
+ riece-ruby-output-queue-alist
+ (delq queue-entry riece-ruby-output-queue-alist))
+ (while pointer
+ (riece-funcall-ignore-errors name handler name (car pointer))
+ (setq pointer (cdr pointer))))
(if entry
(setcdr entry handler)
(setq riece-ruby-output-handler-alist
--- /dev/null
+(require 'riece-ruby)
+
+(luna-define-class test-riece-ruby (lunit-test-case))
+
+(luna-define-method lunit-test-case-teardown ((case test-riece-ruby))
+ (riece-ruby-execute "exit!")
+ (sleep-for 1))
+
+(luna-define-method test-riece-ruby-execute-1 ((case test-riece-ruby))
+ (lunit-assert-2
+ case
+ (equal (riece-ruby-execute "sleep 30") "0"))
+ (lunit-assert-2
+ case
+ (equal (riece-ruby-execute "1 << 32") "1"))
+ (lunit-assert-2
+ case
+ (equal (riece-ruby-execute "\"") "2")))
+
+(luna-define-method test-riece-ruby-inspect-1 ((case test-riece-ruby))
+ (let ((name (riece-ruby-execute "sleep 30")))
+ (lunit-assert-2
+ case
+ (eq (car (car (riece-ruby-inspect name))) 'OK))
+ (lunit-assert-2
+ case
+ (assoc "running" (nth 2 (riece-ruby-inspect name))))))
+
+(luna-define-method test-riece-ruby-inspect-2 ((case test-riece-ruby))
+ (let ((name (riece-ruby-execute "1 << 32")))
+ (lunit-assert-2
+ case
+ (eq (car (car (riece-ruby-inspect name))) 'OK))
+ (lunit-assert-2
+ case
+ (equal (nth 1 (riece-ruby-inspect name)) "4294967296"))
+ (lunit-assert-2
+ case
+ (assoc "finished" (nth 2 (riece-ruby-inspect name))))))
+
+(luna-define-method test-riece-ruby-inspect-3 ((case test-riece-ruby))
+ (let ((name (riece-ruby-execute "\"")))
+ (lunit-assert-2
+ case
+ (eq (car (car (riece-ruby-inspect name))) 'OK))
+ (lunit-assert-2
+ case
+ (equal (nth 1 (riece-ruby-inspect name))
+ "unterminated string meets end of file"))
+ (lunit-assert-2
+ case
+ (assoc "exited" (nth 2 (riece-ruby-inspect name))))))
+
+(luna-define-method test-riece-ruby-clear-1 ((case test-riece-ruby))
+ (let ((name (riece-ruby-execute "sleep 30")))
+ (riece-ruby-clear name)
+ (lunit-assert-2
+ case
+ (eq (car (car (riece-ruby-inspect name))) 'ERR))
+ (lunit-assert-2
+ case
+ (= (nth 1 (car (riece-ruby-inspect name))) 105))))
+
+(defvar test-riece-ruby-exit-handler-1 nil)
+(luna-define-method test-riece-ruby-exit-handler-1 ((case test-riece-ruby))
+ (let ((name (riece-ruby-execute "1 << 32")))
+ (riece-ruby-set-exit-handler
+ name
+ (lambda (name)
+ (setq test-riece-ruby-exit-handler-1 name)))
+ (sleep-for 1)
+ (lunit-assert-2
+ case
+ (equal test-riece-ruby-exit-handler-1 name))))
+
+(defvar test-riece-ruby-output-handler-1 nil)
+(luna-define-method test-riece-ruby-output-handler-1 ((case test-riece-ruby))
+ (let ((name (riece-ruby-execute "output(1 << 32)")))
+ (riece-ruby-set-output-handler
+ name
+ (lambda (name output)
+ (setq test-riece-ruby-output-handler-1 output)))
+ (sleep-for 1)
+ (lunit-assert-2
+ case
+ (equal test-riece-ruby-output-handler-1 "4294967296"))))
+
+(defvar test-riece-ruby-output-handler-2 nil)
+(luna-define-method test-riece-ruby-output-handler-2 ((case test-riece-ruby))
+ (let ((name (riece-ruby-execute "output(1 << 32)")))
+ (sleep-for 1)
+ (riece-ruby-set-output-handler
+ name
+ (lambda (name output)
+ (setq test-riece-ruby-output-handler-2 output)))
+ (lunit-assert-2
+ case
+ (equal test-riece-ruby-output-handler-2 "4294967296"))))
\ No newline at end of file