Browse Source

Add initial unit-tests

master
Nicolas Petton 3 years ago
committed by Damien Cassou
parent
commit
52cac92d8e
Signed by untrusted user: DamienCassou GPG Key ID: B68746238E59B548
2 changed files with 73 additions and 4 deletions
  1. +4
    -4
      Makefile
  2. +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


+ 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