From ebae3f8d55ce3a241c8632d9144761b8055ea66c Mon Sep 17 00:00:00 2001 From: AdrieanKhisbe Date: Tue, 29 Dec 2015 11:30:28 +0100 Subject: [PATCH 1/6] Add Cask file --- Cask | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Cask diff --git a/Cask b/Cask new file mode 100644 index 0000000..7a87d26 --- /dev/null +++ b/Cask @@ -0,0 +1,11 @@ +(source gnu) +(source melpa) + +(package-file "ffi.el") + +(development + (depends-on "f") + (depends-on "ecukes") + (depends-on "ert-runner") + (depends-on "el-mock") + (depends-on "cask-package-toolset")) From e94fb2c64b4fd0ab4951bb3a0ec28c5863221107 Mon Sep 17 00:00:00 2001 From: AdrieanKhisbe Date: Tue, 29 Dec 2015 11:36:08 +0100 Subject: [PATCH 2/6] Add headers to package --- ffi.el | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/ffi.el b/ffi.el index 8f79a7c..bb6c254 100644 --- a/ffi.el +++ b/ffi.el @@ -1,4 +1,32 @@ -;; -*- lexical-binding:t -*- +;;; ffi.el --- FFI(Foreign Function Interface) for Emacs -*- lexical-binding: t; -*- + +;; Copyright (C) 2015 Tom Tromey + +;; Version: 0.0.1 +;; Author: Tom Tromey +;; Keywords: c, languages, extensions + +;; 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 . + +;;; Commentary: + +;; This is an FFI for Emacs. It is based on libffi and relies on the +;; dynamic modules work (available on the Emacs 25 branch) in order to +;; be loaded into Emacs. It is relatively full-featured, but for the +;; time being low-level. + +;;; Code: (require 'cl-macs) @@ -140,3 +168,4 @@ SLOT-NAME is a symbol and TYPE is an FFI type descriptor." `(with-ffi-string ,first-binding ,@body)))) (provide 'ffi) +;;; ffi.el ends here From d01e174f460025a5c8395aa0e597b0a725835632 Mon Sep 17 00:00:00 2001 From: AdrieanKhisbe Date: Tue, 29 Dec 2015 11:47:45 +0100 Subject: [PATCH 3/6] Travis draft and updated makefile/gitignore --- .gitignore | 14 +++++++++++++- .travis.yml | 14 ++++++++++++++ Makefile | 9 ++++++--- 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 .travis.yml diff --git a/.gitignore b/.gitignore index f3f23e7..b3740f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,17 @@ -*~ +# ffi specifics ffi-module.o ffi-module.so test.o test.so + +# Compiled and temporary files +*.elc +*~ + +# Cask +/.cask +dist + +# Ecukes +/features/project/.cask +/features/project/test/*.el diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..fdf56da --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: generic +sudo: false +before_install: + - curl -fsSkL https://gist.github.com/rejeep/ebcd57c3af83b049833b/raw > x.sh && source ./x.sh + - evm install $EVM_EMACS --use --skip + - cask +env: + - EVM_EMACS=emacs-git-snapshot-travis +script: + - emacs --version + - make test + +notifications: + email: false \ No newline at end of file diff --git a/Makefile b/Makefile index d4d1dc2..452b30d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ +EMACS ?= emacs # Where your dynamic-module-enabled Emacs build lies. -EMACS_BUILDDIR = /home/tromey/Emacs/emacs +# EMACS = /home/tromey/Emacs/emacs/src/emacs +CASK ?= cask LDFLAGS = -shared LIBS = -lffi -lltdl @@ -10,6 +12,8 @@ CFLAGS += -g3 -Og -finline-small-functions -shared -fPIC -I$(EMACS_BUILDDIR)/src all: ffi-module.so +test: check + ffi-module.so: ffi-module.o $(CC) $(LDFLAGS) -o ffi-module.so ffi-module.o $(LIBS) @@ -18,8 +22,7 @@ ffi-module.o: ffi-module.c check: ffi-module.so test.so LD_LIBRARY_PATH=`pwd`:$$LD_LIBRARY_PATH; \ export LD_LIBRARY_PATH; \ - $(GDB) $(EMACS_BUILDDIR)/src/emacs -batch -L `pwd` -l ert -l test.el \ - -f ert-run-tests-batch-and-exit + $(GDB) $(CASK) exec ert-runner test.so: test.o $(CC) $(LDFLAGS) -o test.so test.o From dc1e224411a78a2f4e64b4dc24fe8a068fa2d219 Mon Sep 17 00:00:00 2001 From: AdrieanKhisbe Date: Tue, 29 Dec 2015 11:52:42 +0100 Subject: [PATCH 4/6] Update test structure according ert-runner standard --- .ert-runner | 1 + .gitignore | 4 ++-- Makefile | 8 +++---- test/emacs-ffi-test.el | 10 +++++++++ test.c => test/ffi-test.c | 0 test.el => test/ffi-test.el | 8 +++++-- test/test-helper.el | 42 +++++++++++++++++++++++++++++++++++++ 7 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 .ert-runner create mode 100644 test/emacs-ffi-test.el rename test.c => test/ffi-test.c (100%) rename test.el => test/ffi-test.el (97%) create mode 100644 test/test-helper.el diff --git a/.ert-runner b/.ert-runner new file mode 100644 index 0000000..e35e9c9 --- /dev/null +++ b/.ert-runner @@ -0,0 +1 @@ +-L . diff --git a/.gitignore b/.gitignore index b3740f7..b0fd0c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ # ffi specifics ffi-module.o ffi-module.so -test.o -test.so +test/ffi-test.o +test/ffi-test.so # Compiled and temporary files *.elc diff --git a/Makefile b/Makefile index 452b30d..f139c36 100644 --- a/Makefile +++ b/Makefile @@ -19,15 +19,15 @@ ffi-module.so: ffi-module.o ffi-module.o: ffi-module.c -check: ffi-module.so test.so +check: ffi-module.so test/ffi-test.so LD_LIBRARY_PATH=`pwd`:$$LD_LIBRARY_PATH; \ export LD_LIBRARY_PATH; \ $(GDB) $(CASK) exec ert-runner -test.so: test.o - $(CC) $(LDFLAGS) -o test.so test.o +test/ffi-test.so: test/ffi-test.o + $(CC) $(LDFLAGS) -o test/ffi-test.so test/ffi-test.o -test.o: test.c +test/ffi-test.o: test/ffi-test.c clean: -rm -f ffi-module.o ffi-module.so test.o test.so diff --git a/test/emacs-ffi-test.el b/test/emacs-ffi-test.el new file mode 100644 index 0000000..ec0aea6 --- /dev/null +++ b/test/emacs-ffi-test.el @@ -0,0 +1,10 @@ +;;; Test for `emacs-ffi' + +;;; Commentary: +;; These are the tests for `emacs-ffi' + +;;; Code: + +(ert-deftest emacs-ffi-should-not-pass () + (should-not nil)) + diff --git a/test.c b/test/ffi-test.c similarity index 100% rename from test.c rename to test/ffi-test.c diff --git a/test.el b/test/ffi-test.el similarity index 97% rename from test.el rename to test/ffi-test.el index e5ae46c..10b3448 100644 --- a/test.el +++ b/test/ffi-test.el @@ -1,5 +1,9 @@ +;;; Test for `ffi' -(require 'ffi) +;;; Commentary: +;; These are the tests for `ffi' + +;;; Code: (define-ffi-library test.so "test") @@ -40,7 +44,7 @@ (ffi--type-size :int))) (should (eq (ffi--type-alignment struct-type) (ffi--type-alignment :int))))) - + (ert-deftest ffi-struct-layout-offsets () (let* ((types '(:pointer :int)) (struct-type (apply #'ffi--define-struct types))) diff --git a/test/test-helper.el b/test/test-helper.el new file mode 100644 index 0000000..37e2c24 --- /dev/null +++ b/test/test-helper.el @@ -0,0 +1,42 @@ +;;; test-helper --- Test helper for ffi + +;;; Commentary: +;; test helper inspired from https://github.com/tonini/overseer.el/blob/master/test/test-helper.el + +;;; Code: + +(require 'f) + +(defvar cpt-path + (f-parent (f-this-file))) + +(defvar ffi-test-path + (f-dirname (f-this-file))) + +(defvar ffi-root-path + (f-parent ffi-test-path)) + +(defvar ffi-sandbox-path + (f-expand "sandbox" ffi-test-path)) + +(when (f-exists? ffi-sandbox-path) + (error "Something is already in %s. Check and destroy it yourself" ffi-sandbox-path)) + +(defmacro within-sandbox (&rest body) + "Evaluate BODY in an empty sandbox directory." + `(let ((default-directory ffi-sandbox-path)) + (when (f-exists? ffi-sandbox-path) + (f-delete default-directory :force)) + (f-mkdir ffi-sandbox-path) + ,@body + (f-delete default-directory :force))) + + +(require 'ert) +(require 'el-mock) +(eval-when-compile + (require 'cl)) +(require 'ffi) + +(provide 'test-helper) +;;; test-helper.el ends here From 250166c21a5beca1a03eb2bf3ecbfa53b3b37027 Mon Sep 17 00:00:00 2001 From: AdrieanKhisbe Date: Tue, 29 Dec 2015 16:37:03 +0100 Subject: [PATCH 5/6] Setup coverage --- Cask | 3 ++- test/test-helper.el | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Cask b/Cask index 7a87d26..6011b11 100644 --- a/Cask +++ b/Cask @@ -8,4 +8,5 @@ (depends-on "ecukes") (depends-on "ert-runner") (depends-on "el-mock") - (depends-on "cask-package-toolset")) + (depends-on "cask-package-toolset") + (depends-on "undercover")) diff --git a/test/test-helper.el b/test/test-helper.el index 37e2c24..f27a7d4 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -35,7 +35,11 @@ (require 'ert) (require 'el-mock) (eval-when-compile - (require 'cl)) + (require 'cl)) +(require 'undercover) +(undercover "*.el" + (:exclude "*-test.el") + (:report-file "/tmp/undercover-report.json")) (require 'ffi) (provide 'test-helper) From c2b4fff9190f759d384c592f370375216d26e121 Mon Sep 17 00:00:00 2001 From: AdrieanKhisbe Date: Tue, 29 Dec 2015 16:37:15 +0100 Subject: [PATCH 6/6] Fix few typos in ffi.el --- ffi.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ffi.el b/ffi.el index bb6c254..db4da8d 100644 --- a/ffi.el +++ b/ffi.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2015 Tom Tromey ;; Version: 0.0.1 -;; Author: Tom Tromey +;; Author: Tom Tromey ;; Keywords: c, languages, extensions ;; This program is free software; you can redistribute it and/or modify @@ -168,4 +168,5 @@ SLOT-NAME is a symbol and TYPE is an FFI type descriptor." `(with-ffi-string ,first-binding ,@body)))) (provide 'ffi) + ;;; ffi.el ends here