Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d445ffe

Browse files
committedJan 20, 2025
test: support switching API versions in check.sh
Allows easily testing with a given version of the Godot API bindings simply by passing a version to the -a/--api-version parameter.
1 parent 7461251 commit d445ffe

File tree

1 file changed

+52
-16
lines changed

1 file changed

+52
-16
lines changed
 

‎check.sh

+52-16
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ Commands:
3434
dok generate docs and open in browser
3535
3636
Options:
37-
-h, --help print this help text
38-
--double run check with double-precision
39-
-f, --filter <arg> only run integration tests which contain any of the
40-
args (comma-separated). requires itest.
37+
-h, --help print this help text
38+
--double run check with double-precision
39+
-f, --filter <arg> only run integration tests which contain any of the
40+
args (comma-separated). requires itest.
41+
-a, --api-version <ver> specify the Godot API version to use (e.g. 4.3, 4.3.1).
4142
4243
Examples:
4344
check.sh fmt clippy
@@ -61,6 +62,22 @@ function log() {
6162
echo "$@" >&2
6263
}
6364

65+
# Converts a x.x.x version string to a feature string.
66+
# e.g. 4.3.0 -> godot/api-4-3, 4.3.1 -> godot/api-4-3-1
67+
function version_to_feature() {
68+
echo "godot/api-$(echo "$1" | sed 's/\./-/g' | sed 's/-0$//')"
69+
}
70+
71+
# Validates that the given string is a valid x.x.x version string.
72+
# Allow for .0 to be dropped (e.g. 4.3 is equivalent to 4.3.0).
73+
function validate_version_string() {
74+
if [[ ! "$1" =~ ^4\.[0-9]+(\.[0-9]+)?$ ]]; then
75+
log "Invalid Godot version string '$1'."
76+
log "The version string should be in the form 'x.x.x' or 'x.x' and the major version should be at least 4."
77+
exit 2
78+
fi
79+
}
80+
6481
# Echoes the given command to stderr, then executes it.
6582
function run() {
6683
# https://stackoverflow.com/a/76153233/14637
@@ -78,9 +95,10 @@ function findGodot() {
7895
# $godotBin previously detected.
7996
if [[ -v godotBin ]]; then
8097
return
98+
fi
8199

82100
# User-defined GODOT4_BIN.
83-
elif [[ -n "$GODOT4_BIN" ]]; then
101+
if [[ -n "$GODOT4_BIN" ]]; then
84102
log "Using environment variable GODOT4_BIN=$(printf %q "$GODOT4_BIN")"
85103
godotBin="$GODOT4_BIN"
86104

@@ -95,7 +113,7 @@ function findGodot() {
95113
log "Found 'godot4.bat' script"
96114
godotBin="godot4.bat"
97115

98-
# This should come last: only use this as a last resort as `godot` may refer to a
116+
# This should come last: only use this as a last resort as `godot` may refer to a
99117
# Godot 3.x installation.
100118
elif command -v godot >/dev/null; then
101119
# Check if `godot` actually is Godot 4.x
@@ -157,7 +175,7 @@ function cmd_test() {
157175
function cmd_itest() {
158176
findGodot && \
159177
run cargo build -p itest "${extraCargoArgs[@]}" && \
160-
run "$godotBin" --path itest/godot --headless -- "[${extraArgs[@]}]"
178+
run "$godotBin" $GODOT_ARGS --path itest/godot --headless -- "[${extraArgs[@]}]"
161179
}
162180

163181
function cmd_doc() {
@@ -176,10 +194,11 @@ function cmd_dok() {
176194
# `itest` compilations and `check.sh` runs. Note that this means some runs are different from CI.
177195
extraCargoArgs=("--no-default-features")
178196
cmds=()
179-
nextArgIsFilter=false
180197
extraArgs=()
198+
apiVersion=""
181199

182-
for arg in "$@"; do
200+
while [[ $# -gt 0 ]]; do
201+
arg="$1"
183202
case "$arg" in
184203
-h | --help | help)
185204
echo "$HELP_TEXT"
@@ -196,22 +215,39 @@ for arg in "$@"; do
196215
;;
197216
-f | --filter)
198217
if [[ "${cmds[*]}" =~ itest ]]; then
199-
nextArgIsFilter=true
218+
if [[ -z "$2" ]]; then
219+
log "-f/--filter requires an argument."
220+
exit 2
221+
fi
222+
223+
extraArgs+=("$2")
224+
shift
200225
else
201226
log "-f/--filter requires 'itest' to be specified as a command."
202227
exit 2
203228
fi
204229
;;
205-
*)
206-
if $nextArgIsFilter; then
207-
extraArgs+=("$arg")
208-
nextArgIsFilter=false
209-
else
210-
log "Unrecognized argument '$arg'. Use '$0 --help' to see what's available."
230+
-a | --api-version)
231+
if [[ -z "$2" || "$2" == -* ]]; then
232+
log "-a/--api-version requires an argument."
211233
exit 2
212234
fi
235+
236+
apiVersion="$2"
237+
validate_version_string "$apiVersion"
238+
239+
apiFeature=$(version_to_feature "$apiVersion")
240+
extraCargoArgs+=("--features" "$apiFeature")
241+
242+
echo "Using Godot API version $apiVersion with feature $apiFeature"
243+
shift
244+
;;
245+
*)
246+
log "Unrecognized argument '$arg'. Use '$0 --help' to see what's available."
247+
exit 2
213248
;;
214249
esac
250+
shift
215251
done
216252

217253
# Default if no commands are explicitly given.

0 commit comments

Comments
 (0)
Please sign in to comment.