Browse Source

Merge branch 'add-tests' into 'master'

Add tests

See merge request nico/json-process-client!1
pull/2/head
Damien Cassou 4 years ago
parent
commit
7354c41197
3 changed files with 77 additions and 8 deletions
  1. +4
    -4
      Makefile
  2. +4
    -4
      json-process-client.el
  3. +69
    -0
      test/json-process-client-test.el

+ 4
- 4
Makefile View File

@ -1,10 +1,10 @@
ELPA_DEPENDENCIES=package-lint
ELPA_DEPENDENCIES=package-lint buttercup
ELPA_ARCHIVES=melpa
TEST_ERT_FILES=$(wildcard test/*.el)
TEST_BUTTERCUP_OPTIONS=test/
LINT_CHECKDOC_FILES=$(wildcard *.el) $(wildcard test/*.el)
LINT_PACKAGE_LINT_FILES=$(wildcard *.el) $(wildcard test/*.el)
LINT_PACKAGE_LINT_FILES=$(wildcard *.el)
LINT_COMPILE_FILES=$(wildcard *.el) $(wildcard test/*.el)
LINT_CHECKDOC_OPTIONS=--eval "(setq checkdoc-arguments-in-order-flag nil)"
@ -17,7 +17,7 @@ makel.mk:
curl \
--fail --silent --show-error --insecure --location \
--retry 9 --retry-delay 9 \
-O https://gitlab.petton.fr/DamienCassou/makel/raw/v0.5.1/makel.mk; \
-O https://gitlab.petton.fr/DamienCassou/makel/raw/v0.5.2/makel.mk; \
fi
# Include makel.mk if present


+ 4
- 4
json-process-client.el View File

@ -187,7 +187,7 @@ If DEBUG is non-nil, send all messages to a debug buffer. If
DEBUG is a string, use this as the name for the debug buffer.
ARGS are passed to EXECUTABLE."
(let* ((executable (executable-find executable))
(let* ((executable-path (executable-find executable))
(debug-buffer (when debug
(get-buffer-create
(if (stringp debug)
@ -195,7 +195,7 @@ ARGS are passed to EXECUTABLE."
(format "*json-process-client-%s*" name)))))
(application (json-process-client--application-create
:name name
:executable executable
:executable executable-path
:port port
:args args
:tcp-started-callback tcp-started-callback
@ -204,8 +204,8 @@ ARGS are passed to EXECUTABLE."
:delete-callback delete-callback
:started-regexp started-regexp
:debug-buffer debug-buffer)))
(unless executable
(user-error "Cannot find executable `%s'" executable))
(unless executable-path
(user-error "Cannot find executable \"%s\"" executable))
(when (bufferp debug-buffer)
(with-current-buffer debug-buffer


+ 69
- 0
test/json-process-client-test.el View File

@ -0,0 +1,69 @@
;;; json-process-client-test.el --- Test for json-process-client.el -*- lexical-binding: t; -*-
;; Copyright (C) 2016-2018 Nicolas Petton
;; Author: Nicolas Petton <nicolas@petton.fr>
;; 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:
;;; Code:
(require 'buttercup)
(require 'json-process-client)
(describe "json-process-client-start"
(it "should signal a user error when the executable cannot be found"
(expect (json-process-client-start :executable "foobarbaz")
:to-throw
'user-error '("Cannot find executable \"foobarbaz\""))))
(describe "Reading server messages"
(it "should not change the buffer when reading an incomplete message"
(with-temp-buffer
(insert "{foo")
(json-process-client--handle-data (current-buffer))
(expect (buffer-string) :to-equal "{foo")))
(it "should call `json-process-client--handle-message' when reading a complete message"
(spy-on #'json-process-client--handle-message)
(with-temp-buffer
(insert "{\"foo\": 1}\n")
(json-process-client--handle-data (current-buffer))
(expect #'json-process-client--handle-message :to-have-been-called-with nil '((foo . 1)))))
(it "should remove the linefeed char when reading a complete message"
(spy-on #'json-process-client--handle-message)
(with-temp-buffer
(insert "{\"foo\": 1}\n")
(json-process-client--handle-data (current-buffer))
(expect (buffer-string) :to-equal "")))
(it "should remove all linefeed chars when reading multiple complete messages"
(spy-on #'json-process-client--handle-message)
(with-temp-buffer
(insert "{\"foo\": 1}\n{\"bar\": 2}\n")
(json-process-client--handle-data (current-buffer))
(expect (buffer-string) :to-equal "")))
(it "should remove all linefeed chars but keep incomplete messages"
(spy-on #'json-process-client--handle-message)
(with-temp-buffer
(insert "{\"foo\": 1}\n{\"bar\": 2}\n{\"baz")
(json-process-client--handle-data (current-buffer))
(expect (buffer-string) :to-equal "{\"baz"))))
(provide 'json-process-client-test)
;;; json-process-client-test.el ends here

Loading…
Cancel
Save