Skip to content

Commit 2dd80ba

Browse files
committed
tests: coverage for 'compact'-formatted Runfile behavior
1 parent 4bbc526 commit 2dd80ba

File tree

2 files changed

+310
-0
lines changed

2 files changed

+310
-0
lines changed

tests/compact/Makefile

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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+
for x in abc hjkl xyz; \
42+
do \
43+
echo -n " $${x} ::"; \
44+
done
45+
echo
46+
for x in abc hjkl xyz; do \
47+
echo -n " $${x} ::"; \
48+
done
49+
echo
50+
for x in abc hjkl xyz; \
51+
do echo -n " $${x} ::"; \
52+
done
53+
echo
54+
echo "--- while loops ---"
55+
while read x; \
56+
do \
57+
echo -n " $${x} ::"; \
58+
done <<< $$'abc\n hjkl\n xyz'
59+
echo
60+
while read x; do \
61+
echo -n " $${x} ::"; \
62+
done <<< $$'abc\n hjkl\n xyz'
63+
echo
64+
while read x; \
65+
do echo -n " $${x} ::"; \
66+
done <<< $$'abc\n hjkl\n xyz'
67+
echo
68+
echo "--- if constructs ---"
69+
x=''
70+
if [[ -z "$${x}" ]]; \
71+
then \
72+
echo -n " abc"; \
73+
echo -n " ::"; \
74+
elif [[ "$${x}" =~ a[Bb][a-z]$$ ]]; \
75+
then \
76+
echo -n " hjkl"; \
77+
echo -n " ::"; \
78+
else \
79+
echo -n " xyz"; \
80+
echo -n " ::"; \
81+
fi
82+
y=''
83+
if [[ -n "$${y}" ]]; then \
84+
echo -n " abc"; \
85+
echo -n " ::"; \
86+
elif ! [[ "$${y}" =~ a[Bb][a-z]$$ ]]; then \
87+
echo -n " hjkl"; \
88+
echo -n " ::"; \
89+
else \
90+
echo -n " xyz"; \
91+
echo -n " ::"; \
92+
fi
93+
z=''
94+
if [[ -z "$${x}" ]]; \
95+
then x='abc'; echo -n " $${x} ::"; \
96+
elif [[ x =~ a[Bb][a-z]$$ ]]; \
97+
then x='hjkl'; echo -n " $${x} ::"; \
98+
else echo -n " $${x} ::"; \
99+
fi
100+
echo
101+
echo "--- for loops :: pathological semicolon usage ---"
102+
for x in abc hjkl xyz; \
103+
do \
104+
echo -n " $${x} ::"; \
105+
done
106+
echo
107+
for x in abc hjkl xyz; do \
108+
echo -n " $${x} ::"; \
109+
done
110+
echo
111+
for x in abc hjkl xyz; \
112+
do echo -n " $${x} ::"; \
113+
done
114+
echo
115+
echo "--- while loops :: pathological semicolon usage ---"
116+
while read x; \
117+
do \
118+
echo -n " $${x} ::"; \
119+
done <<< $$'abc\n hjkl\n xyz';
120+
echo
121+
while read x; do \
122+
echo -n " $${x} ::"; \
123+
done <<< $$'abc\n hjkl\n xyz';
124+
echo
125+
while read x; \
126+
do echo -n " $${x} ::"; \
127+
done <<< $$'abc\n hjkl\n xyz';
128+
echo
129+
echo "--- if constructs :: pathological semicolon usage ---"
130+
x=''
131+
if [[ -z "$${x}" ]]; \
132+
then \
133+
echo -n " abc"; \
134+
echo -n " ::"; \
135+
elif [[ "$${x}" =~ a[Bb][a-z]$$ ]]; \
136+
then \
137+
echo -n " hjkl"; \
138+
echo -n " ::"; \
139+
else \
140+
echo -n " xyz"; \
141+
echo -n " ::"; \
142+
fi
143+
y=''
144+
if [[ -n "$${y}" ]]; then \
145+
echo -n " abc"; \
146+
echo -n " ::"; \
147+
elif ! [[ "$${y}" =~ a[Bb][a-z]$$ ]]; then \
148+
echo -n " hjkl"; \
149+
echo -n " ::"; \
150+
else \
151+
echo -n " xyz"; \
152+
echo -n " ::"; \
153+
fi
154+
z=''
155+
if [[ -z "$${x}" ]]; \
156+
then x='abc'; echo -n " $${x} ::"; \
157+
elif [[ x =~ a[Bb][a-z]$$ ]]; \
158+
then x='hjkl'; echo -n " $${x} ::"; \
159+
else echo -n " $${x} ::"; \
160+
fi
161+
162+
.PHONY: .tasks
163+
.tasks:
164+
grep -E "^(([[:alnum:]_-][[:alnum:][:space:]_-]+):([[:alnum:][:space:]_-]+)?#)" $(MAKEFILE_LIST) \
165+
| sed -Ee "s/^/ /" -e 's/[[:space:]]*:[[:alnum:] _-]*#[[:space:]]*/ · /'

tests/compact/Runfile

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
start: stop # start app
2+
run build env=dev # tasks can be run directly from other tasks
3+
echo "starting app"
4+
run loading
5+
EXIT run loading --fin # prefixing command with signal registers a trap
6+
INT run loading --fin
7+
stop: # stop app
8+
HUP run loading --fin
9+
echo "stopping app"
10+
loading: # show loading state
11+
if [[ $(@) == '--fin' ]]
12+
then
13+
echo "loading finished"
14+
else
15+
echo "loading started"
16+
fi
17+
build: lint # build app for environment [vars: env]
18+
[[ -n $(env) ]] && echo "buiding app for $(env)" || echo "error: missing env"
19+
test: # run all tests or specific tests [vars: name1, name2, etc.]
20+
run build env=test
21+
[[ -n $(@) ]] && echo "running tests $(@)" || echo "running all tests"
22+
lint: # lint all files or specific file [vars: file]
23+
[[ -n $(1) ]] && echo "linting file $(1)" || echo "linting all files"
24+
complex: # a sample command exploring complex multiline syntax
25+
echo "--- for loops ---"
26+
for x in abc hjkl xyz
27+
do
28+
echo -n " $${x} ::"
29+
done
30+
echo
31+
for x in abc hjkl xyz; do
32+
echo -n " $${x} ::"
33+
done
34+
echo
35+
for x in abc hjkl xyz
36+
do echo -n " $${x} ::"
37+
done
38+
echo
39+
echo "--- while loops ---"
40+
while read x
41+
do
42+
echo -n " $${x} ::"
43+
done <<< $$'abc\n hjkl\n xyz'
44+
echo
45+
while read x; do
46+
echo -n " $${x} ::"
47+
done <<< $$'abc\n hjkl\n xyz'
48+
echo
49+
while read x
50+
do echo -n " $${x} ::"
51+
done <<< $$'abc\n hjkl\n xyz'
52+
echo
53+
echo "--- if constructs ---"
54+
x=''
55+
if [[ -z "$${x}" ]]
56+
then
57+
echo -n " abc"
58+
echo -n " ::"
59+
elif [[ "$${x}" =~ a[Bb][a-z]$$ ]]
60+
then
61+
echo -n " hjkl"
62+
echo -n " ::"
63+
else
64+
echo -n " xyz"
65+
echo -n " ::"
66+
fi
67+
y=''
68+
if [[ -n "$${y}" ]]; then
69+
echo -n " abc"
70+
echo -n " ::"
71+
elif ! [[ "$${y}" =~ a[Bb][a-z]$$ ]]; then
72+
echo -n " hjkl"
73+
echo -n " ::"
74+
else
75+
echo -n " xyz"
76+
echo -n " ::"
77+
fi
78+
z=''
79+
if [[ -z "$${x}" ]]
80+
then x='abc'; echo -n " $${x} ::"
81+
elif [[ x =~ a[Bb][a-z]$$ ]]
82+
then x='hjkl'; echo -n " $${x} ::"
83+
else echo -n " $${x} ::"
84+
fi
85+
echo
86+
echo "--- for loops :: pathological semicolon usage ---"
87+
for x in abc hjkl xyz;
88+
do
89+
echo -n " $${x} ::";
90+
done
91+
echo
92+
for x in abc hjkl xyz; do
93+
echo -n " $${x} ::";
94+
done
95+
echo
96+
for x in abc hjkl xyz;
97+
do echo -n " $${x} ::";
98+
done
99+
echo
100+
echo "--- while loops :: pathological semicolon usage ---"
101+
while read x;
102+
do
103+
echo -n " $${x} ::";
104+
done <<< $$'abc\n hjkl\n xyz';
105+
echo
106+
while read x; do
107+
echo -n " $${x} ::";
108+
done <<< $$'abc\n hjkl\n xyz';
109+
echo
110+
while read x;
111+
do echo -n " $${x} ::";
112+
done <<< $$'abc\n hjkl\n xyz';
113+
echo
114+
echo "--- if constructs :: pathological semicolon usage ---"
115+
x=''
116+
if [[ -z "$${x}" ]];
117+
then
118+
echo -n " abc";
119+
echo -n " ::";
120+
elif [[ "$${x}" =~ a[Bb][a-z]$$ ]];
121+
then
122+
echo -n " hjkl";
123+
echo -n " ::";
124+
else
125+
echo -n " xyz";
126+
echo -n " ::";
127+
fi
128+
y=''
129+
if [[ -n "$${y}" ]]; then
130+
echo -n " abc";
131+
echo -n " ::";
132+
elif ! [[ "$${y}" =~ a[Bb][a-z]$$ ]]; then
133+
echo -n " hjkl";
134+
echo -n " ::";
135+
else
136+
echo -n " xyz";
137+
echo -n " ::";
138+
fi
139+
z=''
140+
if [[ -z "$${x}" ]];
141+
then x='abc'; echo -n " $${x} ::";
142+
elif [[ x =~ a[Bb][a-z]$$ ]];
143+
then x='hjkl'; echo -n " $${x} ::";
144+
else echo -n " $${x} ::";
145+
fi

0 commit comments

Comments
 (0)