xref: /vim-8.2.3635/src/testdir/Makefile (revision 81ea1dfb)
1#
2# Makefile to run all tests for Vim
3#
4
5# Use console or GUI.
6VIMPROG = ../vim
7XXDPROG = ../xxd/xxd
8# VIMPROG = ../gvim
9
10SCRIPTSOURCE = ../../runtime
11
12# Comment out this line to see the verbose output of tests.
13#
14# Catches SwapExists to avoid hanging at the ATTENTION prompt.
15REDIR_TEST_TO_NULL = --cmd 'au SwapExists * let v:swapchoice = "e"' > /dev/null
16
17# 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.
21# VALGRIND = valgrind --tool=memcheck --leak-check=yes --num-callers=25 --log-file=valgrind.$*
22
23default: nongui
24
25# The list of tests is common to all systems.
26# This defines NEW_TESTS, NEW_TESTS_RES, SCRIPTS_ALL, SCRIPTS_MORE* and
27# SCRIPTS_GUI.
28include Make_all.mak
29
30
31SCRIPTS = $(SCRIPTS_ALL) \
32	  $(SCRIPTS_MORE1) \
33	  $(SCRIPTS_MORE2) \
34	  $(SCRIPTS_MORE4)
35
36# Explicit dependencies.
37test49.out: test49.vim
38
39test_options.res test_alot.res: opt_test.vim
40
41SCRIPTS_BENCH = bench_re_freeze.out
42
43.SUFFIXES: .in .out .res .vim
44
45nongui:	nolog $(SCRIPTS_FIRST) $(SCRIPTS) newtests report
46
47gui:	nolog $(SCRIPTS_FIRST) $(SCRIPTS) $(SCRIPTS_GUI) newtests report
48
49benchmark: $(SCRIPTS_BENCH)
50
51report:
52	# without the +eval feature test_result.log is a copy of test.log
53	@/bin/sh -c "if test -f test.log; \
54		then cp test.log test_result.log; \
55		else echo No failures reported > test_result.log; \
56		fi"
57	$(VIMPROG) -u NONE $(NO_INITS) -S summarize.vim messages $(REDIR_TEST_TO_NULL)
58	@echo
59	@echo 'Test results:'
60	@cat test_result.log
61	@/bin/sh -c "if test -f test.log; \
62		then echo TEST FAILURE; exit 1; \
63		else echo ALL DONE; \
64		fi"
65
66$(SCRIPTS_FIRST) $(SCRIPTS) $(SCRIPTS_GUI) $(NEW_TESTS_RES): $(VIMPROG)
67
68# Must run test1 first to create small.vim.
69$(SCRIPTS) $(SCRIPTS_GUI) $(NEW_TESTS_RES): $(SCRIPTS_FIRST)
70
71
72# Execute an individual new style test, e.g.:
73# 	make test_largefile
74$(NEW_TESTS):
75	rm -f $@.res test.log messages
76	@MAKEFLAGS=--no-print-directory $(MAKE) -f Makefile $@.res VIMPROG=$(VIMPROG) XXDPROG=$(XXDPROG) SCRIPTSOURCE=$(SCRIPTSOURCE)
77	@cat messages
78	@if test -f test.log; then \
79		exit 1; \
80	fi
81
82# Run only tests specific for Vim9 script
83test_vim9:
84	rm -f test_vim9_*.res test.log messages
85	@MAKEFLAGS=--no-print-directory $(MAKE) -f Makefile $(TEST_VIM9_RES) VIMPROG=$(VIMPROG) XXDPROG=$(XXDPROG) SCRIPTSOURCE=$(SCRIPTSOURCE)
86	@cat messages
87	@MAKEFLAGS=--no-print-directory $(MAKE) -f Makefile report VIMPROG=$(VIMPROG) XXDPROG=$(XXDPROG) SCRIPTSOURCE=$(SCRIPTSOURCE)
88	@if test -f test.log; then \
89		exit 1; \
90	fi
91
92RM_ON_RUN = test.out X* viminfo
93RM_ON_START = tiny.vim small.vim mbyte.vim mzscheme.vim test.ok benchmark.out
94RUN_VIM = VIMRUNTIME=$(SCRIPTSOURCE) $(VALGRIND) $(VIMPROG) -f $(GUI_FLAG) -u unix.vim $(NO_INITS) -s dotest.in
95
96# Delete files that may interfere with running tests.  This includes some files
97# that may result from working on the tests, not only from running them.
98clean:
99	-rm -rf *.out *.failed *.res *.rej *.orig XfakeHOME Xdir1 Xfind
100	-rm -f opt_test.vim test.log test_result.log messages
101	-rm -f $(RM_ON_RUN) $(RM_ON_START)
102	-rm -f valgrind.*
103
104test1.out: test1.in
105	-rm -rf $*.failed $(RM_ON_RUN) $(RM_ON_START) wrongtermsize
106	$(RUN_VIM) $*.in $(REDIR_TEST_TO_NULL)
107	@/bin/sh -c "if test -f wrongtermsize; \
108		then echo; \
109		echo test1 FAILED - terminal size must be 80x24 or larger; \
110		echo; exit 1; \
111		elif diff test.out $*.ok; \
112		then mv -f test.out $*.out; \
113		else echo; \
114		echo test1 FAILED - Something basic is wrong; \
115		echo; exit 1; fi"
116	-rm -rf X* viminfo
117
118.in.out:
119	-rm -rf $*.failed test.ok $(RM_ON_RUN)
120	cp $*.ok test.ok
121	# Sleep a moment to avoid that the xterm title is messed up.
122	# 200 msec is sufficient, but only modern sleep supports a fraction of
123	# a second, fall back to a second if it fails.
124	@-/bin/sh -c "sleep .2 > /dev/null 2>&1 || sleep 1"
125	$(RUN_VIM) $*.in $(REDIR_TEST_TO_NULL)
126
127	# For flaky tests retry one time.  No tests at the moment.
128	#@/bin/sh -c "if test -f test.out -a $* = test61; then \
129	#	  if diff test.out $*.ok; \
130	#	  then echo flaky test ok first time; \
131	#	  else rm -rf $*.failed $(RM_ON_RUN); \
132	#		$(RUN_VIM) $*.in; \
133	#	  fi \
134	#	fi"
135
136	# Check if the test.out file matches test.ok.
137	@/bin/sh -c "if test -f test.out; then \
138		  if diff test.out $*.ok; \
139		  then mv -f test.out $*.out; \
140		  else echo $* FAILED >>test.log; mv -f test.out $*.failed; \
141		  fi \
142		else echo $* NO OUTPUT >>test.log; \
143		fi"
144	@/bin/sh -c "if test -f valgrind; then\
145		  mv -f valgrind valgrind.$*; \
146		fi"
147	-rm -rf X* test.ok viminfo
148
149bench_re_freeze.out: bench_re_freeze.vim
150	-rm -rf benchmark.out $(RM_ON_RUN)
151	# Sleep a moment to avoid that the xterm title is messed up.
152	# 200 msec is sufficient, but only modern sleep supports a fraction of
153	# a second, fall back to a second if it fails.
154	@-/bin/sh -c "sleep .2 > /dev/null 2>&1 || sleep 1"
155	$(RUN_VIM) $*.in $(REDIR_TEST_TO_NULL)
156	@/bin/sh -c "if test -f benchmark.out; then cat benchmark.out; fi"
157
158nolog:
159	-rm -f test.log messages
160
161
162# New style of tests uses Vim script with assert calls.  These are easier
163# to write and a lot easier to read and debug.
164# Limitation: Only works with the +eval feature.
165RUN_VIMTEST = VIMRUNTIME=$(SCRIPTSOURCE) $(VALGRIND) $(VIMPROG) -f $(GUI_FLAG) -u unix.vim
166
167newtests: newtestssilent
168	@/bin/sh -c "if test -f messages && grep -q 'SKIPPED\|FAILED' messages; then cat messages; fi"
169
170newtestssilent: $(NEW_TESTS_RES)
171
172
173.vim.res:
174	@echo "$(VIMPROG)" > vimcmd
175	@echo "$(RUN_VIMTEST)" >> vimcmd
176	$(RUN_VIMTEST) $(NO_INITS) -S runtest.vim $*.vim $(REDIR_TEST_TO_NULL)
177	@rm vimcmd
178
179test_gui.res: test_gui.vim
180	@echo "$(VIMPROG)" > vimcmd
181	@echo "$(RUN_GVIMTEST)" >> vimcmd
182	$(RUN_VIMTEST) -u NONE $(NO_INITS) -S runtest.vim $<
183	@rm vimcmd
184
185test_gui_init.res: test_gui_init.vim
186	@echo "$(VIMPROG)" > vimcmd
187	@echo "$(RUN_GVIMTEST_WITH_GVIMRC)" >> vimcmd
188	$(RUN_VIMTEST) -u gui_preinit.vim -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $<
189	@rm vimcmd
190
191opt_test.vim: ../optiondefs.h gen_opt_test.vim
192	$(VIMPROG) -u NONE -S gen_opt_test.vim --noplugin --not-a-term ../optiondefs.h
193
194test_xxd.res:
195	XXD=$(XXDPROG); export XXD; $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim test_xxd.vim
196