[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 5e8fe4c 26/69: Add jsonrpc-tests.el
From: |
João Távora |
Subject: |
[elpa] externals/eglot 5e8fe4c 26/69: Add jsonrpc-tests.el |
Date: |
Fri, 22 Jun 2018 11:54:58 -0400 (EDT) |
branch: externals/eglot
commit 5e8fe4c2153ce110287b4f39276dd3d49f92e127
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Add jsonrpc-tests.el
* Makefile (jsonrpc-check): Add test target.
* jsonrpc-tests.el: New file.
---
Makefile | 5 +++
jsonrpc-tests.el | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 109 insertions(+)
diff --git a/Makefile b/Makefile
index 41619fc..cdfeb79 100644
--- a/Makefile
+++ b/Makefile
@@ -28,6 +28,11 @@ check: compile
-l eglot-tests \
-f ert-run-tests-batch-and-exit \
+jsonrpc-check: jsonrpc.elc
+ $(EMACS) -Q --batch $(LOAD_PATH) \
+ -l jsonrpc-tests \
+ -f ert-run-tests-batch-and-exit \
+
# Cleanup
#
clean:
diff --git a/jsonrpc-tests.el b/jsonrpc-tests.el
new file mode 100644
index 0000000..a3de884
--- /dev/null
+++ b/jsonrpc-tests.el
@@ -0,0 +1,104 @@
+;;; jsonrpc-tests.el --- tests for jsonrpc.el -*- lexical-binding: t;
-*-
+
+;; Copyright (C) 2018 Free Software Foundation, Inc.
+
+;; Author: João Távora <address@hidden>
+;; Maintainer: João Távora <address@hidden>
+;; URL: https://github.com/joaotavora/eglot
+;; Keywords: tests
+
+;; 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 <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'ert)
+(require 'jsonrpc)
+
+(cl-defmacro jsonrpc--with-emacsrpc-fixture ((endpoint-sym) &body body)
+ (declare (indent 1) (debug t))
+ (let ((server (gensym)))
+ `(let* ((,server (make-network-process
+ :name "Emacs RPC server" :server t :host "localhost"
:service 44444
+ :log (lambda (_server client _message)
+ (jsonrpc-connect
+ (process-name client) client
+ (lambda (endpoint method id params)
+ (unless (memq method '(+ - * / vconcat append
sit-for))
+ (signal 'jsonrpc-error
`((jsonrpc-error-message
+ . "Sorry, this
isn't allowed")
+ (jsonrpc-error-code
. -32601))))
+ (jsonrpc-reply endpoint id :result
+ (apply method (append params
nil))))))))
+ (,endpoint-sym (jsonrpc-connect
+ "Emacs RPC client" '("localhost" 44444)
+ (lambda (_endpoint method _id &rest _params)
+ (message "server wants to %s" method)))))
+ (unwind-protect
+ ,@body
+ (unwind-protect
+ (delete-process ,server)
+ (delete-process (jsonrpc--process ,endpoint-sym)))))))
+
+(ert-deftest returns-3 ()
+ "returns 3"
+ (jsonrpc--with-emacsrpc-fixture (server-endpoint)
+ (should (= 3 (jsonrpc-request server-endpoint '+ '(1 2))))))
+
+(ert-deftest errors-with--32601 ()
+ "errors with -32601"
+ (jsonrpc--with-emacsrpc-fixture (server-endpoint)
+ (condition-case err
+ (progn
+ (jsonrpc-request server-endpoint 'delete-directory "~/tmp")
+ (ert-fail "A `jsonrpc-error' should have been signalled!"))
+ (jsonrpc-error
+ (should (= -32601 (cdr (assoc 'jsonrpc-error-code (cdr err)))))))))
+
+(ert-deftest signals-an--32603-JSONRPC-error ()
+ "signals an -32603 JSONRPC error"
+ (jsonrpc--with-emacsrpc-fixture (server-endpoint)
+ (condition-case err
+ (progn
+ (jsonrpc-request server-endpoint '+ '(a 2))
+ (ert-fail "A `jsonrpc-error' should have been signalled!"))
+ (jsonrpc-error
+ (should (= -32603 (cdr (assoc 'jsonrpc-error-code (cdr err)))))))))
+
+(ert-deftest times-out ()
+ "times out"
+ (jsonrpc--with-emacsrpc-fixture (server-endpoint)
+ (should-error
+ (jsonrpc-request server-endpoint 'sit-for '(5) :timeout 2))))
+
+(ert-deftest stretching-it-but-works ()
+ "stretching it, but works"
+ (jsonrpc--with-emacsrpc-fixture (server-endpoint)
+ (should (equal
+ [1 2 3 3 4 5]
+ (jsonrpc-request server-endpoint 'vconcat '([1 2 3] [3 4 5]))))))
+
+(ert-deftest json-el-cant-serialize-this ()
+ "json.el can't serialize this, json.el errors and request isn't sent"
+ (jsonrpc--with-emacsrpc-fixture (server-endpoint)
+ (should-error
+ (jsonrpc-request server-endpoint 'append '((1 2 3)
+ (3 4 5))))))
+
+
+(provide 'jsonrpc-tests)
+;;; jsonrpc-tests.el ends here
- [elpa] externals/eglot 7769c07 16/69: Send message, then establish continuations, (continued)
- [elpa] externals/eglot 7769c07 16/69: Send message, then establish continuations, João Távora, 2018/06/22
- [elpa] externals/eglot 7f2e894 11/69: Merge branch 'master' into jsonrpc-refactor (using good ol' git merge), João Távora, 2018/06/22
- [elpa] externals/eglot e5ba4f6 18/69: Automatically reply with error if dispatcher doesn't, João Távora, 2018/06/22
- [elpa] externals/eglot 33ae871 09/69: More flexible jrpc.el and improve eglot.el's doc, João Távora, 2018/06/22
- [elpa] externals/eglot 3265c1d 10/69: Simpler callback protocol for JSONRPC parameters and results, João Távora, 2018/06/22
- [elpa] externals/eglot e906d25 14/69: Overhaul JSON and JSRONRPC error handling, João Távora, 2018/06/22
- [elpa] externals/eglot 7cd94b9 12/69: Improve jrpc.el's doc (and change jrpc-request's protocol a tiny bit), João Távora, 2018/06/22
- [elpa] externals/eglot 489182d 24/69: New jsonrpc-error error type, João Távora, 2018/06/22
- [elpa] externals/eglot 5cea412 20/69: Fix typos and phrasing in commentary and docstrings, João Távora, 2018/06/22
- [elpa] externals/eglot c30f0f3 23/69: Get rid of jsonrpc.el customization group and timeout, João Távora, 2018/06/22
- [elpa] externals/eglot 5e8fe4c 26/69: Add jsonrpc-tests.el,
João Távora <=
- [elpa] externals/eglot 05ff697 29/69: Document current API breaches a bit, João Távora, 2018/06/22
- [elpa] externals/eglot 258e3b0 07/69: Merge master into jsonrpc-refactor (using imerge), João Távora, 2018/06/22
- [elpa] externals/eglot 4bbf810 25/69: Don't return implementation details in jsonrpc-async-request, João Távora, 2018/06/22
- [elpa] externals/eglot 5874af9 32/69: Fix deferred actions (forgot the crucial non-local exit), João Távora, 2018/06/22
- [elpa] externals/eglot 481f16e 33/69: * eglot.el (eglot-eldoc-function): Remove spurious log message, João Távora, 2018/06/22
- [elpa] externals/eglot c43dff4 35/69: On request timeout, clear it from the deferred actions, João Távora, 2018/06/22
- [elpa] externals/eglot 870c60a 04/69: Merge master into jsonrpc-refactor (using imerge), João Távora, 2018/06/22
- [elpa] externals/eglot 980f3e7 34/69: Fix another merge-related bug in eglot-eldoc-function, João Távora, 2018/06/22
- [elpa] externals/eglot fab7f8b 44/69: Improve Makefile test targets, João Távora, 2018/06/22
- [elpa] externals/eglot d7e1b92 42/69: * jsonrpc.el (jsonrpc-message): Fix formatting bug., João Távora, 2018/06/22