[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 37/119: fixed tests, running and passing
From: |
Eric Schulte |
Subject: |
[elpa] 37/119: fixed tests, running and passing |
Date: |
Mon, 10 Mar 2014 16:57:14 +0000 |
eschulte pushed a commit to branch master
in repository elpa.
commit 9337310771fd1398bc235ee49808e9b8551bbf12
Author: Eric Schulte <address@hidden>
Date: Mon Dec 23 15:44:20 2013 -0700
fixed tests, running and passing
---
emacs-web-server-test.el | 74 +++++++++++++++++++++++++---------------------
1 files changed, 40 insertions(+), 34 deletions(-)
diff --git a/emacs-web-server-test.el b/emacs-web-server-test.el
index 21d7d5e..5649c91 100644
--- a/emacs-web-server-test.el
+++ b/emacs-web-server-test.el
@@ -14,53 +14,57 @@
(eval-when-compile (require 'cl))
(require 'ert)
-(defun ews-test-run-asynch (continuation program &rest program-args)
- (let* ((buffer (generate-new-buffer "*ews-test-run-asynch*"))
- (proc (apply #'start-process "ews-test" buffer program program-args)))
- (set-process-sentinel proc
- (lexical-let ((cont continuation)
- (buf buffer))
- (lambda (proc signal)
- (when (memq (process-status proc) '(exit signal))
- (funcall cont (prog1 (with-current-buffer buf
- (buffer-string))
- (kill-buffer buf)))))))))
-
(defvar ews-test-port 8999)
+(defun ews-test-curl-to-string (url &optional get-params post-params)
+ "Curl URL with optional parameters."
+ (async-shell-command
+ (format "curl -m 4 %s %s localhost:%s/%s"
+ (if get-params
+ (format "%s %S"
+ (mapconcat (lambda (p) (format "%s=%s" (car p) (cdr p)))
+ get-params "&"))
+ "")
+ (if post-params
+ (mapconcat (lambda (p) (format "-s -F '%s=%s'" (car p) (cdr p)))
+ post-params " ")
+ "")
+ ews-test-port url))
+ (unwind-protect
+ (with-current-buffer "*Async Shell Command*"
+ (while (get-buffer-process (current-buffer)) (sit-for 0.1))
+ (goto-char (point-min))
+ (buffer-string))
+ (kill-buffer "*Async Shell Command*")))
+
+(defmacro ews-test-with (handler &rest body)
+ (declare (indent 1))
+ (let ((srv (gensym)))
+ `(let* ((,srv (ews-start ,handler ews-test-port)))
+ (unwind-protect (progn ,@body) (ews-stop ,srv)))))
+(def-edebug-spec ews-test-with (form body))
+
(ert-deftest ews/keyword-style-handler ()
"Ensure that a simple keyword-style handler matches correctly."
- (let ((handler (mapcar (lambda (letter)
+ (ews-test-with (mapcar (lambda (letter)
`((:GET . ,letter) .
(lambda (proc request)
(ews-response-header proc 200
'("Content-type" . "text/plain"))
(process-send-string proc
(concat "returned:" ,letter)))))
- '("a" "b"))))
- (lexical-let ((server (ews-start handler ews-test-port)))
- (ews-test-run-asynch
- (lambda (response)
- (should (string= response "returned:a"))
- (ews-stop server))
- "curl" "-s" (format "localhost:%d/a" ews-test-port)))))
+ '("a" "b"))
+ (should (string= "returned:a" (ews-test-curl-to-string "a")))
+ (should (string= "returned:b" (ews-test-curl-to-string "b")))))
(ert-deftest ews/function-style-handler ()
"Test that a simple hello-world server responds."
- (lexical-let
- ((server
- (ews-start
- '(((lambda (_) t) .
- (lambda (proc request)
- (ews-response-header proc 200 '("Content-type" . "text/plain"))
- (process-send-string proc "hello world")
- :finished)))
- ews-test-port)))
- (ews-test-run-asynch
- (lambda (response)
- (should (string= response "hello world"))
- (ews-stop server))
- "curl" "-s" (format "localhost:%d" ews-test-port))))
+ (ews-test-with
+ '(((lambda (_) t) .
+ (lambda (proc request)
+ (ews-response-header proc 200 '("Content-type" . "text/plain"))
+ (process-send-string proc "hello world"))))
+ (should (string= (ews-test-curl-to-string "") "hello world"))))
(ert-deftest ews/removed-from-ews-servers-after-stop ()
(let ((start-length (length ews-servers)))
@@ -163,3 +167,5 @@
org=-+one%0A-+two%0A-+three%0A-+four%0A%0A&beg=646&end=667&path=%2Fcomplex.org")
"))))
(ews-stop server))))
+
+(provide 'emacs-web-server-test)
- [elpa] 28/119: testing a hello-world server, (continued)
- [elpa] 28/119: testing a hello-world server, Eric Schulte, 2014/03/10
- [elpa] 27/119: run test processes asynch, Eric Schulte, 2014/03/10
- [elpa] 29/119: update examples, Eric Schulte, 2014/03/10
- [elpa] 31/119: match more HTTP methods, Eric Schulte, 2014/03/10
- [elpa] 30/119: fleshed out some more tests, Eric Schulte, 2014/03/10
- [elpa] 32/119: url-encoded parameters, Eric Schulte, 2014/03/10
- [elpa] 34/119: found a confounding POST example, Eric Schulte, 2014/03/10
- [elpa] 33/119: ews-subdirectoryp convenience function, Eric Schulte, 2014/03/10
- [elpa] 36/119: bug fix, Eric Schulte, 2014/03/10
- [elpa] 35/119: cleaned up header/param parsing, Eric Schulte, 2014/03/10
- [elpa] 37/119: fixed tests, running and passing,
Eric Schulte <=
- [elpa] 39/119: removed extra comments from examples, Eric Schulte, 2014/03/10
- [elpa] 40/119: moving around examples, Eric Schulte, 2014/03/10
- [elpa] 42/119: Makefile integration, Eric Schulte, 2014/03/10
- [elpa] 44/119: note, Eric Schulte, 2014/03/10
- [elpa] 43/119: more, Eric Schulte, 2014/03/10
- [elpa] 41/119: including examples in documentation, Eric Schulte, 2014/03/10
- [elpa] 47/119: even more documentation and examples, Eric Schulte, 2014/03/10
- [elpa] 48/119: update README, Eric Schulte, 2014/03/10
- [elpa] 49/119: small updates to README and NOTES, Eric Schulte, 2014/03/10
- [elpa] 50/119: MAYBE incremental handler calls, Eric Schulte, 2014/03/10