Skip to content

Commit 12a0dfd

Browse files
authored
Merge pull request #8 from J3RN/add-tests
Add tests
2 parents b526ce8 + 8649723 commit 12a0dfd

File tree

4 files changed

+124
-4
lines changed

4 files changed

+124
-4
lines changed

.circleci/config.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: 2.1
2+
3+
jobs:
4+
test:
5+
working_directory: /app
6+
docker:
7+
- image: ghcr.io/j3rn/emacs-elixir:v1
8+
steps:
9+
- checkout
10+
- run: emacs -batch -l ert -l inf-elixir.el -l tests/inf-elixir-test.el -f ert-run-tests-batch-and-exit
11+
12+
workflows:
13+
test:
14+
jobs: [test]

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# inf-elixir
22
[![License GPL 3][badge-license]](http://www.gnu.org/licenses/gpl-3.0.txt)
33
[![MELPA](https://melpa.org/packages/inf-elixir-badge.svg)](https://melpa.org/#/inf-elixir)
4+
[![CircleCI status](https://circleci.com/gh/J3RN/inf-elixir.svg?style=svg)](https://app.circleci.com/pipelines/github/J3RN/inf-elixir)
45

56
This is a package to allow you to pop open and interact with Elixir REPL (IEx, presently).
67

@@ -41,3 +42,18 @@ Once your installation is configured to use MELPA, `inf-elixir` can be installed
4142
An example of keybindings is included in the `use-package` declaration above.
4243

4344
[badge-license]: https://img.shields.io/badge/license-GPL_3-green.svg
45+
46+
## Development
47+
48+
I am not yet using any kind of build tool (like [Eldev](https://github.com/doublep/eldev) or [Cask](https://github.com/cask/cask)) to develop this plugin. Generally speaking, working with the code involves:
49+
1. Clone the git repository
50+
2. Make some changes
51+
3. Load your changes with `M-x load-file RET inf-elixir.el RET`
52+
4. Verify your changes worked
53+
5. Send a PR :pray:
54+
55+
There are some tests written with [ERT](https://www.gnu.org/software/emacs/manual/html_node/ert/index.html) that can be run with this command:
56+
57+
```
58+
$ emacs -batch -l ert -l inf-elixir.el -l tests/inf-elixir-test.el -f ert-run-tests-batch-and-exit
59+
```

inf-elixir.el

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,8 @@ Always returns a REPL buffer for DIR."
164164
"Create a new IEx buffer and run CMD in project DIR.
165165
166166
DIR should be an absolute path to the root level of a Mix project (where the
167-
mix.exs file is).
168-
169-
A value of nil for DIR indicates that the REPL should not belong to any
170-
project and should be created as a global REPL."
167+
mix.exs file is). A value of nil for DIR indicates that the REPL should not
168+
belong to any project."
171169
(inf-elixir--maybe-kill-repl dir)
172170
(inf-elixir--maybe-clear-repl dir)
173171
(pop-to-buffer (inf-elixir--maybe-start-repl dir (split-string cmd))))

tests/inf-elixir-test.el

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
;;; inf-elixir-test.el --- Inf-Elixir's test suite -*- lexical-binding: t -*-
2+
3+
;;; Commentary:
4+
;; Inf-Elixir uses ERT for testing.
5+
;; Run tests with:
6+
;; $ emacs -batch -l ert -l inf-elixir.el -l tests/inf-elixir-test.el -f ert-run-tests-batch-and-exit
7+
8+
;;; Code:
9+
10+
(require 'inf-elixir)
11+
12+
(defmacro inf-elixir-with-project (&rest body)
13+
"Create an Elixir project directory and eval BODY there."
14+
(let ((temp-dir (concat temporary-file-directory (file-name-as-directory "inf-elixir-test"))))
15+
`(unwind-protect
16+
(progn
17+
(make-directory ,temp-dir)
18+
(let ((default-directory ,temp-dir))
19+
(with-temp-buffer
20+
(insert "defmodule Foobar.MixProject do
21+
use Mix.Project
22+
23+
def project do
24+
[
25+
app: :foobar,
26+
version: \"0.1.0\"
27+
]
28+
end
29+
end")
30+
(write-file "mix.exs"))
31+
,@body))
32+
(when (file-directory-p ,temp-dir)
33+
(delete-directory ,temp-dir t)))))
34+
35+
(defmacro inf-elixir-with-cleanup (&rest body)
36+
"Evaulate BODY and cleanup inf-elixir side-effects afterwards."
37+
`(unwind-protect
38+
(progn
39+
,@body)
40+
(let ((kill-buffer-query-functions nil))
41+
(when-let ((inf-elixir-buf (get-buffer "*Inf-Elixir*")))
42+
(kill-buffer inf-elixir-buf))
43+
44+
(maphash
45+
(lambda (proj buffer) (kill-buffer buffer))
46+
inf-elixir-project-buffers)
47+
48+
(clrhash inf-elixir-project-buffers))))
49+
50+
(ert-deftest inf-elixir-run-cmd ()
51+
"`inf-elixir-run-cmd' opens new buffer running cmd."
52+
(inf-elixir-with-cleanup
53+
(inf-elixir-run-cmd nil "iex")
54+
(should (process-live-p (get-buffer-process (current-buffer))))
55+
(should (equal (buffer-name (current-buffer)) "*Inf-Elixir*"))
56+
(should (equal
57+
(process-command (get-buffer-process (current-buffer)))
58+
'("iex")))))
59+
60+
(ert-deftest inf-elixir-has-no-project ()
61+
"The `inf-elixir' command does not associate REPL with a project."
62+
(inf-elixir-with-cleanup
63+
(inf-elixir)
64+
(should (process-live-p (get-buffer-process (current-buffer))))
65+
(should (equal (buffer-name (current-buffer)) "*Inf-Elixir*"))
66+
(maphash
67+
(lambda (proj buffer) (should-not (eq buffer (current-buffer))))
68+
inf-elixir-project-buffers)))
69+
70+
(ert-deftest inf-elixir-project-has-project ()
71+
"The `inf-elixir-project' command associates a REPL with a project."
72+
(inf-elixir-with-project
73+
(inf-elixir-with-cleanup
74+
(inf-elixir-project)
75+
(should (process-live-p (get-buffer-process (current-buffer))))
76+
(should (equal (buffer-name (current-buffer)) "*Inf-Elixir - inf-elixir-test*"))
77+
(should (gethash default-directory inf-elixir-project-buffers)))))
78+
79+
(ert-deftest inf-elixir-send-within-project ()
80+
"`inf-elixir-send-line' sends text to a REPL within the project."
81+
(inf-elixir-with-project
82+
(inf-elixir-with-cleanup
83+
(inf-elixir-project)
84+
(while (not (string-match-p "iex(1)>" (buffer-string))) (sleep-for 0 10))
85+
(with-temp-buffer
86+
(insert "1 + 1")
87+
(inf-elixir-send-line))
88+
(sleep-for 0 500)
89+
(should (string-match-p "iex(1)> 2" (buffer-string))))))
90+
91+
(provide 'inf-elixir-test)
92+
;;; inf-elixir-test.el ends here

0 commit comments

Comments
 (0)