Permalink
Browse files

Use Servant to provide our test ELPA server

  • Loading branch information...
1 parent e06c29e commit 3bce2317d7541933235f76a024eaa9203ca1223a @lunaryorn lunaryorn committed Oct 21, 2013
View
@@ -31,6 +31,6 @@ matrix:
script:
- make ecukes
after_failure:
- - cat tmp/server.log
+ - cat servant/tmp/servant.log
after_script:
- make stop-sever
View
2 Cask
@@ -9,5 +9,5 @@
(depends-on "dash")
(depends-on "ansi")
(depends-on "ecukes")
- (depends-on "elnode")
+ (depends-on "servant")
(depends-on "ert-runner"))
View
@@ -3,7 +3,7 @@ TAGS ?=
CASK ?= cask
ECUKES = ecukes
ECUKES_ARGS = --script features ${TAGS}
-SERVER = ${CASK} exec ${EMACS} --load server/app.el -Q
+SERVER = ${CASK} exec ${EMACS} -Q --load servant/app.el
PKG_DIR := $(shell ${CASK} package-directory)
@@ -17,11 +17,12 @@ test: elpa unit ecukes
ecukes:
${CASK} exec ${ECUKES} ${ECUKES_ARGS}
-start-server: elpa tmp
- ${SERVER} --batch > tmp/server.log 2>&1 &
+start-server: elpa
+ mkdir -p servant/tmp
+ ${SERVER} --batch > servant/tmp/servant.log 2>&1 &
stop-server:
- kill $$(cat tmp/server.pid)
+ kill $$(cat servant/tmp/servant.pid)
server: elpa
${SERVER} -nw
@@ -33,9 +34,6 @@ ${PKG_DIR}: Cask
# NOTE: `touch` is called here since `cask install` does not update
# timestamp of ${PKG_DIR} directory.
-tmp:
- mkdir $@
-
clean:
rm -rf ${PKG_DIR}
View
@@ -0,0 +1,63 @@
+;;; app.el --- Cask: Stub ELPA server for integration tests -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2012, 2013 Johan Andersson
+
+;; Author: Johan Andersson <johan.rejeep@gmail.com>
+;; Maintainer: Johan Andersson <johan.rejeep@gmail.com>
+;; URL: http://github.com/cask/cask
+
+;; This file is NOT part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; A simple stub ELPA server for Cask's integration tests.
+
+;;; Code:
+
+(require 'f)
+(require 'servant)
+(require 'rx)
+
+(let* ((port 9191)
+ (host "127.0.0.1")
+ (directory (f-parent (f-this-file)))
+ (tmp-directory (f-join directory "tmp"))
+ (routes (--map
+ (cons (format "^.*//%s/\\(.*\\)$" (regexp-quote it))
+ (servant-make-elnode-handler (f-join directory it)))
+ '("packages" "new-packages"))))
+
+ (global-set-key (kbd "q") (lambda ()
+ (interactive)
+ (elnode-stop port)
+ (kill-emacs 0)))
+
+ (insert
+ (format "Running (fake) ELPA server on port %d... Press `q' to quit." port))
+
+ (elnode-start (lambda (httpcon) (elnode-hostpath-dispatcher httpcon routes))
+ :port port :host host)
+
+ (when noninteractive
+ (f-mkdir tmp-directory)
+ (with-temp-file (f-join tmp-directory "servant.pid")
+ (insert (format "%s" (emacs-pid))))
+ ;; Start "event loop".
+ (while t
+ ;; We need `while' due to http://stackoverflow.com/questions/14698081/
+ (sit-for 10))))
+
+;;; app.el ends here
@@ -0,0 +1,7 @@
+;;; foo.el --- Foo -*- lexical-binding: t; -*-
+
+;; Version: 0.0.2
+
+(provide 'foo)
+
+;;; foo.el ends here
@@ -0,0 +1,7 @@
+;;; bar.el --- bar -*- lexical-binding: t; -*-
+
+;; Version: 0.0.2
+
+(provide 'bar)
+
+;;; bar.el ends here
File renamed without changes.
@@ -0,0 +1,7 @@
+;;; foo.el --- Foo -*- lexical-binding: t; -*-
+
+;; Version: 0.0.1
+
+(provide 'foo)
+
+;;; foo.el ends here
Binary file not shown.
@@ -0,0 +1,10 @@
+;;; qux.el --- Qux -*- lexical-binding: t; -*-
+
+;; Version: 0.0.4
+
+(defun hello ()
+ (princ "Hello from QUX, which is a BAZ dependency"))
+
+(provide 'qux)
+
+;;; qux.el ends here
View
@@ -1,97 +0,0 @@
-;;; app.el --- Cask: Stub ELPA server for integration tests -*- lexical-binding: t; -*-
-
-;; Copyright (C) 2012, 2013 Johan Andersson
-
-;; Author: Johan Andersson <johan.rejeep@gmail.com>
-;; Maintainer: Johan Andersson <johan.rejeep@gmail.com>
-;; URL: http://github.com/cask/cask
-
-;; This file is NOT part of GNU Emacs.
-
-;; This program is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; This program is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; A simple stub ELPA server for Cask's integration tests.
-
-;;; Code:
-
-(require 'elnode)
-
-(defvar port 9191)
-
-(defvar routes
- '(("\/packages\/archive-contents" . archive-handler)
- ("\/new-packages\/archive-contents" . new-archive-handler)
- ("\/\\(new-\\)?packages\/\\(.+\\)-\\(.+\\)\.\\(tar\\|el\\)$" . package-handler)))
-
-(defun root-handler (httpcon)
- (elnode-hostpath-dispatcher httpcon routes))
-
-(defun new-archive-handler (httpcon)
- (elnode-http-start httpcon 200 '("Content-type" . "text/plain"))
- (elnode-http-return httpcon "(1 (foo . [(0 0 2) nil \"New foo\" single]))"))
-
-(defun archive-handler (httpcon)
- (elnode-http-start httpcon 200 '("Content-type" . "text/plain"))
- (elnode-http-return httpcon "(1
- (foo . [(0 0 1) nil \"Foo\" single])
- (bar . [(0 0 2) nil \"Bar\" single])
- (baz . [(0 0 3) ((qux (0 0 4))) \"Baz\" tar])
- (qux . [(0 0 4) nil \"Qux\" single])
- (hey . [(0 0 5) nil \"Hey\" tar]))"))
-
-(defun package-handler (httpcon)
- (let* ((name (elnode-http-mapping httpcon 2))
- (version (elnode-http-mapping httpcon 3))
- (format (elnode-http-mapping httpcon 4))
- (filename
- (expand-file-name
- (concat name "-" version "." format) "server"))
- (content-type
- (if (equal format "el")
- "application/octet-stream"
- "application/x-tar"))
- (content
- (with-temp-buffer
- (insert-file-contents-literally filename)
- (buffer-string)))
- (content-length (length content)))
- (elnode-http-start
- httpcon 200
- `("Content-type" . ,content-type)
- `("Content-length" . ,content-length))
- (elnode-http-return httpcon content)))
-
-(defun stop-and-quit ()
- (interactive)
- (elnode-stop port)
- (kill-emacs 0))
-
-(global-set-key (kbd "q") 'stop-and-quit)
-
-(insert
- (format "Running (fake) ELPA server on port %d... Press `q' to quit." port))
-
-(elnode-start 'root-handler :port port :host "localhost")
-
-(when noninteractive
- (with-temp-file "tmp/server.pid"
- (insert (format "%s" (emacs-pid))))
- ;; Start "event loop".
- (while t
- ;; We need `while' due to http://stackoverflow.com/questions/14698081/
- (sit-for most-positive-fixnum)))
-
-;;; app.el ends here
View
@@ -1 +0,0 @@
-(provide 'bar)
View
@@ -1 +0,0 @@
-(provide 'foo)
View
@@ -1 +0,0 @@
-(provide 'foo)
View
@@ -1,4 +0,0 @@
-(defun hello ()
- (princ "Hello from QUX, which is a BAZ dependency"))
-
-(provide 'qux)

0 comments on commit 3bce231

Please sign in to comment.