Skip to content

Commit

Permalink
Use Servant to provide our test ELPA server
Browse files Browse the repository at this point in the history
  • Loading branch information
swsnr committed Oct 21, 2013
1 parent e06c29e commit 3bce231
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -31,6 +31,6 @@ matrix:
script:
- make ecukes
after_failure:
- cat tmp/server.log
- cat servant/tmp/servant.log
after_script:
- make stop-sever
2 changes: 1 addition & 1 deletion Cask
Expand Up @@ -9,5 +9,5 @@
(depends-on "dash")
(depends-on "ansi")
(depends-on "ecukes")
(depends-on "elnode")
(depends-on "servant")
(depends-on "ert-runner"))
12 changes: 5 additions & 7 deletions Makefile
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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}

Expand Down
63 changes: 63 additions & 0 deletions servant/app.el
@@ -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
7 changes: 7 additions & 0 deletions servant/new-packages/foo-0.0.2.el
@@ -0,0 +1,7 @@
;;; foo.el --- Foo -*- lexical-binding: t; -*-

;; Version: 0.0.2

(provide 'foo)

;;; foo.el ends here
7 changes: 7 additions & 0 deletions servant/packages/bar-0.0.2.el
@@ -0,0 +1,7 @@
;;; bar.el --- bar -*- lexical-binding: t; -*-

;; Version: 0.0.2

(provide 'bar)

;;; bar.el ends here
File renamed without changes.
7 changes: 7 additions & 0 deletions servant/packages/foo-0.0.1.el
@@ -0,0 +1,7 @@
;;; foo.el --- Foo -*- lexical-binding: t; -*-

;; Version: 0.0.1

(provide 'foo)

;;; foo.el ends here
Binary file not shown.
10 changes: 10 additions & 0 deletions servant/packages/qux-0.0.4.el
@@ -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
97 changes: 0 additions & 97 deletions server/app.el

This file was deleted.

1 change: 0 additions & 1 deletion server/bar-0.0.2.el

This file was deleted.

1 change: 0 additions & 1 deletion server/foo-0.0.1.el

This file was deleted.

1 change: 0 additions & 1 deletion server/foo-0.0.2.el

This file was deleted.

4 changes: 0 additions & 4 deletions server/qux-0.0.4.el

This file was deleted.

0 comments on commit 3bce231

Please sign in to comment.