forked from neomake/neomake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
340 lines (294 loc) · 11.8 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# Do not let mess "cd" with user-defined paths.
CDPATH:=
bash:=$(shell command -v bash 2>/dev/null)
ifeq ($(bash),)
$(error Could not find bash)
endif
# This is expected in tests.
TEST_VIM_PREFIX:=SHELL=$(bash)
SHELL:=$(bash) -o pipefail
# Use nvim if it is installed, otherwise vim.
ifeq ($(shell command -v nvim 2>/dev/null),)
DEFAULT_VIM:=vim
else
DEFAULT_VIM:=nvim
endif
TEST_VIM:=nvim
IS_NEOVIM=$(findstring nvim,$(TEST_VIM))$(findstring neovim,$(TEST_VIM))
# Run testnvim and testvim by default, and only one if TEST_VIM is given.
test: $(if $(TEST_VIM),$(if $(IS_NEOVIM),testnvim,testvim),testnvim testvim)
test_interactive: $(if $(TEST_VIM),$(if $(IS_NEOVIM),testnvim_interactive,testvim_interactive),testnvim_interactive testvim_interactive)
VADER:=Vader!
VADER_OPTIONS:=-q
VADER_ARGS=tests/main.vader tests/isolated.vader
VIM_ARGS='+$(VADER) $(VADER_OPTIONS) $(VADER_ARGS)'
NEOMAKE_TESTS_DEP_PLUGINS_DIR?=build/vim/plugins
TESTS_VADER_DIR:=$(NEOMAKE_TESTS_DEP_PLUGINS_DIR)/vader
$(TESTS_VADER_DIR):
mkdir -p $(dir $@)
git clone -q --depth=1 -b display-source-with-exceptions https://github.com/blueyed/vader.vim $@
TESTS_FUGITIVE_DIR:=$(NEOMAKE_TESTS_DEP_PLUGINS_DIR)/vim-fugitive
$(TESTS_FUGITIVE_DIR):
mkdir -p $(dir $@)
git clone -q --depth=1 https://github.com/tpope/vim-fugitive $@
DEP_PLUGINS=$(TESTS_VADER_DIR) $(TESTS_FUGITIVE_DIR)
TEST_VIMRC:=tests/vim/vimrc
testwatch: override export VADER_OPTIONS+=-q
testwatch:
contrib/run-tests-watch
testwatchx: override export VADER_OPTIONS+=-x
testwatchx: testwatch
testx: override VADER_OPTIONS+=-x
testx: test
testnvimx: override VADER_OPTIONS+=-x
testnvimx: testnvim
testvimx: override VADER_OPTIONS+=-x
testvimx: testvim
# Neovim might quit after ~5s with stdin being closed. Use --headless mode to
# work around this.
# > Vim: Error reading input, exiting...
# > Vim: Finished.
testnvim: TEST_VIM:=nvim
# Neovim needs a valid HOME (https://github.com/neovim/neovim/issues/5277).
testnvim: build/neovim-test-home
testnvim: TEST_VIM_PREFIX+=HOME=$(CURDIR)/build/neovim-test-home
testnvim: TEST_VIM_PREFIX+=VADER_OUTPUT_FILE=/dev/stderr
testnvim: | build $(DEP_PLUGINS)
$(call func-run-vim)
testvim: TEST_VIM:=vim
testvim: TEST_VIM_PREFIX+=HOME=/dev/null
testvim: | build $(DEP_PLUGINS)
$(call func-run-vim)
# Add coloring to Vader's output:
# 1. failures (includes pending) in red "(X)"
# 2. test case header in bold "(2/2)"
# 3. Neomake's debug log messages in less intense grey
# 4. non-Neomake log lines (e.g. from :Log) in bold/bright yellow.
_SED_HIGHLIGHT_ERRORS:=| contrib/highlight-log --compact vader
# Need to close stdin to fix spurious 'sed: couldn't write X items to stdout: Resource temporarily unavailable'.
# Redirect to stderr again for Docker (where only stderr is used from).
_REDIR_STDOUT:=2>&1 </dev/null >/dev/null $(_SED_HIGHLIGHT_ERRORS) >&2
_COVIMERAGE=$(if $(filter-out 0,$(NEOMAKE_DO_COVERAGE)),covimerage run --append --no-report ,)
define func-run-vim
$(info Using: $(shell $(TEST_VIM_PREFIX) $(TEST_VIM) --version | head -n2))
$(_COVIMERAGE)$(if $(TEST_VIM_PREFIX),env $(TEST_VIM_PREFIX) ,)$(TEST_VIM) \
$(if $(IS_NEOVIM),$(if $(_REDIR_STDOUT),--headless,),-X) \
--noplugin -Nu $(TEST_VIMRC) -i NONE $(VIM_ARGS) $(_REDIR_STDOUT)
endef
# Interactive tests, keep Vader open.
_run_interactive: VADER:=Vader
_run_interactive: _REDIR_STDOUT:=
_run_interactive:
$(call func-run-vim)
testvim_interactive: TEST_VIM:=vim -X
testvim_interactive: TEST_VIM_PREFIX+=HOME=/dev/null
testvim_interactive: _run_interactive
testnvim_interactive: TEST_VIM:=nvim
testnvim_interactive: TEST_VIM_PREFIX+=HOME=$(CURDIR)/build/neovim-test-home
testnvim_interactive: _run_interactive
# Manually invoke Vim, using the test setup. This helps with building tests.
runvim: VIM_ARGS:=
runvim: testvim_interactive
runnvim: VIM_ARGS:=
runnvim: testnvim_interactive
# Add targets for .vader files, absolute and relative.
# This can be used with `b:dispatch = ':Make %'` in Vim.
TESTS:=$(wildcard tests/*.vader tests/*/*.vader)
uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
_TESTS_REL_AND_ABS:=$(call uniq,$(abspath $(TESTS)) $(TESTS))
FILE_TEST_TARGET=test$(DEFAULT_VIM)
$(_TESTS_REL_AND_ABS):
$(MAKE) --no-print-directory $(FILE_TEST_TARGET) VADER_ARGS='$@'
.PHONY: $(_TESTS_REL_AND_ABS)
testcoverage: COVERAGE_VADER_ARGS:=tests/main.vader $(wildcard tests/isolated/*.vader)
testcoverage:
$(RM) .coverage.covimerage
@ret=0; \
for testfile in $(COVERAGE_VADER_ARGS); do \
$(MAKE) --no-print-directory test VADER_ARGS=$$testfile NEOMAKE_DO_COVERAGE=1 || (( ++ret )); \
done; \
exit $$ret
tags:
ctags -R --langmap=vim:+.vader
.PHONY: tags
# Linters, called from .travis.yml.
LINT_ARGS:=./plugin ./autoload
# Vint.
VINT_BIN=$(shell command -v vint 2>/dev/null || echo build/vint/bin/vint)
build/vint: | build
$(shell command -v virtualenv 2>/dev/null || echo python3 -m venv) $@
build/vint/bin/vint: | build/vint
build/vint/bin/pip install --quiet vim-vint
vint: | $(VINT_BIN)
$| --color $(LINT_ARGS)
vint-errors: | $(VINT_BIN)
$| --color --error $(LINT_ARGS)
# vimlint
VIMLINT_BIN=$(shell command -v vimlint 2>/dev/null || echo build/vimlint/bin/vimlint.sh -l build/vimlint -p build/vimlparser)
build/vimlint/bin/vimlint.sh: build/vimlint build/vimlparser
build/vimlint: | build
git clone -q --depth=1 https://github.com/syngan/vim-vimlint $@
build/vimlparser: | build
git clone -q --depth=1 https://github.com/ynkdir/vim-vimlparser $@
VIMLINT_OPTIONS=-u -e EVL102.l:_=1
vimlint: | $(firstword $(VIMLINT_BIN))
$(VIMLINT_BIN) $(VIMLINT_OPTIONS) $(LINT_ARGS)
vimlint-errors: | $(firstword VIMLINT_BIN)
$(VIMLINT_BIN) $(VIMLINT_OPTIONS) -E $(LINT_ARGS)
build build/neovim-test-home:
mkdir $@
build/neovim-test-home: | build
build/vimhelplint: | build
cd build \
&& wget -O- https://github.com/machakann/vim-vimhelplint/archive/master.tar.gz \
| tar xz \
&& mv vim-vimhelplint-master vimhelplint
vimhelplint: export VIMHELPLINT_VIM:=vim
vimhelplint: | $(if $(VIMHELPLINT_DIR),,build/vimhelplint)
contrib/vimhelplint doc/neomake.txt
# Run tests in dockerized Vims.
DOCKER_REPO:=neomake/vims-for-tests
DOCKER_TAG:=22
NEOMAKE_DOCKER_IMAGE?=
DOCKER_IMAGE:=$(if $(NEOMAKE_DOCKER_IMAGE),$(NEOMAKE_DOCKER_IMAGE),$(DOCKER_REPO):$(DOCKER_TAG))
DOCKER_STREAMS:=-ti
DOCKER=docker run $(DOCKER_STREAMS) --rm \
-v $(PWD):/testplugin \
-w /testplugin \
-e NEOMAKE_TEST_NO_COLORSCHEME \
$(DOCKER_IMAGE)
docker_image:
docker build -f Dockerfile.tests -t $(DOCKER_REPO):$(DOCKER_TAG) .
docker_push:
docker push $(DOCKER_REPO):$(DOCKER_TAG)
docker_update_image:
@git diff --cached --exit-code >/dev/null || { echo "WARN: git index is not clean."; }
@if git diff --exit-code Makefile >/dev/null; then \
sed -i '/^DOCKER_TAG:=/s/:=.*/:=$(shell echo $$(($(DOCKER_TAG)+1)))/' Makefile; \
else \
echo "WARN: Makefile is not clean. Not updating."; \
fi
@if git diff --exit-code Dockerfile.tests >/dev/null; then \
sed -i '/^ENV NEOMAKE_DOCKERFILE_UPDATE=/s/=.*/=$(shell date +%Y-%m-%d)/' Dockerfile.tests; \
else \
echo "WARN: Dockerfile.tests is not clean. Not updating."; \
fi
make docker_image
make docker_test DOCKER_VIM=neovim-master
@echo "Done. Use 'make docker_push' to push it, and then update .circleci/config.yml."
DOCKER_VIMS:=vim73 vim74-trusty vim74-xenial vim-8.0.586 vim-master neovim-v0.1.7 neovim-v0.2.0 neovim-v0.2.1 neovim-v0.2.2 neovim-master
_DOCKER_VIM_TARGETS:=$(addprefix docker_test-,$(DOCKER_VIMS))
docker_test_all: $(_DOCKER_VIM_TARGETS)
$(_DOCKER_VIM_TARGETS):
$(MAKE) docker_test DOCKER_VIM=$(patsubst docker_test-%,%,$@)
_docker_test: DOCKER_VIM:=vim-master
_docker_test: DOCKER_MAKE_TARGET=$(DOCKER_MAKE_TEST_TARGET) \
TEST_VIM='/vim-build/bin/$(DOCKER_VIM)' \
VADER_OPTIONS="$(VADER_OPTIONS)" VADER_ARGS="$(VADER_ARGS)"
_docker_test: docker_make
docker_test: DOCKER_MAKE_TEST_TARGET:=test
docker_test: DOCKER_STREAMS:=-t
docker_test: _docker_test
docker_test_interactive: DOCKER_MAKE_TEST_TARGET:=test_interactive
docker_test_interactive: DOCKER_STREAMS:=-ti
docker_test_interactive: _docker_test
docker_run: $(DEP_PLUGINS)
docker_run:
$(DOCKER) $(if $(DOCKER_RUN),$(DOCKER_RUN),bash)
docker_make: DOCKER_RUN=make $(DOCKER_MAKE_TARGET)
docker_make: docker_run
docker_check: DOCKER_MAKE_TARGET=check_docker
docker_check: docker_make
docker_vimhelplint:
$(MAKE) docker_make "DOCKER_MAKE_TARGET=vimhelplint \
VIMHELPLINT_VIM=/vim-build/bin/vim-master"
_ECHO_DOCKER_VIMS:=ls /vim-build/bin | grep vim | sort
docker_list_vims:
docker run --rm $(DOCKER_IMAGE) $(_ECHO_DOCKER_VIMS)
check_lint_diff:
@# NOTE: does not see changed files for builds on master.
@set -e; \
echo "Looking for changed files (to origin/master)."; \
CHANGED_VIM_FILES=($$(git diff-tree --no-commit-id --name-only --diff-filter=AM -r origin/master.. \
| grep '\.vim$$' | grep -v '^tests/fixtures')) || true; \
ret=0; \
if [ "$${#CHANGED_VIM_FILES[@]}" -eq 0 ]; then \
echo 'No .vim files changed.'; \
else \
MAKE_ARGS="LINT_ARGS=$${CHANGED_VIM_FILES[*]}"; \
echo "== Running \"make vimlint $$MAKE_ARGS\" =="; \
$(MAKE) --no-print-directory vimlint "$$MAKE_ARGS" || (( ret+=1 )); \
echo "== Running \"make vint $$MAKE_ARGS\" =="; \
$(MAKE) --no-print-directory vint "$$MAKE_ARGS" || (( ret+=2 )); \
fi; \
if ! git diff-tree --quiet --exit-code --diff-filter=AM -r origin/master.. -- doc/neomake.txt; then \
echo "== Running \"make vimhelplint\" for changed doc/neomake.txt =="; \
$(MAKE) --no-print-directory vimhelplint || (( ret+=4 )); \
fi; \
exit $$ret
check_lint: vimlint vint vimhelplint
# Checks to be run within the Docker image.
check_docker:
@:; set -e; ret=0; \
echo '== Checking for DOCKER_VIMS to be in sync'; \
vims=$$($(_ECHO_DOCKER_VIMS)); \
docker_vims="$$(printf '%s\n' $(DOCKER_VIMS) | sort)"; \
if ! [ "$$vims" = "$$docker_vims" ]; then \
echo "DOCKER_VIMS is out of sync with Vims in image."; \
diff <(echo "$$vims") <(echo "$$docker_vims"); \
(( ret+=8 )); \
fi; \
exit $$ret
check:
@:; set -e; ret=0; \
echo '== Checking that all tests are included'; \
for f in $(filter-out main.vader isolated.vader,$(notdir $(shell git ls-files tests/*.vader))); do \
if ! grep -q "^Include.*: $$f" tests/main.vader; then \
echo "Test not included in main.vader: $$f" >&2; ret=1; \
fi; \
done; \
for f in $(filter-out main.vader,$(notdir $(shell git ls-files tests/isolated/*.vader))); do \
if ! grep -q "^Include.*: isolated/$$f" tests/isolated.vader; then \
echo "Test not included in isolated.vader: $$f" >&2; ret=1; \
fi; \
done; \
echo '== Checking for absent Before sections in tests'; \
if grep '^Before:' tests/*.vader; then \
echo "Before: should not be used in tests itself, because it overrides the global one."; \
(( ret+=2 )); \
fi; \
echo '== Checking for absent :Log calls'; \
if git --no-pager grep --line-number --color '^(\s*au.*\b)?\s*Log\b' \
-- :^tests/include/init.vim :^tests/include/setup.vader; then \
echo "Found Log commands."; \
(( ret+=4 )); \
fi; \
echo '== Checking tests'; \
output="$$(grep --line-number --color AssertThrows -A1 tests/*.vader \
| grep -E '^[^[:space:]]+- ' \
| grep -v g:vader_exception | sed -e s/-/:/ -e s/-// || true)"; \
if [[ -n "$$output" ]]; then \
echo 'AssertThrows used without checking g:vader_exception:' >&2; \
echo "$$output" >&2; \
(( ret+=16 )); \
fi; \
echo '== Running custom checks'; \
contrib/vim-checks $(LINT_ARGS) || (( ret+= 16 )); \
exit $$ret
.coverage.covimerage: .coveragerc $(shell find . -name '*.vim')
$(MAKE) testcoverage
coverage: .coverage.covimerage
coverage report -m
NEOMAKE_LOG:=/tmp/neomake.log
tail_log:
fifo=$(shell mktemp -u); \
mkfifo $$fifo; \
tail -f $(NEOMAKE_LOG) \
| $(CURDIR)/contrib/highlight-log >> $$fifo & \
less --force --chop-long-lines +F $$fifo
clean:
$(RM) -r build
.PHONY: clean
.PHONY: vint vint-errors vimlint vimlint-errors
.PHONY: test testnvim testvim testnvim_interactive testvim_interactive
.PHONY: runvim runnvim tags _run_tests