|
| 1 | +PYTESTS = $(wildcard test/test_*.py) |
| 2 | + |
1 | 3 | .PHONY: all
|
2 |
| -all: yadm.md contrib |
| 4 | +all: |
| 5 | + @$(MAKE) usage | less |
3 | 6 |
|
4 |
| -yadm.md: yadm.1 |
5 |
| - @groff -man -Tascii ./yadm.1 | col -bx | sed 's/^[A-Z]/## &/g' | sed '/yadm(1)/d' > yadm.md |
| 7 | +# Display usage for all make targets |
| 8 | +.PHONY: usage |
| 9 | +usage: |
| 10 | + @echo |
| 11 | + @echo 'make TARGET [option=value, ...]' |
| 12 | + @echo |
| 13 | + @echo 'TESTING' |
| 14 | + @echo |
| 15 | + @echo ' make test [testargs=ARGS]' |
| 16 | + @echo ' - Run all tests. "testargs" can specify a single string of arguments' |
| 17 | + @echo ' for py.test.' |
| 18 | + @echo |
| 19 | + @echo ' make <testfile>.py [testargs=ARGS]' |
| 20 | + @echo ' - Run tests from a specific test file. "testargs" can specify a' |
| 21 | + @echo ' single string of arguments for py.test.' |
| 22 | + @echo |
| 23 | + @echo ' make testhost [version=VERSION]' |
| 24 | + @echo ' - Create an ephemeral container for doing adhoc yadm testing. The' |
| 25 | + @echo ' HEAD revision of yadm will be used unless "version" is' |
| 26 | + @echo ' specified. "version" can be set to any commit, branch, tag, etc.' |
| 27 | + @echo ' The targeted "version" will be retrieved from the repo, and' |
| 28 | + @echo ' linked into the container as a local volume.' |
| 29 | + @echo |
| 30 | + @echo 'LINTING' |
| 31 | + @echo |
| 32 | + @echo ' make testenv' |
| 33 | + @echo ' - Create a python virtual environment with the dependencies used' |
| 34 | + @echo " by yadm's testbed environment. Creating and activating this" |
| 35 | + @echo ' environment might be useful if your editor does real time' |
| 36 | + @echo ' linting of python files. After creating the virtual environment,' |
| 37 | + @echo ' you can activate it by typing' |
| 38 | + @echo |
| 39 | + @echo 'MANPAGES' |
| 40 | + @echo |
| 41 | + @echo ' make man' |
| 42 | + @echo ' - View yadm.1 as a standard manpage.' |
| 43 | + @echo |
| 44 | + @echo ' make man-wide' |
| 45 | + @echo ' - View yadm.1 as a manpage, using all columns of your display.' |
| 46 | + @echo |
| 47 | + @echo ' make man-ps' |
| 48 | + @echo ' - Create a postscript version of the manpage.' |
| 49 | + @echo |
| 50 | + @echo 'FILE GENERATION' |
| 51 | + @echo |
| 52 | + @echo ' make yadm.md' |
| 53 | + @echo ' - Generate the markdown version of the manpage (for viewing on' |
| 54 | + @echo ' the web).' |
| 55 | + @echo |
| 56 | + @echo ' make contrib' |
| 57 | + @echo ' - Generate the CONTRIBUTORS file, from the repo history.' |
| 58 | + @echo |
| 59 | + @echo 'UTILITIES' |
| 60 | + @echo |
| 61 | + @echo ' make sync-clock' |
| 62 | + @echo ' - Reset the hardware clock for the docker hypervisor host. This' |
| 63 | + @echo ' can be useful for docker engine hosts which are not' |
| 64 | + @echo ' Linux-based.' |
| 65 | + @echo |
6 | 66 |
|
7 |
| -.PHONY: contrib |
8 |
| -contrib: |
9 |
| - @echo "CONTRIBUTORS\n" > CONTRIBUTORS |
10 |
| - @git shortlog -ns master gh-pages dev dev-pages | cut -f2 >> CONTRIBUTORS |
11 |
| - |
12 |
| -.PHONY: pdf |
13 |
| -pdf: |
14 |
| - @groff -man -Tps ./yadm.1 > yadm.ps |
15 |
| - @open yadm.ps |
16 |
| - @sleep 1 |
17 |
| - @rm yadm.ps |
| 67 | +# Make it possible to run make specifying a py.test test file |
| 68 | +.PHONY: $(PYTESTS) |
| 69 | +$(PYTESTS): |
| 70 | + @$(MAKE) test testargs="-k $@ $(testargs)" |
| 71 | +%.py: |
| 72 | + @$(MAKE) test testargs="-k $@ $(testargs)" |
18 | 73 |
|
| 74 | +# Run all tests with additional testargs |
19 | 75 | .PHONY: test
|
20 |
| -test: bats shellcheck |
21 |
| - |
22 |
| -.PHONY: parallel |
23 |
| -parallel: |
24 |
| - ls test/*bats | time parallel -q -P0 -- docker run --rm -v "$$PWD:/yadm:ro" yadm/testbed bash -c 'bats {}' |
25 |
| - |
26 |
| -.PHONY: pytest |
27 |
| -pytest: |
28 |
| - @echo Running all pytest tests |
29 |
| - @pytest -v |
30 |
| - |
31 |
| -.PHONY: bats |
32 |
| -bats: |
33 |
| - @echo Running all bats tests |
34 |
| - @GPG_AGENT_INFO= bats test |
35 |
| - |
36 |
| -.PHONY: shellcheck |
37 |
| -shellcheck: |
38 |
| - @echo Running shellcheck |
39 |
| - @shellcheck --version || true |
40 |
| - @shellcheck -s bash yadm bootstrap test/*.bash completion/yadm.bash_completion |
41 |
| - @cd test; \ |
42 |
| - for bats_file in *bats; do \ |
43 |
| - sed 's/^@test.*{/function test() {/' "$$bats_file" > "/tmp/$$bats_file.bash"; \ |
44 |
| - shellcheck -s bash "/tmp/$$bats_file.bash"; \ |
45 |
| - test_result="$$?"; \ |
46 |
| - rm -f "/tmp/$$bats_file.bash"; \ |
47 |
| - [ "$$test_result" -ne 0 ] && exit 1; \ |
48 |
| - done; true |
| 76 | +test: |
| 77 | + @if [ -f /.yadmtestbed ]; then \ |
| 78 | + cd /yadm && \ |
| 79 | + py.test -v $(testargs); \ |
| 80 | + else \ |
| 81 | + if command -v "docker-compose" >/dev/null 2>&1; then \ |
| 82 | + docker-compose run --rm testbed make test testargs="$(testargs)"; \ |
| 83 | + else \ |
| 84 | + echo "Sorry, this make test requires docker-compose to be installed."; \ |
| 85 | + false; \ |
| 86 | + fi \ |
| 87 | + fi |
49 | 88 |
|
50 | 89 | .PHONY: testhost
|
51 | 90 | testhost:
|
52 |
| - @target=HEAD |
| 91 | + @if ! command -v "docker" >/dev/null 2>&1; then \ |
| 92 | + echo "Sorry, this make target requires docker to be installed."; \ |
| 93 | + false; \ |
| 94 | + fi |
| 95 | + @version=HEAD |
53 | 96 | @rm -rf /tmp/testhost
|
54 |
| - @git show $(target):yadm > /tmp/testhost |
| 97 | + @git show $(version):yadm > /tmp/testhost |
55 | 98 | @chmod a+x /tmp/testhost
|
56 |
| - @echo Starting testhost target=\"$$target\" |
57 |
| - @docker run -w /root --hostname testhost --rm -it -v "/tmp/testhost:/bin/yadm:ro" yadm/testbed:latest bash |
| 99 | + @echo Starting testhost version=\"$$version\" |
| 100 | + @docker run -w /root --hostname testhost --rm -it -v "/tmp/testhost:/bin/yadm:ro" yadm/testbed:latest bash -l |
| 101 | + |
| 102 | +.PHONY: testenv |
| 103 | +testenv: |
| 104 | + @echo 'Creating a local virtual environment in "testenv/"' |
| 105 | + @echo |
| 106 | + virtualenv --python=python3 testenv |
| 107 | + testenv/bin/pip3 install --upgrade pip setuptools |
| 108 | + testenv/bin/pip3 install --upgrade pytest pylint==1.9.2 flake8==3.5.0 |
| 109 | + @echo |
| 110 | + @echo 'To activate this test environment type:' |
| 111 | + @echo ' source testenv/bin/activate' |
58 | 112 |
|
59 | 113 | .PHONY: man
|
60 | 114 | man:
|
61 |
| - groff -man -Tascii ./yadm.1 | less |
| 115 | + @groff -man -Tascii ./yadm.1 | less |
| 116 | + |
| 117 | +.PHONY: man-wide |
| 118 | +man-wide: |
| 119 | + @man ./yadm.1 |
| 120 | + |
| 121 | +.PHONY: man-ps |
| 122 | +man-ps: |
| 123 | + @groff -man -Tps ./yadm.1 > yadm.ps |
| 124 | + |
| 125 | +yadm.md: yadm.1 |
| 126 | + @groff -man -Tascii ./yadm.1 | col -bx | sed 's/^[A-Z]/## &/g' | sed '/yadm(1)/d' > yadm.md |
62 | 127 |
|
63 |
| -.PHONY: wide |
64 |
| -wide: |
65 |
| - man ./yadm.1 |
| 128 | +.PHONY: contrib |
| 129 | +contrib: |
| 130 | + @echo "CONTRIBUTORS\n" > CONTRIBUTORS |
| 131 | + @git shortlog -ns master gh-pages dev dev-pages | cut -f2 >> CONTRIBUTORS |
66 | 132 |
|
67 | 133 | .PHONY: sync-clock
|
68 | 134 | sync-clock:
|
69 | 135 | docker run --rm --privileged alpine hwclock -s
|
70 |
| - |
71 |
| -.PHONY: .env |
72 |
| -.env: |
73 |
| - virtualenv --python=python3 .env |
74 |
| - .env/bin/pip3 install --upgrade pip setuptools |
75 |
| - .env/bin/pip3 install --upgrade pytest pylint==1.9.2 flake8==3.5.0 |
|
0 commit comments