1 |
commit: 372d3fe6ab0afb0248190a23b6a1bd270617978d |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Jun 20 21:17:50 2021 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Jun 21 00:35:14 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=372d3fe6 |
7 |
|
8 |
dev-lang/starlark-rust: Add feature tests to src_test |
9 |
|
10 |
Package-Manager: Portage-3.0.20, Repoman-3.0.3 |
11 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
12 |
|
13 |
dev-lang/starlark-rust/files/test/features.bash | 193 ++++++++++++++++++++++ |
14 |
dev-lang/starlark-rust/starlark-rust-0.4.0.ebuild | 7 +- |
15 |
2 files changed, 199 insertions(+), 1 deletion(-) |
16 |
|
17 |
diff --git a/dev-lang/starlark-rust/files/test/features.bash b/dev-lang/starlark-rust/files/test/features.bash |
18 |
new file mode 100644 |
19 |
index 00000000000..1fd74e3326e |
20 |
--- /dev/null |
21 |
+++ b/dev-lang/starlark-rust/files/test/features.bash |
22 |
@@ -0,0 +1,193 @@ |
23 |
+#!/usr/bin/env bash |
24 |
+ |
25 |
+# shellcheck disable=SC2034 |
26 |
+STARLARK_RUST_EXPECTED_functions=( |
27 |
+ any |
28 |
+ dir |
29 |
+ fail |
30 |
+ getattr |
31 |
+ hasattr |
32 |
+ hash |
33 |
+ len |
34 |
+ max |
35 |
+ min |
36 |
+ print |
37 |
+ range |
38 |
+ repr |
39 |
+ reversed |
40 |
+ sorted |
41 |
+ type |
42 |
+ zip |
43 |
+) |
44 |
+ |
45 |
+# shellcheck disable=SC2034 |
46 |
+STARLARK_RUST_EXPECTED_types=( |
47 |
+ bool |
48 |
+ int |
49 |
+ list |
50 |
+ str |
51 |
+ tuple |
52 |
+ dict |
53 |
+) |
54 |
+ |
55 |
+# shellcheck disable=SC2034 |
56 |
+STARLARK_RUST_EXPECTED_dict_methods=( |
57 |
+ clear |
58 |
+ get |
59 |
+ items |
60 |
+ keys |
61 |
+ pop |
62 |
+ popitem |
63 |
+ setdefault |
64 |
+ update |
65 |
+ values |
66 |
+) |
67 |
+ |
68 |
+# shellcheck disable=SC2034 |
69 |
+STARLARK_RUST_EXPECTED_list_methods=( |
70 |
+ append |
71 |
+ clear |
72 |
+ extend |
73 |
+ index |
74 |
+ insert |
75 |
+ pop |
76 |
+ remove |
77 |
+) |
78 |
+ |
79 |
+# shellcheck disable=SC2034 |
80 |
+STARLARK_RUST_EXPECTED_str_methods=( |
81 |
+ capitalize |
82 |
+ count |
83 |
+ elems |
84 |
+ endswith |
85 |
+ find |
86 |
+ format |
87 |
+ index |
88 |
+ isalnum |
89 |
+ isalpha |
90 |
+ isdigit |
91 |
+ islower |
92 |
+ isspace |
93 |
+ istitle |
94 |
+ isupper |
95 |
+ join |
96 |
+ lower |
97 |
+ lstrip |
98 |
+ partition |
99 |
+ replace |
100 |
+ rfind |
101 |
+ rindex |
102 |
+ rpartition |
103 |
+ rsplit |
104 |
+ rstrip |
105 |
+ split |
106 |
+ splitlines |
107 |
+ startswith |
108 |
+ strip |
109 |
+ title |
110 |
+ upper |
111 |
+) |
112 |
+ |
113 |
+_test-features_execute-test() { |
114 |
+ local error_msg test_title=$1 test_stdin=$2 exp_stdout=$3 exp_stderr=$4 exp_exitcode=$5 |
115 |
+ ebegin "$test_title" |
116 |
+ error_msg=$( |
117 |
+ stderr_file=$(mktemp) || exit |
118 |
+ cleanup() { rm -f "$stderr_file"; } |
119 |
+ trap cleanup EXIT |
120 |
+ |
121 |
+ test_stdout=$("$starlark_binary" -i --json <<< "$test_stdin" 2>"$stderr_file") |
122 |
+ test_exitcode=$? |
123 |
+ |
124 |
+ if (( test_exitcode != exp_exitcode )); then |
125 |
+ echo "unexpected exit code \"$test_exitcode\", expected exit code \"$exp_exitcode\" for test_stdin: $test_stdin" |
126 |
+ exit 1 |
127 |
+ elif [[ "$test_stdout" != "$exp_stdout" ]]; then |
128 |
+ echo "unexpected stdout \"$test_stdout\", expected stdout \"$exp_stdout\" for test_stdin: $test_stdin" |
129 |
+ exit 1 |
130 |
+ elif [[ $(< "$stderr_file") != "$exp_stderr" ]]; then |
131 |
+ echo "unexpected stderr \"$(< "$stderr_file")\", expected stderr \"$exp_stderr\" for test_stdin: $test_stdin" |
132 |
+ exit 1 |
133 |
+ fi |
134 |
+ exit 0 |
135 |
+ ) |
136 |
+ eend $? "$error_msg" |
137 |
+ |
138 |
+ # shellcheck disable=SC2015 |
139 |
+ [[ $error_msg ]] && failures+=("$error_msg") || (( successes += 1 )) |
140 |
+} |
141 |
+ |
142 |
+test-features_main() { |
143 |
+ local starlark_binary=$1 |
144 |
+ local failures=() successes=0 |
145 |
+ local banner_width=45 |
146 |
+ |
147 |
+ local attr attr_type test_case |
148 |
+ for attr_type in function type; do |
149 |
+ printf -- '\n\n' >&2 |
150 |
+ printf -- '%s\n' "Checking for existence of expected ${attr_type}s" >&2 |
151 |
+ eval "printf -- '=%.0s' {1..${banner_width}}" >&2 |
152 |
+ echo >&2 |
153 |
+ while read -r attr; do |
154 |
+ test_case=( |
155 |
+ "$attr" |
156 |
+ "$attr and print('$attr exists')" |
157 |
+ "$attr exists" |
158 |
+ "" |
159 |
+ 0 |
160 |
+ ) |
161 |
+ _test-features_execute-test "${test_case[@]}" |
162 |
+ done < <(eval "printf -- '%s\n' \"\${STARLARK_RUST_EXPECTED_${attr_type}s[@]}\"") |
163 |
+ done |
164 |
+ |
165 |
+ local attr attr_type test_case type_literal |
166 |
+ for attr_type in dict list str; do |
167 |
+ printf -- '\n\n' >&2 |
168 |
+ printf -- '%s\n' "Checking ${attr_type} built-in methods" >&2 |
169 |
+ eval "printf -- '=%.0s' {1..${banner_width}}" >&2 |
170 |
+ echo >&2 |
171 |
+ |
172 |
+ case $attr_type in |
173 |
+ str) |
174 |
+ type_literal='""' |
175 |
+ ;; |
176 |
+ *) |
177 |
+ type_literal="$attr_type()" |
178 |
+ ;; |
179 |
+ esac |
180 |
+ |
181 |
+ while read -r attr; do |
182 |
+ test_case=( |
183 |
+ "$attr_type.$attr" |
184 |
+ "hasattr($type_literal, \"$attr\") and print('$attr method exists')" |
185 |
+ "$attr method exists" |
186 |
+ "" |
187 |
+ 0 |
188 |
+ ) |
189 |
+ _test-features_execute-test "${test_case[@]}" |
190 |
+ done < <(eval "printf -- '%s\n' \"\${STARLARK_RUST_EXPECTED_${attr_type}_methods[@]}\"") |
191 |
+ done |
192 |
+ |
193 |
+ printf -- '\n\n' >&2 |
194 |
+ printf -- '%s\n' "Checking for miscellaneous starlark features" >&2 |
195 |
+ eval "printf -- '=%.0s' {1..${banner_width}}" >&2 |
196 |
+ printf -- '\n\n' >&2 |
197 |
+ |
198 |
+ test_case=( |
199 |
+ 'list comprehension' |
200 |
+ '[print("output from list comprehension") for i in range(0, 1) if (i == 0 and True) or not False]' |
201 |
+ 'output from list comprehension' |
202 |
+ "" |
203 |
+ 0 |
204 |
+ ) |
205 |
+ _test-features_execute-test "${test_case[@]}" |
206 |
+ printf -- '\n\n' >&2 |
207 |
+ |
208 |
+ if (( ${#failures[@]} > 0 )); then |
209 |
+ echo "${#failures[@]} test (s) failed" >&2 |
210 |
+ return 1 |
211 |
+ elif (( successes == 0 )); then |
212 |
+ echo "no tests ran" >&2 |
213 |
+ return 1 |
214 |
+ fi |
215 |
+} |
216 |
|
217 |
diff --git a/dev-lang/starlark-rust/starlark-rust-0.4.0.ebuild b/dev-lang/starlark-rust/starlark-rust-0.4.0.ebuild |
218 |
index 23f6be89722..9b5109aeab2 100644 |
219 |
--- a/dev-lang/starlark-rust/starlark-rust-0.4.0.ebuild |
220 |
+++ b/dev-lang/starlark-rust/starlark-rust-0.4.0.ebuild |
221 |
@@ -172,7 +172,6 @@ LICENSE="Apache-2.0" |
222 |
SLOT="0" |
223 |
KEYWORDS="~amd64" |
224 |
IUSE="" |
225 |
-RESTRICT+=" test" |
226 |
|
227 |
# Nightly rust-1.53.0 required for https://bugs.gentoo.org/796824 |
228 |
BDEPEND="${RUST_DEPEND} |
229 |
@@ -184,6 +183,12 @@ src_prepare() { |
230 |
default |
231 |
} |
232 |
|
233 |
+src_test() { |
234 |
+ source "${FILESDIR}/test/features.bash" || die |
235 |
+ unset -f test_features |
236 |
+ test-features_main "${PWD}/target/release/starlark" || die |
237 |
+} |
238 |
+ |
239 |
src_install() { |
240 |
dobin target/release/starlark |
241 |
ln "${ED}/usr/bin/starlark"{,-rust} || die |