From d208ef541baa7b3fb1dae00027ec36fc018ae14d Mon Sep 17 00:00:00 2001 From: Phillip Lord Date: Wed, 14 Sep 2016 22:39:25 +0100 Subject: [PATCH] Makefile generator for tests --- packages/GNUmakefile | 33 +++++----- packages/admin/package-makefile.el | 76 ++++++++++++++++++++++-- packages/core/example/test/first-test.el | 7 +++ packages/gnumakefile.mk | 20 +++++-- packages/temp.el | 5 +- test/Makefile.in | 2 +- 6 files changed, 113 insertions(+), 30 deletions(-) create mode 100644 packages/core/example/test/first-test.el diff --git a/packages/GNUmakefile b/packages/GNUmakefile index 4d97ed32934..e1bc6f85f96 100644 --- a/packages/GNUmakefile +++ b/packages/GNUmakefile @@ -3,36 +3,33 @@ EMACS=../src/emacs +ELPA=../../elpa + DIRS=$(filter-out .,$(subst ./,,$(shell find . -maxdepth 1 -type d))) ## dependent on makefile all: pkg-all $(EMACS) +check: cleanlog check-packages +check-maybe: check-packages -# define package_template -# $(1): $(1)/$(1)-pkg.el - -# $(1)/$(1)-pkg.el: -# $$(EMACS) --batch --load package-build.el --eval '(package-build-prepare "$(1)")' - -# endef - -# $(foreach dir,$(DIRS),$(eval $(call package_template,$(dir)))) - -# define test_template -# $(1)-test: -# $$(EMACS) --batch --load package-test.el --eval '(assess-discover-run-and-exit-batch-dir "$(1)")' -# endef +WRITE_LOG = > $@ 2>&1 || { stat=ERROR; cat $@; }; echo $$stat: $@ -# $(foreach dir,$(DIRS),$(info $(call test_template,$(dir)))) - -# test: $(patsubst %,%-test,$(DIRS)) +gnumakefile-inc.mk: ./admin/package-makefile.el + $(EMACS) --batch --load admin/package-makefile.el \ + --funcall package-makefile include gnumakefile-inc.mk -clean: +cleanlog: + find . -name "*log" -exec rm -v {} \; + +clean: cleanlog find . -name "*pkg.el" -exec rm -v {} \; find . -name "*-autoloads.el" -exec rm -v {} \; find . -name "*elc" -exec rm -v {} \; + + +.PHONY: check clean all diff --git a/packages/admin/package-makefile.el b/packages/admin/package-makefile.el index ea8cece74ba..0e42918a0d8 100644 --- a/packages/admin/package-makefile.el +++ b/packages/admin/package-makefile.el @@ -1,3 +1,5 @@ +(require 'seq) + (defun package-makefile--package-dirs (directory) (directory-files directory nil "[^.].*")) @@ -5,7 +7,7 @@ (format "%s-pkg: %s/%s/%s-pkg.el -%s/%s/%s-pkg.el: +%s/%s/%s-pkg.el: %s \t$(EMACS) --batch --directory=admin \\ \t\t--load admin/package-build.el \\ \t\t--eval '(package-build-prepare \"%s/%s\")' @@ -13,9 +15,24 @@ base-dir top-dir base-dir base-dir top-dir base-dir base-dir + (mapconcat + (lambda (n) + (concat top-dir "/" base-dir "/" n)) + (seq-remove + (lambda (n) + (or + (string-match-p + ".*-autoloads.el" n) + (string-match-p + ".*-pkg.el" n))) + (directory-files + (concat top-dir "/" base-dir) + nil + ".*el$")) + " ") top-dir base-dir)) -(defun package-makefile--makefile-pkg-targets (top-dir all-dirs) +(defun package-makefile--pkg-targets (top-dir all-dirs) (concat "pkg-all: " (mapconcat @@ -30,13 +47,62 @@ all-dirs "\n"))) +(defun package-makefile--log-target (top-dir base-dir) + (let* ((fulldir (concat top-dir "/" base-dir)) + (filestem (concat top-dir "/" base-dir "/" base-dir)) + (logfile (concat filestem ".log")) + (pkgfile (concat filestem "-pkg.el"))) + (format + "%s: %s + @$(EMACS) --batch --load admin/assess-discover.el \\ + --eval '(assess-discover-run-and-exit-batch-dir \"%s\")' \\ + $(WRITE_LOG) + +%s: + test ! -f ./%s || mv ./%s ./%s~ + $(MAKE) %s WRITE_LOG= + +%s: %s + +.PHONY: %s %s +" + logfile pkgfile + fulldir + fulldir + logfile logfile logfile + logfile + base-dir fulldir + fulldir base-dir + ))) + +(defun package-makefile--test-targets (top-dir all-dirs) + (concat + (mapconcat + (lambda (base-dir) + (package-makefile--log-target top-dir base-dir)) + all-dirs + "\n") + + " +check-packages: " + + (mapconcat + (lambda (base-dir) + (concat top-dir "/" base-dir "/" base-dir ".log")) + all-dirs + " "))) (defun package-makefile--core-packages () (package-makefile--package-dirs "core")) -(defun package-makefile--makefile () +(defun package-makefile--1 () (concat - (package-makefile--makefile-pkg-targets + (package-makefile--pkg-targets + "core" + (package-makefile--core-packages)) + "\n" + + (package-makefile--test-targets "core" (package-makefile--core-packages)) "\n")) @@ -45,7 +111,7 @@ (defun package-makefile () (with-temp-buffer (insert - (package-makefile--makefile)) + (package-makefile--1)) (write-file "gnumakefile-inc.mk"))) ;; example: core/example/example-pkg.el diff --git a/packages/core/example/test/first-test.el b/packages/core/example/test/first-test.el new file mode 100644 index 00000000000..0e9803e1bac --- /dev/null +++ b/packages/core/example/test/first-test.el @@ -0,0 +1,7 @@ +(ert-deftest simple-succeeding-test () + (should t)) + + +(ert-deftest simple-failing-test () + :expected-result :failed + (should nil)) diff --git a/packages/gnumakefile.mk b/packages/gnumakefile.mk index 347f0da201f..eba54fcdf83 100644 --- a/packages/gnumakefile.mk +++ b/packages/gnumakefile.mk @@ -1,6 +1,16 @@ -example: core/example/example-pkg.el +core/example/example.log: core/example/example-pkg.el + @$(EMACS) --batch --load admin/assess-discover.el \ + --eval '(assess-discover-run-and-exit-batch-dir "core/example")' \ + $(WRITE_LOG) -core/example/example-pkg.el: - $(EMACS) --batch --directory=admin \ - --load admin/package-build.el \ - --eval '(package-build-prepare "core/example")' + +core/example: + test ! -f core/example/example.log || mv ./core/example/example.log ./core/example/example.log~ + $(MAKE) core/example/example.log WRITE_LOG= + +example: core/example + +.PHONY: core/example example + + +check-packages: core/example/example.log diff --git a/packages/temp.el b/packages/temp.el index 23e7e801c0e..47635363c37 100644 --- a/packages/temp.el +++ b/packages/temp.el @@ -8,4 +8,7 @@ (package-build-prepare "core/example") -(package-makefile) +(package-makefile--pkg-targets + "/home/phillord/src/git/elpa-git/master/packages" + (package-makefile--package-dirs + "/home/phillord/src/git/elpa-git/master/packages")) diff --git a/test/Makefile.in b/test/Makefile.in index a3fbc846205..e8505405108 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -169,7 +169,7 @@ check: mostlyclean check-no-automated-subdir check-packages check-packages: - @${MAKE} -C ../packages test + @${MAKE} -C ../packages check ## Rerun all default and expensive tests. .PHONY: check-expensive -- 2.39.5