summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2021-06-20 14:17:50 -0700
committerZac Medico <zmedico@gentoo.org>2021-06-20 17:35:14 -0700
commit372d3fe6ab0afb0248190a23b6a1bd270617978d (patch)
treea3b6f1ebf328bf330fcf7cffffbcd93438906074
parentmedia-sound/pulseaudio: fix building with USE=-glib (diff)
downloadgentoo-372d3fe6ab0afb0248190a23b6a1bd270617978d.tar.gz
gentoo-372d3fe6ab0afb0248190a23b6a1bd270617978d.tar.bz2
gentoo-372d3fe6ab0afb0248190a23b6a1bd270617978d.zip
dev-lang/starlark-rust: Add feature tests to src_test
Package-Manager: Portage-3.0.20, Repoman-3.0.3 Signed-off-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r--dev-lang/starlark-rust/files/test/features.bash193
-rw-r--r--dev-lang/starlark-rust/starlark-rust-0.4.0.ebuild7
2 files changed, 199 insertions, 1 deletions
diff --git a/dev-lang/starlark-rust/files/test/features.bash b/dev-lang/starlark-rust/files/test/features.bash
new file mode 100644
index 000000000000..1fd74e3326e9
--- /dev/null
+++ b/dev-lang/starlark-rust/files/test/features.bash
@@ -0,0 +1,193 @@
+#!/usr/bin/env bash
+
+# shellcheck disable=SC2034
+STARLARK_RUST_EXPECTED_functions=(
+ any
+ dir
+ fail
+ getattr
+ hasattr
+ hash
+ len
+ max
+ min
+ print
+ range
+ repr
+ reversed
+ sorted
+ type
+ zip
+)
+
+# shellcheck disable=SC2034
+STARLARK_RUST_EXPECTED_types=(
+ bool
+ int
+ list
+ str
+ tuple
+ dict
+)
+
+# shellcheck disable=SC2034
+STARLARK_RUST_EXPECTED_dict_methods=(
+ clear
+ get
+ items
+ keys
+ pop
+ popitem
+ setdefault
+ update
+ values
+)
+
+# shellcheck disable=SC2034
+STARLARK_RUST_EXPECTED_list_methods=(
+ append
+ clear
+ extend
+ index
+ insert
+ pop
+ remove
+)
+
+# shellcheck disable=SC2034
+STARLARK_RUST_EXPECTED_str_methods=(
+ capitalize
+ count
+ elems
+ endswith
+ find
+ format
+ index
+ isalnum
+ isalpha
+ isdigit
+ islower
+ isspace
+ istitle
+ isupper
+ join
+ lower
+ lstrip
+ partition
+ replace
+ rfind
+ rindex
+ rpartition
+ rsplit
+ rstrip
+ split
+ splitlines
+ startswith
+ strip
+ title
+ upper
+)
+
+_test-features_execute-test() {
+ local error_msg test_title=$1 test_stdin=$2 exp_stdout=$3 exp_stderr=$4 exp_exitcode=$5
+ ebegin "$test_title"
+ error_msg=$(
+ stderr_file=$(mktemp) || exit
+ cleanup() { rm -f "$stderr_file"; }
+ trap cleanup EXIT
+
+ test_stdout=$("$starlark_binary" -i --json <<< "$test_stdin" 2>"$stderr_file")
+ test_exitcode=$?
+
+ if (( test_exitcode != exp_exitcode )); then
+ echo "unexpected exit code \"$test_exitcode\", expected exit code \"$exp_exitcode\" for test_stdin: $test_stdin"
+ exit 1
+ elif [[ "$test_stdout" != "$exp_stdout" ]]; then
+ echo "unexpected stdout \"$test_stdout\", expected stdout \"$exp_stdout\" for test_stdin: $test_stdin"
+ exit 1
+ elif [[ $(< "$stderr_file") != "$exp_stderr" ]]; then
+ echo "unexpected stderr \"$(< "$stderr_file")\", expected stderr \"$exp_stderr\" for test_stdin: $test_stdin"
+ exit 1
+ fi
+ exit 0
+ )
+ eend $? "$error_msg"
+
+ # shellcheck disable=SC2015
+ [[ $error_msg ]] && failures+=("$error_msg") || (( successes += 1 ))
+}
+
+test-features_main() {
+ local starlark_binary=$1
+ local failures=() successes=0
+ local banner_width=45
+
+ local attr attr_type test_case
+ for attr_type in function type; do
+ printf -- '\n\n' >&2
+ printf -- '%s\n' "Checking for existence of expected ${attr_type}s" >&2
+ eval "printf -- '=%.0s' {1..${banner_width}}" >&2
+ echo >&2
+ while read -r attr; do
+ test_case=(
+ "$attr"
+ "$attr and print('$attr exists')"
+ "$attr exists"
+ ""
+ 0
+ )
+ _test-features_execute-test "${test_case[@]}"
+ done < <(eval "printf -- '%s\n' \"\${STARLARK_RUST_EXPECTED_${attr_type}s[@]}\"")
+ done
+
+ local attr attr_type test_case type_literal
+ for attr_type in dict list str; do
+ printf -- '\n\n' >&2
+ printf -- '%s\n' "Checking ${attr_type} built-in methods" >&2
+ eval "printf -- '=%.0s' {1..${banner_width}}" >&2
+ echo >&2
+
+ case $attr_type in
+ str)
+ type_literal='""'
+ ;;
+ *)
+ type_literal="$attr_type()"
+ ;;
+ esac
+
+ while read -r attr; do
+ test_case=(
+ "$attr_type.$attr"
+ "hasattr($type_literal, \"$attr\") and print('$attr method exists')"
+ "$attr method exists"
+ ""
+ 0
+ )
+ _test-features_execute-test "${test_case[@]}"
+ done < <(eval "printf -- '%s\n' \"\${STARLARK_RUST_EXPECTED_${attr_type}_methods[@]}\"")
+ done
+
+ printf -- '\n\n' >&2
+ printf -- '%s\n' "Checking for miscellaneous starlark features" >&2
+ eval "printf -- '=%.0s' {1..${banner_width}}" >&2
+ printf -- '\n\n' >&2
+
+ test_case=(
+ 'list comprehension'
+ '[print("output from list comprehension") for i in range(0, 1) if (i == 0 and True) or not False]'
+ 'output from list comprehension'
+ ""
+ 0
+ )
+ _test-features_execute-test "${test_case[@]}"
+ printf -- '\n\n' >&2
+
+ if (( ${#failures[@]} > 0 )); then
+ echo "${#failures[@]} test (s) failed" >&2
+ return 1
+ elif (( successes == 0 )); then
+ echo "no tests ran" >&2
+ return 1
+ fi
+}
diff --git a/dev-lang/starlark-rust/starlark-rust-0.4.0.ebuild b/dev-lang/starlark-rust/starlark-rust-0.4.0.ebuild
index 23f6be897226..9b5109aeab2d 100644
--- a/dev-lang/starlark-rust/starlark-rust-0.4.0.ebuild
+++ b/dev-lang/starlark-rust/starlark-rust-0.4.0.ebuild
@@ -172,7 +172,6 @@ LICENSE="Apache-2.0"
SLOT="0"
KEYWORDS="~amd64"
IUSE=""
-RESTRICT+=" test"
# Nightly rust-1.53.0 required for https://bugs.gentoo.org/796824
BDEPEND="${RUST_DEPEND}
@@ -184,6 +183,12 @@ src_prepare() {
default
}
+src_test() {
+ source "${FILESDIR}/test/features.bash" || die
+ unset -f test_features
+ test-features_main "${PWD}/target/release/starlark" || die
+}
+
src_install() {
dobin target/release/starlark
ln "${ED}/usr/bin/starlark"{,-rust} || die