summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSebastian Wiesner <lunaryorn@gmail.com>2013-10-20 10:39:01 +0200
committerSebastian Wiesner <lunaryorn@gmail.com>2013-10-20 10:39:01 +0200
commit6e3152b24f2cb55cb18781a6297744777a0a1bc4 (patch)
tree40b0aaf898884be11c945d69b2f6a205b0455d9a /test
parent3c2c33814ed3964f9266d14a0315e8af22bb5094 (diff)
Add tests for pkg-info
Diffstat (limited to 'test')
-rw-r--r--test/.gitignore1
-rw-r--r--test/pkg-info-test.el61
-rw-r--r--test/test-helper.el80
3 files changed, 142 insertions, 0 deletions
diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644
index 0000000..a803a30
--- /dev/null
+++ b/test/.gitignore
@@ -0,0 +1 @@
+/elpa
diff --git a/test/pkg-info-test.el b/test/pkg-info-test.el
new file mode 100644
index 0000000..7bfc95f
--- /dev/null
+++ b/test/pkg-info-test.el
@@ -0,0 +1,61 @@
+;;; pkg-info-tests.el --- Unit tests for pkg-info -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2013 Sebastian Wiesner
+
+;; Author: Sebastian Wiesner <lunaryorn@gmail.com>
+;; Keywords:
+
+;; 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:
+
+;; Unit tests for pkg-info.
+
+;;; Code:
+
+(require 'pkg-info)
+
+(require 'ert)
+
+(require 'pkg-info-dummy-package)
+
+(ert-deftest pkg-info-library-version-feature ()
+ (should (equal (pkg-info-library-version 'pkg-info-dummy-package) '(3 4 2 1)))
+ (should-error (pkg-info-library-version 'no-such-feature))
+ ;; TODO: Fails? We must find a way to get the defining file of a `require'
+ ;; (should (equal (pkg-info-library-version 'pkg-info) pkg-info-version))
+ )
+
+(ert-deftest pkg-info-library-version-filename ()
+ (should (equal (pkg-info-library-version "pkg-info-dummy-package.el")
+ '(3 4 2 1)))
+ (should-error (pkg-info-library-version "no-such-library")))
+
+(ert-deftest pkg-info-defining-library-version ()
+ (should (equal (pkg-info-defining-library-version
+ #'pkg-info-dummy-package-dummy-function)
+ '(3 4 2 1)))
+ (should-error (pkg-info-defining-library-version #'this-is-no-function))
+ (should-error (pkg-info-defining-library-version (lambda () "foo"))))
+
+(ert-deftest pkg-info-format-version ()
+ (should (equal (pkg-info-format-version '(3 4 2 1)) "3.4.2.1"))
+ (should (equal (pkg-info-format-version '(2 1 -3)) "2.1alpha")))
+
+;; Local Variables:
+;; coding: utf-8
+;; indent-tabs-mode: nil
+;; End:
+
+;;; pkg-info-tests.el ends here
diff --git a/test/test-helper.el b/test/test-helper.el
new file mode 100644
index 0000000..7b11dd3
--- /dev/null
+++ b/test/test-helper.el
@@ -0,0 +1,80 @@
+;;; test-helper.el --- pkg-info: Unit test helper -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2013 Sebastian Wiesner
+
+;; Author: Sebastian Wiesner <lunaryorn@gmail.com>
+;; URL: https://github.com/lunaryorn/pkg-info.el
+
+;; 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:
+
+;; Unit test helper for pkg-info
+
+;;; Code:
+
+(require 'cl-lib)
+(require 'find-func)
+(require 'epl)
+(require 'f)
+
+(unless noninteractive
+ (error "The test suite cannot be used interactively."))
+
+(eval-and-compile
+ (defconst pkg-info-test-directory (f-parent (f-this-file))
+ "Directory of unit tests.")
+
+ (defconst pkg-info-source-directory (file-name-as-directory
+ (f-parent pkg-info-test-directory))
+ "Directory of unit tests."))
+
+(require 'pkg-info (f-join pkg-info-source-directory "pkg-info.elc"))
+
+(cl-assert (f-same? (symbol-file #'pkg-info-package-version 'defun)
+ (f-join pkg-info-source-directory "pkg-info.elc"))
+ nil "ERROR: pkg-info not loaded from compiled source. Run make compile")
+
+(defconst pkg-info-version
+ (let ((default-directory pkg-info-source-directory))
+ (version-to-list (car (process-lines "cask" "version"))))
+ "The pkg-info version, to use in unit tests.")
+
+(defconst pkg-info-test-package-directory
+ (f-join pkg-info-test-directory "elpa")
+ "Directory for temporary package installations.")
+
+(defun pkg-info-test-initialize-packages ()
+ "Initialize packages for our unit tests."
+ (epl-change-package-dir pkg-info-test-package-directory)
+ (unless (epl-package-installed-p 'pkg-info-dummy-package)
+ ;; Only install the dummy package if needed
+ (epl-add-archive "localhost" "http://localhost:9191/packages/")
+ (epl-refresh)
+ (let ((package (car (epl-find-available-packages 'pkg-info-dummy-package))))
+ (unless package
+ (error (error "Test dummy package missing. \
+Start servant with cask exec servant start")))
+ (epl-package-install package))))
+
+(pkg-info-test-initialize-packages)
+
+(provide 'test-helper)
+
+;; Local Variables:
+;; indent-tabs-mode: nil
+;; coding: utf-8
+;; End:
+
+;;; test-helper.el ends here