From 18f8fd181e5e99fe5a8793974acca7dc50bd6831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20R=C3=A9mot?= Date: Fri, 10 Feb 2017 13:33:08 +0100 Subject: [PATCH 1/2] Make some private functions public Rename `ede-php-autoload--merge-composer-data` to `ede-php-autoload-composer-merge-composer-data`. This function is now part of the public API for other packages. --- ede-php-autoload-composer.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ede-php-autoload-composer.el b/ede-php-autoload-composer.el index bec85ed..91dd054 100644 --- a/ede-php-autoload-composer.el +++ b/ede-php-autoload-composer.el @@ -1,6 +1,6 @@ ;;; ede-php-autoload-composer.el --- Composer projects detection and analysis -*- lexical-binding: t -*- -;; Copyright (C) 2015, Steven Rémot +;; Copyright (C) 2015, 2017, Steven Rémot ;; Author: Steven Rémot ;; Keywords: PHP project ede @@ -164,7 +164,7 @@ NEW-AUTOLOADS will be merged into BASE-AUTOLOADS. BASE-AUTOLOADS will be mutate autoloads)) -(defun ede-php-autoload--merge-composer-autoloads (composer-data autoloads &optional base-dir) +(defun ede-php-autoload-composer-merge-composer-autoloads (composer-data autoloads &optional base-dir) "Load the autoload information in COMPOSER-DATA and merge it with AUTOLOADS. COMPOSER-DATA is the parsed composer.json file. @@ -249,7 +249,7 @@ Returns the new list of autoloads." CONTEXT is the composer context. AUTOLOADS is the current list of autoloads." - (ede-php-autoload--merge-composer-autoloads (ede-php-autoload-composer-get-composer-data context) autoloads nil)) + (ede-php-autoload-composer-merge-composer-autoloads (ede-php-autoload-composer-get-composer-data context) autoloads nil)) (ede-php-autoload-composer-define-visitor #'ede-php-autoload-composer--merge-composer-data-autoloads) @@ -267,7 +267,7 @@ AUTOLOADS is the current list of autoloads." current-data) (while (< i l) (setq current-data (aref third-party-data i) - autoloads (ede-php-autoload--merge-composer-autoloads + autoloads (ede-php-autoload-composer-merge-composer-autoloads current-data autoloads (ede-php-autoload-composer--get-third-party-dir current-data vendor-dir)) From 36331eb37c319dc7631cfa47c5b75c37c1ab7912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20R=C3=A9mot?= Date: Fri, 10 Feb 2017 13:56:24 +0100 Subject: [PATCH 2/2] Add unit test in ede-php-autoload-composer Add a simple unit test to the function `ede-php-autoload-composer-merge-autoloads` and run it on the CI. --- Cask | 1 + Makefile | 13 ++++++-- test/ede-php-autoload-composer-test.el | 45 ++++++++++++++++++++++++++ test/test-helper.el | 38 ++++++++++++++++++++++ 4 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 test/ede-php-autoload-composer-test.el create mode 100644 test/test-helper.el diff --git a/Cask b/Cask index 67b59cc..3f88a0f 100644 --- a/Cask +++ b/Cask @@ -6,4 +6,5 @@ (development (depends-on "ecukes") + (depends-on "ert-runner") (depends-on "f")) diff --git a/Makefile b/Makefile index 27ca72e..1486b6c 100644 --- a/Makefile +++ b/Makefile @@ -2,14 +2,21 @@ CASK=cask .PHONY: test test-simple elc package clean -test-simple: +test-unit: + $(CASK) exec ert-runner + +test-functional: $(CASK) exec ecukes +test-all: + $(MAKE) test-unit + $(MAKE) test-functional + test: $(MAKE) clean - $(MAKE) test-simple + $(MAKE) test-all $(MAKE) elc - $(MAKE) test-simple + $(MAKE) test-all elc: $(CASK) build diff --git a/test/ede-php-autoload-composer-test.el b/test/ede-php-autoload-composer-test.el new file mode 100644 index 0000000..df78a57 --- /dev/null +++ b/test/ede-php-autoload-composer-test.el @@ -0,0 +1,45 @@ +;;; ede-php-autoload-composer-test.el --- Unit test for ede-php-autoload-composer + +;;; Commentary: +;; +;; Copyright (C) 2017, Steven Rémot + +;; Author: Steven Rémot +;; Keywords: PHP project ede +;; Homepage: https://github.com/stevenremot/ede-php-autoload + +;; This file is not part of GNU Emacs. + +;; 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 2, 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; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Code: + +(ert-deftest ede-php-autoload-composer-merge-autoloads-concats-files () + "`ede-php-autoload-composer-merge-autoloads' should concat provided autoloads." + (should (equal + + (ede-php-autoload-composer-merge-autoloads + '(:psr-0 (("Test" . "test/")) :psr-4 (("Test3" . "test3/"))) + '(:psr-0 (("Test2" . "test2/")) :psr-4 (("Test4" . "test4/")))) + + '(:psr-0 (("Test" . "test/") + ("Test2" . "test2/")) + :psr-4 (("Test3" . "test3/") + ("Test4" . "test4/")))))) + +(provide 'ede-php-autoload-composer-test) + +;;; ede-php-autoload-composer-test.el ends here diff --git a/test/test-helper.el b/test/test-helper.el new file mode 100644 index 0000000..666b87a --- /dev/null +++ b/test/test-helper.el @@ -0,0 +1,38 @@ +;;; test-helper.el --- Unit test bootstrap + +;;; Commentary: +;; +;; Copyright (C) 2017, Steven Rémot + +;; Author: Steven Rémot +;; Keywords: PHP project ede +;; Homepage: https://github.com/stevenremot/ede-php-autoload + +;; This file is not part of GNU Emacs. + +;; 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 2, 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; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Code: + +(add-to-list 'load-path (concat (file-name-directory (or load-file-name buffer-file-name)) "/..")) +(message (concat (or load-file-name buffer-file-name) "/..")) + +(require 'ert) +(require 'ede-php-autoload) + +(provide 'test-helper) + +;;; test-helper.el ends here