From: ueno Date: Fri, 12 Aug 2005 09:45:43 +0000 (+0000) Subject: Add some tests. X-Git-Tag: channel-coding-branchpoint~117 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f7dbff8c78a2010987bd97a0264ec9ae96b1a28;p=elisp%2Friece.git Add some tests. --- diff --git a/lisp/riece-ruby.el b/lisp/riece-ruby.el index 8a3c66b..e11ec90 100644 --- a/lisp/riece-ruby.el +++ b/lisp/riece-ruby.el @@ -106,6 +106,8 @@ Local to the process buffer.") "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. @@ -196,7 +198,7 @@ Use `riece-ruby-set-property' to set this variable.") (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") @@ -212,11 +214,8 @@ Use `riece-ruby-set-property' to set this variable.") (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)) @@ -224,13 +223,22 @@ Use `riece-ruby-set-property' to set this variable.") (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))) @@ -330,9 +338,17 @@ An output-handler is called when the program sends any output by using `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 diff --git a/lisp/test/test-riece-ruby.el b/lisp/test/test-riece-ruby.el new file mode 100644 index 0000000..7b41b8f --- /dev/null +++ b/lisp/test/test-riece-ruby.el @@ -0,0 +1,98 @@ +(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