blob: 680d1a121dc9fed06f0d3d81e59dfdc18dc1d2e6 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001#
Bram Moolenaar6ee10162007-07-26 20:58:42 +00002# Makefile to run all tests for Vim
Bram Moolenaar071d4272004-06-13 20:20:40 +00003#
4
Bram Moolenaar3f12a242015-12-05 20:56:57 +01005# Use console or GUI.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006VIMPROG = ../vim
Bram Moolenaar29f9ed22018-04-10 19:20:31 +02007XXDPROG = ../xxd/xxd
Bram Moolenaar3f12a242015-12-05 20:56:57 +01008# VIMPROG = ../gvim
9
Bram Moolenaarefa304d2014-04-01 14:08:28 +020010SCRIPTSOURCE = ../../runtime
Bram Moolenaar071d4272004-06-13 20:20:40 +000011
Bram Moolenaard8f27b32018-10-07 15:42:07 +020012# Comment out this line to see the verbose output of tests.
13#
14# Catches SwapExists to avoid hanging at the ATTENTION prompt.
Christian Brabandt075ab5a2024-10-03 16:38:52 +020015REDIR_TEST_TO_NULL = --cmd 'au SwapExists * let v:swapchoice = "e"' | LC_ALL=C awk '/Executing Test_/{match($$0, "([0-9][0-9]:[0-9][0-9] *)?Executing Test_[^\\)]*\\)"); print substr($$0, RSTART, RLENGTH) "\r"; fflush()}'
Bram Moolenaare76d7a62018-09-21 16:37:25 +020016
Bram Moolenaar0c77b7b2009-06-24 16:08:18 +000017# Uncomment this line to use valgrind for memory leaks and extra warnings.
18# The output goes into a file "valgrind.testN"
19# Vim should be compiled with EXITFREE to avoid false warnings.
20# This will make testing about 10 times as slow.
Bram Moolenaarf39d9e92023-04-22 22:54:40 +010021# VALGRIND = valgrind --tool=memcheck --leak-check=yes --num-callers=45 --log-file=valgrind.$*
Bram Moolenaar4d2fffc2007-08-14 15:29:16 +000022
Bram Moolenaardaaa3d92022-09-22 15:13:00 +010023# To execute one test, e.g. in gdb, use something like this:
24# run -f -u unix.vim --gui-dialog-file guidialog -U NONE --noplugin --not-a-term -S runtest.vim test_name.vim
25
Bram Moolenaar40bbcee2015-12-28 22:24:41 +010026default: nongui
Bram Moolenaar680eeca2010-10-20 17:44:42 +020027
Bram Moolenaar7b6156f2015-12-28 16:01:26 +010028# The list of tests is common to all systems.
Bram Moolenaarb96a32e2020-08-13 18:59:55 +020029# This defines SCRIPTS_TINY_OUT, NEW_TESTS and NEW_TESTS_RES.
Bram Moolenaar7b6156f2015-12-28 16:01:26 +010030include Make_all.mak
Bram Moolenaar071d4272004-06-13 20:20:40 +000031
Bram Moolenaar46fd6bf2019-01-11 19:19:44 +010032# Explicit dependencies.
Milly6eca04e2024-10-21 22:20:51 +020033test_options_all.res: opt_test.vim
Bram Moolenaar46fd6bf2019-01-11 19:19:44 +010034
Bram Moolenaar43345542015-11-29 17:35:35 +010035.SUFFIXES: .in .out .res .vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000036
Bram Moolenaarb96a32e2020-08-13 18:59:55 +020037nongui: nolog tinytests newtests report
Bram Moolenaar071d4272004-06-13 20:20:40 +000038
Bram Moolenaarb96a32e2020-08-13 18:59:55 +020039gui: nolog tinytests newtests report
40
41tiny: nolog tinytests report
Bram Moolenaarf2e53da2008-09-10 16:26:04 +000042
Bram Moolenaarfda37292014-11-05 14:27:36 +010043benchmark: $(SCRIPTS_BENCH)
44
Bram Moolenaarf2e53da2008-09-10 16:26:04 +000045report:
K.Takatac5125992021-05-26 21:49:18 +020046 @# without the +eval feature test_result.log is a copy of test.log
Bram Moolenaar18250e22019-06-06 14:28:54 +020047 @/bin/sh -c "if test -f test.log; \
48 then cp test.log test_result.log; \
49 else echo No failures reported > test_result.log; \
50 fi"
Bram Moolenaar7d232042019-11-05 22:37:20 +010051 $(VIMPROG) -u NONE $(NO_INITS) -S summarize.vim messages $(REDIR_TEST_TO_NULL)
Bram Moolenaarb9093d52022-09-23 19:42:31 +010052 @rm -f starttime
Bram Moolenaar071d4272004-06-13 20:20:40 +000053 @echo
Bram Moolenaarf2e53da2008-09-10 16:26:04 +000054 @echo 'Test results:'
Bram Moolenaar9c0cec62019-06-06 13:38:15 +020055 @cat test_result.log
Bram Moolenaarf2e53da2008-09-10 16:26:04 +000056 @/bin/sh -c "if test -f test.log; \
Bram Moolenaar9c0cec62019-06-06 13:38:15 +020057 then echo TEST FAILURE; exit 1; \
Bram Moolenaarf2e53da2008-09-10 16:26:04 +000058 else echo ALL DONE; \
59 fi"
Bram Moolenaar071d4272004-06-13 20:20:40 +000060
Bram Moolenaarb96a32e2020-08-13 18:59:55 +020061$(SCRIPTS_TINY_OUT) $(NEW_TESTS_RES): $(VIMPROG)
Bram Moolenaarec504012019-01-11 17:30:16 +010062
Christian Brabandtce35ee82024-10-27 21:15:50 +010063# For $ASAN_OPTIONS and $UBSAN_OPTIONS append the testname to it.
64# This assumes $ASAN_OPTIONS contains log_path as last part of the environment variable
65# For Github CI, those variables are set in .github/workflows/ci.yml
Bram Moolenaarec504012019-01-11 17:30:16 +010066
67# Execute an individual new style test, e.g.:
68# make test_largefile
69$(NEW_TESTS):
Bram Moolenaarb9093d52022-09-23 19:42:31 +010070 rm -f $@.res $(CLEANUP_FILES)
Bram Moolenaar85683ec2020-02-20 22:35:02 +010071 @MAKEFLAGS=--no-print-directory $(MAKE) -f Makefile $@.res VIMPROG=$(VIMPROG) XXDPROG=$(XXDPROG) SCRIPTSOURCE=$(SCRIPTSOURCE)
Bram Moolenaarba089302019-10-19 18:56:58 +020072 @cat messages
Bram Moolenaar4e0bf842019-06-07 22:40:25 +020073 @if test -f test.log; then \
74 exit 1; \
75 fi
Bram Moolenaar071d4272004-06-13 20:20:40 +000076
Bram Moolenaarec5929d2020-04-07 20:53:39 +020077# Run only tests specific for Vim9 script
78test_vim9:
Bram Moolenaarb9093d52022-09-23 19:42:31 +010079 rm -f test_vim9_*.res $(CLEANUP_FILES)
Bram Moolenaarec5929d2020-04-07 20:53:39 +020080 @MAKEFLAGS=--no-print-directory $(MAKE) -f Makefile $(TEST_VIM9_RES) VIMPROG=$(VIMPROG) XXDPROG=$(XXDPROG) SCRIPTSOURCE=$(SCRIPTSOURCE)
81 @cat messages
Bram Moolenaarb9093d52022-09-23 19:42:31 +010082 @rm -f starttime
Bram Moolenaarec5929d2020-04-07 20:53:39 +020083 @MAKEFLAGS=--no-print-directory $(MAKE) -f Makefile report VIMPROG=$(VIMPROG) XXDPROG=$(XXDPROG) SCRIPTSOURCE=$(SCRIPTSOURCE)
84 @if test -f test.log; then \
85 exit 1; \
86 fi
87
Bram Moolenaar60ec5f32012-12-05 18:21:32 +010088RM_ON_RUN = test.out X* viminfo
Bram Moolenaarb96a32e2020-08-13 18:59:55 +020089RM_ON_START = test.ok benchmark.out
RestorerZcd33faf2024-07-04 17:47:16 +020090RUN_VIMPROG = VIMRUNTIME=$(SCRIPTSOURCE) $(VALGRIND) $(VIMPROG) -f $(GUI_FLAG) -u unix.vim $(NO_INITS) -s dotest.in
Bram Moolenaar60ec5f32012-12-05 18:21:32 +010091
Bram Moolenaard9b0d832019-09-14 15:46:32 +020092# Delete files that may interfere with running tests. This includes some files
93# that may result from working on the tests, not only from running them.
Bram Moolenaar071d4272004-06-13 20:20:40 +000094clean:
Julio Be20c7d72024-04-09 21:22:41 +020095 -rm -rf *.out *.failed *.res *.rej *.orig XfakeHOME Xdir1 Xfind failed
Bram Moolenaarb9093d52022-09-23 19:42:31 +010096 -rm -f opt_test.vim test_result.log $(CLEANUP_FILES)
shane.xb.qian5a8fad32022-05-16 11:14:09 +010097 -rm -rf $(RM_ON_RUN) $(RM_ON_START)
Bram Moolenaar8ed75cb2019-06-09 14:39:13 +020098 -rm -f valgrind.*
Yegappan Lakshmanan54d7f182025-02-10 21:35:07 +010099 -rm -f asan.* asan_test_*
Bram Moolenaar2d12c252022-06-13 21:42:45 +0100100 -rm -f guidialog guidialogfile
Bram Moolenaar071d4272004-06-13 20:20:40 +0000101
Bram Moolenaar76381a52022-05-27 20:13:28 +0100102# Delete the files produced by benchmarking, so they can run again.
103benchmarkclean:
104 rm -f $(SCRIPTS_BENCH)
105
Bram Moolenaar071d4272004-06-13 20:20:40 +0000106nolog:
Bram Moolenaarb9093d52022-09-23 19:42:31 +0100107 -rm -f test_result.log $(CLEANUP_FILES)
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200108
109
110# Tiny tests. Works even without the +eval feature.
111tinytests: $(SCRIPTS_TINY_OUT)
112
113.in.out:
114 -rm -rf $*.failed test.ok $(RM_ON_RUN)
115 cp $*.ok test.ok
116 @# Sleep a moment to avoid that the xterm title is messed up.
117 @# 200 msec is sufficient, but only modern sleep supports a fraction of
118 @# a second, fall back to a second if it fails.
119 @-/bin/sh -c "sleep .2 > /dev/null 2>&1 || sleep 1"
Christian Brabandtce35ee82024-10-27 21:15:50 +0100120 if test -n "$${ASAN_OPTIONS}"; then \
121 ASAN_OPTIONS="$${ASAN_OPTIONS}_$*" UBSAN_OPTIONS="$${UBSAN_OPTIONS}_$*" $(RUN_VIMPROG) $*.in $(REDIR_TEST_TO_NULL) ; \
122 else \
123 $(RUN_VIMPROG) $*.in $(REDIR_TEST_TO_NULL) ; \
124 fi
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200125
126 @# Check if the test.out file matches test.ok.
127 @/bin/sh -c "if test -f test.out; then \
128 if diff test.out $*.ok; \
129 then mv -f test.out $*.out; \
130 else echo $* FAILED >>test.log; mv -f test.out $*.failed; \
131 fi \
132 else echo $* NO OUTPUT >>test.log; \
133 fi"
134 @/bin/sh -c "if test -f valgrind; then\
135 mv -f valgrind valgrind.$*; \
136 fi"
137 -rm -rf X* test.ok viminfo
Bram Moolenaar43345542015-11-29 17:35:35 +0100138
139
140# New style of tests uses Vim script with assert calls. These are easier
141# to write and a lot easier to read and debug.
142# Limitation: Only works with the +eval feature.
Bram Moolenaar2d12c252022-06-13 21:42:45 +0100143# Add --gui-dialog-file to avoid getting stuck in a dialog.
144RUN_VIMTEST = VIMRUNTIME=$(SCRIPTSOURCE) $(VALGRIND) $(VIMPROG) -f $(GUI_FLAG) -u unix.vim --gui-dialog-file guidialog
Bram Moolenaar43345542015-11-29 17:35:35 +0100145
Bram Moolenaare7893a42016-01-06 21:23:56 +0100146newtests: newtestssilent
Bram Moolenaar6e3aeec2020-08-26 22:29:57 +0200147 @/bin/sh -c "if test -f messages; then cat messages; fi"
Bram Moolenaare7893a42016-01-06 21:23:56 +0100148
Bram Moolenaarec504012019-01-11 17:30:16 +0100149newtestssilent: $(NEW_TESTS_RES)
Bram Moolenaare7893a42016-01-06 21:23:56 +0100150
Bram Moolenaar43345542015-11-29 17:35:35 +0100151
Bram Moolenaar14170312019-02-21 21:50:46 +0100152.vim.res:
Bram Moolenaar63182052017-10-07 20:03:23 +0200153 @echo "$(VIMPROG)" > vimcmd
154 @echo "$(RUN_VIMTEST)" >> vimcmd
Christian Brabandtce35ee82024-10-27 21:15:50 +0100155 if test -n "$${ASAN_OPTIONS}"; then \
156 ASAN_OPTIONS="$${ASAN_OPTIONS}_$*" UBSAN_OPTIONS="$${UBSAN_OPTIONS}_$*" $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim $*.vim $(REDIR_TEST_TO_NULL) ; \
157 else \
158 $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim $*.vim $(REDIR_TEST_TO_NULL) ; \
159 fi
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100160 @rm vimcmd
161
162test_gui.res: test_gui.vim
Bram Moolenaar63182052017-10-07 20:03:23 +0200163 @echo "$(VIMPROG)" > vimcmd
164 @echo "$(RUN_GVIMTEST)" >> vimcmd
Christian Brabandtce35ee82024-10-27 21:15:50 +0100165 if test -n "$${ASAN_OPTIONS}"; then \
166 ASAN_OPTIONS="$${ASAN_OPTIONS}_$*" UBSAN_OPTIONS="$${UBSAN_OPTIONS}_$*" $(RUN_VIMTEST) -u NONE $(NO_INITS) -S runtest.vim $< ; \
167 else \
168 $(RUN_VIMTEST) -u NONE $(NO_INITS) -S runtest.vim $< ; \
169 fi
170
Bram Moolenaar8be2fbb2017-02-23 19:32:47 +0100171 @rm vimcmd
172
173test_gui_init.res: test_gui_init.vim
Bram Moolenaar63182052017-10-07 20:03:23 +0200174 @echo "$(VIMPROG)" > vimcmd
175 @echo "$(RUN_GVIMTEST_WITH_GVIMRC)" >> vimcmd
Christian Brabandtce35ee82024-10-27 21:15:50 +0100176 if test -n "$${ASAN_OPTIONS}"; then \
177 ASAN_OPTIONS="$${ASAN_OPTIONS}_$*" UBSAN_OPTIONS="$${UBSAN_OPTIONS}_$*" $(RUN_VIMTEST) -u gui_preinit.vim -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $< ; \
178 else \
179 $(RUN_VIMTEST) -u gui_preinit.vim -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $< ; \
180 fi
Bram Moolenaar66459b72016-08-06 19:01:55 +0200181 @rm vimcmd
Bram Moolenaar65408f72017-03-07 21:31:27 +0100182
Milly6eca04e2024-10-21 22:20:51 +0200183GEN_OPT_DEPS = gen_opt_test.vim ../optiondefs.h ../../runtime/doc/options.txt
Millyb498c442024-10-17 21:05:31 +0200184
185opt_test.vim: $(GEN_OPT_DEPS)
Christian Brabandtce35ee82024-10-27 21:15:50 +0100186 if test -n "$${ASAN_OPTIONS}"; then \
187 ASAN_OPTIONS="$${ASAN_OPTIONS}_$*" UBSAN_OPTIONS="$${UBSAN_OPTIONS}_$*" $(VIMPROG) -e -s -u NONE $(NO_INITS) --nofork --gui-dialog-file guidialog -S $(GEN_OPT_DEPS) ; \
188 else \
189 $(VIMPROG) -e -s -u NONE $(NO_INITS) --nofork --gui-dialog-file guidialog -S $(GEN_OPT_DEPS) ; \
190 fi
Millyb498c442024-10-17 21:05:31 +0200191 @if test -f test.log; then \
192 cat test.log; \
193 exit 1; \
194 fi
Bram Moolenaar29f9ed22018-04-10 19:20:31 +0200195
196test_xxd.res:
Christian Brabandtce35ee82024-10-27 21:15:50 +0100197 if test -n "$${ASAN_OPTIONS}"; then \
198 XXD=$(XXDPROG); export XXD; ASAN_OPTIONS="$${ASAN_OPTIONS}_$*" UBSAN_OPTIONS="$${UBSAN_OPTIONS}_$*" $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim test_xxd.vim ; \
199 else \
200 XXD=$(XXDPROG); export XXD; $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim test_xxd.vim ; \
201 fi
Bram Moolenaarad48e6c2020-04-21 22:19:45 +0200202
203test_bench_regexp.res: test_bench_regexp.vim
204 -rm -rf benchmark.out $(RM_ON_RUN)
Bram Moolenaarb96a32e2020-08-13 18:59:55 +0200205 @# Sleep a moment to avoid that the xterm title is messed up.
206 @# 200 msec is sufficient, but only modern sleep supports a fraction of
207 @# a second, fall back to a second if it fails.
Bram Moolenaarad48e6c2020-04-21 22:19:45 +0200208 @-/bin/sh -c "sleep .2 > /dev/null 2>&1 || sleep 1"
Christian Brabandtce35ee82024-10-27 21:15:50 +0100209 if test -n "$${ASAN_OPTIONS}"; then \
210 ASAN_OPTIONS="$${ASAN_OPTIONS}_$*" UBSAN_OPTIONS="$${UBSAN_OPTIONS}_$*" $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim $*.vim $(REDIR_TEST_TO_NULL) ; \
211 else \
212 $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim $*.vim $(REDIR_TEST_TO_NULL) ; \
213 fi
Bram Moolenaarad48e6c2020-04-21 22:19:45 +0200214 @/bin/sh -c "if test -f benchmark.out; then cat benchmark.out; fi"