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 f3f23e7..b0fd0c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,17 @@ -*~ +# 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 +*~ + +# 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/Cask b/Cask new file mode 100644 index 0000000..6011b11 --- /dev/null +++ b/Cask @@ -0,0 +1,12 @@ +(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") + (depends-on "undercover")) diff --git a/Makefile b/Makefile index d4d1dc2..f139c36 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,21 +12,22 @@ 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) 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) $(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 +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/ffi.el b/ffi.el index 8f79a7c..db4da8d 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,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 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..f27a7d4 --- /dev/null +++ b/test/test-helper.el @@ -0,0 +1,46 @@ +;;; 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 'undercover) +(undercover "*.el" + (:exclude "*-test.el") + (:report-file "/tmp/undercover-report.json")) +(require 'ffi) + +(provide 'test-helper) +;;; test-helper.el ends here