forked from earthly/earthly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfor.earth
111 lines (100 loc) · 2.92 KB
/
for.earth
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
VERSION --for-in 0.5
FROM alpine:3.13
WORKDIR /test
all:
BUILD +test-for-ls
BUILD +test-for-empty
BUILD +test-for-single
BUILD +test-for-comma
BUILD +test-for-comma-colon
BUILD +test-for-constant
BUILD +test-for-expand-arg
BUILD +test-for-ls-locally
test-for-ls:
RUN touch a b c d
RUN ls
RUN ls | tr '\n' ' '
RUN test "$(ls | tr '\n' ' ')" = "a b c d "
FOR variable IN $(ls)
RUN echo "variable=$variable"
RUN echo "$variable" >>./output.txt
END
RUN cat ./output.txt
RUN cat ./output.txt | tr '\n' ' '
RUN test "$(cat ./output.txt | tr '\n' ' ')" = "a b c d "
test-for-empty:
FOR variable IN ""
RUN echo "fail! variable='$variable'"; false
END
FOR variable IN ''
RUN echo "fail! variable='$variable'"; false
END
ARG empty=""
FOR variable IN $empty
RUN echo "fail! variable='$variable'"; false
END
ARG empty2
FOR variable IN $empty2
RUN echo "fail! variable='$variable'"; false
END
FOR variable IN $(cat /dev/null)
RUN echo "fail! variable='$variable'"; false
END
FOR variable IN "$(cat /dev/null)"
RUN echo "fail! variable='$variable'"; false
END
test-for-single:
FOR variable IN one
RUN test ! -f ./single
RUN touch ./single
RUN test "$variable" = "one"
END
test-for-comma:
RUN echo "foo,bar:buz:zub,oof" >./input.txt
FOR --sep="," what IN $(cat ./input.txt)
RUN echo "what=$what"
RUN echo "$what" >>./output.txt
END
RUN cat ./output.txt
RUN cat ./output.txt | tr '\n' ' '
RUN test "$(cat ./output.txt | tr '\n' ' ')" = "foo bar:buz:zub oof "
test-for-comma-colon:
RUN echo "foo,bar:buz:zub,oof" >./input.txt
FOR --sep=",:" what IN $(cat ./input.txt)
RUN echo "what=$what"
RUN echo "$what" >>./output.txt
END
RUN cat ./output.txt
RUN cat ./output.txt | tr '\n' ' '
RUN test "$(cat ./output.txt | tr '\n' ' ')" = "foo bar buz zub oof "
test-for-constant:
FOR what IN "foo bar buz"
RUN echo "what=$what"
RUN echo "$what" >>./output.txt
END
RUN cat ./output.txt
RUN cat ./output.txt | tr '\n' ' '
RUN test "$(cat ./output.txt | tr '\n' ' ')" = "foo bar buz "
test-for-expand-arg:
ARG data="foo bar buz"
FOR what IN "$data"
RUN echo "what=$what"
RUN echo "$what" >>./output.txt
END
RUN cat ./output.txt
RUN cat ./output.txt | tr '\n' ' '
RUN test "$(cat ./output.txt | tr '\n' ' ')" = "foo bar buz "
test-for-ls-locally:
LOCALLY
WORKDIR test-locally
RUN touch a b c d
RUN ls
RUN ls | tr '\n' ' '
RUN test "$(ls | tr '\n' ' ')" = "a b c d "
FOR variable IN $(ls)
RUN echo "variable=$variable"
RUN echo "$variable" >>./output.txt
END
RUN cat ./output.txt
RUN cat ./output.txt | tr '\n' ' '
RUN test "$(cat ./output.txt | tr '\n' ' ')" = "a b c d "