Skip to content

Commit 32c7f32

Browse files
committed
tests: add coverage for various Runfile indentation chars
1 parent 013673d commit 32c7f32

File tree

12 files changed

+1498
-6
lines changed

12 files changed

+1498
-6
lines changed

Runfile

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,26 @@ test: # test
3434
fi
3535

3636
test-all: lint # run all tests
37-
$(BIN)/bats --jobs 16 --no-parallelize-across-files tests/test.bats
37+
for runfile in tests/*/Runfile
38+
do
39+
echo -ne "$$( tput smul )$$( tput bold )$${runfile}$$( tput sgr0 ) -> "
40+
TEST_RUNFILE="$${runfile}" \
41+
$(BIN)/bats --jobs 16 --no-parallelize-across-files tests/test.bats
42+
done
3843

3944
test-by-index: lint # run test case at index
40-
$(BIN)/bats -f "$$( grep @test ./tests/test.bats | head -$(1) | tail -1 | cut -d' ' -f3- | cut -d'"' -f1 )$$" ./tests/test.bats
45+
for runfile in tests/*/Runfile
46+
do
47+
echo -ne "$$( tput smul )$$( tput bold )$${runfile}$$( tput sgr0 ) -> "
48+
TEST_RUNFILE="$${runfile}" \
49+
$(BIN)/bats -f "$$( grep @test ./tests/test.bats | head -$(1) | tail -1 | cut -d' ' -f3- | cut -d'"' -f1 )$$" ./tests/test.bats
50+
done
4151

4252
test-by-substring: lint # run test cases matching substring
43-
$(BIN)/bats -f "$(@)" tests/test.bats
53+
for runfile in tests/*/Runfile
54+
do
55+
echo -ne "$$( tput smul )$$( tput bold )$${runfile}$$( tput sgr0 ) -> "
56+
TEST_RUNFILE="$${runfile}" \
57+
$(BIN)/bats -f "$(@)" tests/test.bats
58+
done
4459

File renamed without changes.

tests/Runfile renamed to tests/2space/Runfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
start: stop # start app
24
run build env=dev # tasks can be run directly from other tasks
35
echo "starting app"

tests/3space/Makefile

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
SHELL = /bin/bash
2+
3+
.PHONY: _tasks
4+
_tasks: .tasks
5+
6+
.PHONY: start
7+
start: stop # start app
8+
run build env=dev # tasks can be run directly from other tasks
9+
echo "starting app"
10+
run loading
11+
12+
.PHONY: stop
13+
stop: # stop app
14+
echo "stopping app"
15+
16+
.PHONY: loading
17+
loading: # show loading state
18+
if [[ $(@) == '--fin' ]]; \
19+
then \
20+
echo "loading finished"; \
21+
else \
22+
echo "loading started"; \
23+
fi
24+
25+
.PHONY: build
26+
build: lint # build app for environment [vars: env]
27+
[[ -n $(env) ]] && echo "buiding app for $(env)" || echo "error: missing env"
28+
29+
.PHONY: test
30+
test: # run all tests or specific tests [vars: name1, name2, etc.]
31+
run build env=test
32+
[[ -n $(@) ]] && echo "running tests $(@)" || echo "running all tests"
33+
34+
.PHONY: lint
35+
lint: # lint all files or specific file [vars: file]
36+
[[ -n $(1) ]] && echo "linting file $(1)" || echo "linting all files"
37+
38+
.PHONY: complex
39+
complex: # a sample command exploring complex multiline syntax
40+
echo "--- for loops ---"
41+
42+
for x in abc hjkl xyz; \
43+
do \
44+
echo -n " $${x} ::"; \
45+
done
46+
echo
47+
48+
for x in abc hjkl xyz; do \
49+
echo -n " $${x} ::"; \
50+
done
51+
echo
52+
53+
for x in abc hjkl xyz; \
54+
do echo -n " $${x} ::"; \
55+
done
56+
echo
57+
58+
echo "--- while loops ---"
59+
60+
while read x; \
61+
do \
62+
echo -n " $${x} ::"; \
63+
done <<< $$'abc\n hjkl\n xyz'
64+
echo
65+
66+
while read x; do \
67+
echo -n " $${x} ::"; \
68+
done <<< $$'abc\n hjkl\n xyz'
69+
echo
70+
71+
while read x; \
72+
do echo -n " $${x} ::"; \
73+
done <<< $$'abc\n hjkl\n xyz'
74+
echo
75+
76+
echo "--- if constructs ---"
77+
78+
x=''
79+
if [[ -z "$${x}" ]]; \
80+
then \
81+
echo -n " abc"; \
82+
echo -n " ::"; \
83+
elif [[ "$${x}" =~ a[Bb][a-z]$$ ]]; \
84+
then \
85+
echo -n " hjkl"; \
86+
echo -n " ::"; \
87+
else \
88+
echo -n " xyz"; \
89+
echo -n " ::"; \
90+
fi
91+
92+
y=''
93+
if [[ -n "$${y}" ]]; then \
94+
echo -n " abc"; \
95+
echo -n " ::"; \
96+
elif ! [[ "$${y}" =~ a[Bb][a-z]$$ ]]; then \
97+
echo -n " hjkl"; \
98+
echo -n " ::"; \
99+
else \
100+
echo -n " xyz"; \
101+
echo -n " ::"; \
102+
fi
103+
104+
z=''
105+
if [[ -z "$${x}" ]]; \
106+
then x='abc'; echo -n " $${x} ::"; \
107+
elif [[ x =~ a[Bb][a-z]$$ ]]; \
108+
then x='hjkl'; echo -n " $${x} ::"; \
109+
else echo -n " $${x} ::"; \
110+
fi
111+
echo
112+
113+
echo "--- for loops :: pathological semicolon usage ---"
114+
115+
for x in abc hjkl xyz; \
116+
do \
117+
echo -n " $${x} ::"; \
118+
done
119+
echo
120+
121+
for x in abc hjkl xyz; do \
122+
echo -n " $${x} ::"; \
123+
done
124+
echo
125+
126+
for x in abc hjkl xyz; \
127+
do echo -n " $${x} ::"; \
128+
done
129+
echo
130+
131+
echo "--- while loops :: pathological semicolon usage ---"
132+
133+
while read x; \
134+
do \
135+
echo -n " $${x} ::"; \
136+
done <<< $$'abc\n hjkl\n xyz';
137+
echo
138+
139+
while read x; do \
140+
echo -n " $${x} ::"; \
141+
done <<< $$'abc\n hjkl\n xyz';
142+
echo
143+
144+
while read x; \
145+
do echo -n " $${x} ::"; \
146+
done <<< $$'abc\n hjkl\n xyz';
147+
echo
148+
149+
echo "--- if constructs :: pathological semicolon usage ---"
150+
151+
x=''
152+
if [[ -z "$${x}" ]]; \
153+
then \
154+
echo -n " abc"; \
155+
echo -n " ::"; \
156+
elif [[ "$${x}" =~ a[Bb][a-z]$$ ]]; \
157+
then \
158+
echo -n " hjkl"; \
159+
echo -n " ::"; \
160+
else \
161+
echo -n " xyz"; \
162+
echo -n " ::"; \
163+
fi
164+
165+
y=''
166+
if [[ -n "$${y}" ]]; then \
167+
echo -n " abc"; \
168+
echo -n " ::"; \
169+
elif ! [[ "$${y}" =~ a[Bb][a-z]$$ ]]; then \
170+
echo -n " hjkl"; \
171+
echo -n " ::"; \
172+
else \
173+
echo -n " xyz"; \
174+
echo -n " ::"; \
175+
fi
176+
177+
z=''
178+
if [[ -z "$${x}" ]]; \
179+
then x='abc'; echo -n " $${x} ::"; \
180+
elif [[ x =~ a[Bb][a-z]$$ ]]; \
181+
then x='hjkl'; echo -n " $${x} ::"; \
182+
else echo -n " $${x} ::"; \
183+
fi
184+
185+
.PHONY: .tasks
186+
.tasks:
187+
grep -E "^(([[:alnum:]_-][[:alnum:][:space:]_-]+):([[:alnum:][:space:]_-]+)?#)" $(MAKEFILE_LIST) \
188+
| sed -Ee "s/^/ /" -e 's/[[:space:]]*:[[:alnum:] _-]*#[[:space:]]*/ · /'

0 commit comments

Comments
 (0)