Skip to content

Commit 9b1b709

Browse files
landakramLefterisJP
authored andcommitted
Add some tests for remapping logic
1 parent d14acf9 commit 9b1b709

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
solidity-mode.elc
1+
solidity-mode.elc
2+
test/elpa
3+
test/straight

test/solidity-flycheck-tests.el

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
;;; solidity-flycheck-tests.el --- Setup and execute all tests
2+
3+
;;; Commentary:
4+
5+
;; This package contains tests for the solidity-flycheck package.
6+
7+
;;; Code:
8+
9+
(require 'solidity-flycheck)
10+
11+
(ert-deftest test-solidity-flycheck--solc-allow-paths ()
12+
"Test that `solidity-flycheck--solc-allow-paths' contains `solidity-flycheck-solc-additional-allow-paths'."
13+
(let ((solidity-flycheck-solc-additional-allow-paths '("/tmp/test1" "/tmp/test2")))
14+
(should (equal
15+
(solidity-flycheck--solc-allow-paths)
16+
'("/tmp/test1" "/tmp/test2" ".")))))
17+
18+
(defmacro with-temp-dirs (temp-dirs &rest body)
19+
(let ((bindings (mapcar (lambda (d) `(,d (make-temp-file "" t)))
20+
temp-dirs)))
21+
`(let ,bindings
22+
(unwind-protect
23+
(progn
24+
,@body)
25+
(progn
26+
(dolist (d (list ,@temp-dirs))
27+
(delete-directory d t)))))))
28+
29+
(ert-deftest test-solidity-flycheck--solc-remappings ()
30+
"Test that `solidity-flycheck--solc-remappings' creates remappings for path in `solidity-flycheck--solc-allow-paths'"
31+
(with-temp-dirs
32+
(test-dir-1 test-dir-2 test-dir-3)
33+
(let* ((default-directory test-dir-1)
34+
(solidity-flycheck-solc-additional-allow-paths (list test-dir-2 test-dir-3)))
35+
(make-directory (concat (file-name-as-directory test-dir-2) "subdir1"))
36+
(make-directory (concat (file-name-as-directory test-dir-3) "@subdir2"))
37+
(should (equal
38+
(solidity-flycheck--solc-remappings)
39+
(list (concat "subdir1=" (concat (file-name-as-directory test-dir-2) "subdir1"))
40+
(concat "@subdir2=" (concat (file-name-as-directory test-dir-3) "@subdir2")))))))
41+
)
42+
43+
(provide 'solidity-flycheck-tests)
44+
;;; solidity-flycheck-tests.el ends here

test/solidity-mode-test-setup.el

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
;;; solidity-mode-test-setup.el --- Setup and execute all tests
2+
3+
;;; Commentary:
4+
5+
;; This package sets up a suitable enviroment for testing
6+
;; solidity-mode, and executes the tests.
7+
;;
8+
;; Usage:
9+
;;
10+
;; emacs -q -l test/solidity-mode-test-setup.el
11+
;;
12+
;; Note that this package assumes that some packages are located in
13+
;; specific locations.
14+
15+
;;; Code:
16+
17+
(setq user-init-file (or load-file-name (buffer-file-name)))
18+
(setq user-emacs-directory (file-name-directory user-init-file))
19+
20+
(require 'package)
21+
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
22+
(setq package-enable-at-startup nil)
23+
(package-initialize)
24+
(when (not package-archive-contents)
25+
(package-refresh-contents))
26+
27+
(defvar bootstrap-version)
28+
(let ((bootstrap-file
29+
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
30+
(bootstrap-version 5))
31+
(unless (file-exists-p bootstrap-file)
32+
(with-current-buffer
33+
(url-retrieve-synchronously
34+
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
35+
'silent 'inhibit-cookies)
36+
(goto-char (point-max))
37+
(eval-print-last-sexp)))
38+
(load bootstrap-file nil 'nomessage))
39+
40+
(straight-use-package 'use-package)
41+
42+
(add-to-list 'load-path (expand-file-name "./"))
43+
(add-to-list 'load-path (expand-file-name "./test"))
44+
(package-install-file "solidity-mode.el")
45+
(package-install-file "solidity-flycheck.el")
46+
(global-flycheck-mode 1)
47+
48+
(use-package solidity-mode
49+
:mode ("\\.sol\\'" . solidity-mode))
50+
51+
(use-package solidity-flycheck
52+
:defer t
53+
:init
54+
(setq solidity-flycheck-solium-checker-active t)
55+
(setq solidity-flycheck-solc-checker-active t)
56+
(setq solidity-flycheck-chaining-error-level t)
57+
(setq solidity-flycheck-use-project t)
58+
(setq solidity-flycheck-solc-additional-allow-paths '("~/.brownie/packages"))
59+
(add-hook
60+
'solidity-mode-hook
61+
(lambda ()
62+
(require 'solidity-flycheck))))
63+
64+
(require 'ert)
65+
66+
(require 'solidity-flycheck-tests)
67+
68+
(ert t)

0 commit comments

Comments
 (0)