From 3bce2317d7541933235f76a024eaa9203ca1223a Mon Sep 17 00:00:00 2001 From: Sebastian Wiesner Date: Mon, 21 Oct 2013 12:40:23 +0200 Subject: [PATCH] Use Servant to provide our test ELPA server --- .travis.yml | 2 +- Cask | 2 +- Makefile | 12 ++- servant/app.el | 63 +++++++++++++ servant/new-packages/foo-0.0.2.el | 7 ++ servant/packages/bar-0.0.2.el | 7 ++ {server => servant/packages}/baz-0.0.3.tar | Bin servant/packages/foo-0.0.1.el | 7 ++ {server => servant/packages}/hey-0.0.5.tar | Bin 3584 -> 4608 bytes servant/packages/qux-0.0.4.el | 10 +++ server/app.el | 97 --------------------- server/bar-0.0.2.el | 1 - server/foo-0.0.1.el | 1 - server/foo-0.0.2.el | 1 - server/qux-0.0.4.el | 4 - 15 files changed, 101 insertions(+), 113 deletions(-) create mode 100644 servant/app.el create mode 100644 servant/new-packages/foo-0.0.2.el create mode 100644 servant/packages/bar-0.0.2.el rename {server => servant/packages}/baz-0.0.3.tar (100%) create mode 100644 servant/packages/foo-0.0.1.el rename {server => servant/packages}/hey-0.0.5.tar (60%) create mode 100644 servant/packages/qux-0.0.4.el delete mode 100644 server/app.el delete mode 100644 server/bar-0.0.2.el delete mode 100644 server/foo-0.0.1.el delete mode 100644 server/foo-0.0.2.el delete mode 100644 server/qux-0.0.4.el diff --git a/.travis.yml b/.travis.yml index 1b7065f2..a89f340f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,6 @@ matrix: script: - make ecukes after_failure: - - cat tmp/server.log + - cat servant/tmp/servant.log after_script: - make stop-sever diff --git a/Cask b/Cask index abd7e166..49ede038 100644 --- a/Cask +++ b/Cask @@ -9,5 +9,5 @@ (depends-on "dash") (depends-on "ansi") (depends-on "ecukes") - (depends-on "elnode") + (depends-on "servant") (depends-on "ert-runner")) diff --git a/Makefile b/Makefile index 8cd9f86c..050ce4e4 100644 --- a/Makefile +++ b/Makefile @@ -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} diff --git a/servant/app.el b/servant/app.el new file mode 100644 index 00000000..9dd112f3 --- /dev/null +++ b/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 +;; Maintainer: Johan Andersson +;; 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 . + +;;; 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 diff --git a/servant/new-packages/foo-0.0.2.el b/servant/new-packages/foo-0.0.2.el new file mode 100644 index 00000000..23d5ff79 --- /dev/null +++ b/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 diff --git a/servant/packages/bar-0.0.2.el b/servant/packages/bar-0.0.2.el new file mode 100644 index 00000000..8cdf2fe2 --- /dev/null +++ b/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 diff --git a/server/baz-0.0.3.tar b/servant/packages/baz-0.0.3.tar similarity index 100% rename from server/baz-0.0.3.tar rename to servant/packages/baz-0.0.3.tar diff --git a/servant/packages/foo-0.0.1.el b/servant/packages/foo-0.0.1.el new file mode 100644 index 00000000..26a7d301 --- /dev/null +++ b/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 diff --git a/server/hey-0.0.5.tar b/servant/packages/hey-0.0.5.tar similarity index 60% rename from server/hey-0.0.5.tar rename to servant/packages/hey-0.0.5.tar index 2e19da11f55589139be88184435d8f3871775534..d4b45fd7724d229f2275c3d0a9ee4c8bccf41575 100644 GIT binary patch delta 265 zcmZpWX;7KaC2VADXlQC+Y+$BfU}$V)Zo;5oIysRsMWD2}B(aFWz@WH1GqpG`wP>>- zV=E)OiGi6JE)|mnng6is7G$UErRGc&449n4q9|c%s9rR!kOT ze6OLAlA4y8m#SNkn4F!Mo~odfky@#wpk$zDpl1rCJwUv?%pA?l3LG~WC$UUtGchp2 XW#DE();2~qQ;?^y+qhYf{XH814WmsG delta 159 zcmZorX^@%FC2VMFWM*J$VrZ^lU}$7+WXPakIysRsg|D=@B(aFWz@R8KD>b!XqM+1f tO~zbCc4Jcm+)5^EGC!Hj%hAPVU}(yqV1UaU&OAmoBLj0hD!8w+0RWYfEXx1@ diff --git a/servant/packages/qux-0.0.4.el b/servant/packages/qux-0.0.4.el new file mode 100644 index 00000000..611091a1 --- /dev/null +++ b/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 diff --git a/server/app.el b/server/app.el deleted file mode 100644 index 2bd70275..00000000 --- a/server/app.el +++ /dev/null @@ -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 -;; Maintainer: Johan Andersson -;; 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 . - -;;; 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 diff --git a/server/bar-0.0.2.el b/server/bar-0.0.2.el deleted file mode 100644 index 38b29513..00000000 --- a/server/bar-0.0.2.el +++ /dev/null @@ -1 +0,0 @@ -(provide 'bar) diff --git a/server/foo-0.0.1.el b/server/foo-0.0.1.el deleted file mode 100644 index 5c6bf13a..00000000 --- a/server/foo-0.0.1.el +++ /dev/null @@ -1 +0,0 @@ -(provide 'foo) diff --git a/server/foo-0.0.2.el b/server/foo-0.0.2.el deleted file mode 100644 index 5c6bf13a..00000000 --- a/server/foo-0.0.2.el +++ /dev/null @@ -1 +0,0 @@ -(provide 'foo) diff --git a/server/qux-0.0.4.el b/server/qux-0.0.4.el deleted file mode 100644 index b5760610..00000000 --- a/server/qux-0.0.4.el +++ /dev/null @@ -1,4 +0,0 @@ -(defun hello () - (princ "Hello from QUX, which is a BAZ dependency")) - -(provide 'qux)