development.org (4195B)
1 * Build 2 ** bootstrapping 3 Libraries that are part of the "bootstrap set" cannot rely on 4 autoloading. Example: =files.el= must ~(eval-when-compile (require 5 'pcase))~, even though it only uses autoloaded macros. 6 * Tests 7 ** Running 8 Somehow I can never remember how to ask =make= how to run a specific 9 set of tests. 10 11 tl;dr, running =$testcases_regexp= from =test/$testfile.el=, to test 12 changes in =lisp/$sourcefile.el=: 13 #+begin_src sh 14 make -C test $testfile \ 15 TEST_LOAD_EL=yes \ 16 TEST_BACKTRACE_LINE_LENGTH=nil \ 17 SELECTOR="\"$testcases_regexp\"" \ 18 EMACS_EXTRAOPT="-l ../lisp/$sourcefile.el" 19 #+end_src 20 21 Relevant bits from test/Makefile: 22 23 #+begin_src makefile 24 ## filename.log: run tests from filename.el(c) if .log file needs updating 25 ## filename: re-run tests from filename.el(c), with no logging 26 #+end_src 27 28 #+begin_src makefile 29 # Whether to run tests from .el files in preference to .elc, we do 30 # this by default since it gives nicer stacktraces. 31 # If you just want a pass/fail, setting this to no is much faster. 32 export TEST_LOAD_EL ?= \ 33 $(if $(findstring $(MAKECMDGOALS), all check check-maybe),no,yes) 34 #+end_src 35 36 #+begin_src makefile 37 TEST_RUN_ERT = --batch --eval '(ert-run-tests-batch-and-exit (quote ${SELECTOR_ACTUAL}))' ${WRITE_LOG} 38 #+end_src 39 40 #+begin_src makefile 41 ifdef SELECTOR 42 SELECTOR_ACTUAL=$(SELECTOR) 43 #+end_src 44 45 Selector documentation from ~ert-select-tests~: 46 #+begin_quote 47 Valid SELECTORs: 48 49 nil -- Selects the empty set. 50 t -- Selects UNIVERSE. 51 :new -- Selects all tests that have not been run yet. 52 :failed, :passed -- Select tests according to their most recent result. 53 :expected, :unexpected -- Select tests according to their most recent result. 54 a string -- A regular expression selecting all tests with matching names. 55 a test -- (i.e., an object of the ert-test data-type) Selects that test. 56 a symbol -- Selects the test that the symbol names, signals an 57 ‘ert-test-unbound’ error if none. 58 (member TESTS...) -- Selects the elements of TESTS, a list of tests 59 or symbols naming tests. 60 (eql TEST) -- Selects TEST, a test or a symbol naming a test. 61 (and SELECTORS...) -- Selects the tests that match all SELECTORS. 62 (or SELECTORS...) -- Selects the tests that match any of the SELECTORS. 63 (not SELECTOR) -- Selects all tests that do not match SELECTOR. 64 (tag TAG) -- Selects all tests that have TAG on their tags list. 65 A tag is an arbitrary label you can apply when you define a test. 66 (satisfies PREDICATE) -- Selects all tests that satisfy PREDICATE. 67 PREDICATE is a function that takes an ert-test object as argument, 68 and returns non-nil if it is selected. 69 #+end_quote 70 ** Writing 71 *** Mocking functions 72 #+begin_src elisp 73 (cl-letf (((symbol-function 'read-something) 74 (lambda (&rest _) "result"))) 75 (some-command)) 76 #+end_src 77 78 * Third-party packages 79 ** forge 80 *** build 81 Use =config.mk= to set =LOAD_PATH=: 82 #+begin_src makefile 83 find-lib = $(dir $(shell emacs -Q -batch \ 84 -eval "(require 'find-func)" \ 85 -eval "(package-initialize)" \ 86 -eval "(require '$(1))" \ 87 -eval "(princ (find-library-name \"$(1)\"))")) 88 89 sources = ~/src/emacs/magit/lisp 90 91 elpa = \ 92 closql \ 93 compat \ 94 dash \ 95 emacsql \ 96 ghub \ 97 markdown-mode \ 98 transient \ 99 treepy \ 100 with-editor \ 101 yaml 102 elpa_dirs = $(foreach d,$(elpa),$(call find-lib,$(d))) 103 104 LOAD_PATH = $(addprefix -L ,$(elpa_dirs) $(sources)) 105 #+end_src 106 107 *** load sources 108 ~emacs -Q -L ./lisp~ does not seem to work: after running 109 ~(package-initialize)~, =M-x find-library forge= returns the instance 110 installed under ~package-user-dir~. 111 112 This can be circumvented with ~(setq pacakge-load-list '((forge nil) 113 all))~. 114 115 Full command line for easy startup: 116 117 #+begin_src sh 118 emacs -Q -L ./lisp \ 119 -eval "(setq pacakge-load-list '((forge nil) all))" \ 120 -f package-initialize \ 121 #+end_src