Skip to content

Commit 11b49b4

Browse files
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 55a7d99 commit 11b49b4

File tree

1 file changed

+89
-16
lines changed

1 file changed

+89
-16
lines changed

check.sh

+89-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
@@ -50,6 +51,7 @@ EOF
5051
# Terminal color codes.
5152
RED='\033[1;31m'
5253
CYAN='\033[1;36m'
54+
YELLOW='\033[1;33m'
5355
END='\033[0m'
5456

5557
################################################################################
@@ -61,6 +63,22 @@ function log() {
6163
echo "$@" >&2
6264
}
6365

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

82101
# User-defined GODOT4_BIN.
83-
elif [[ -n "$GODOT4_BIN" ]]; then
102+
if [[ -n "$GODOT4_BIN" ]]; then
84103
log "Using environment variable GODOT4_BIN=$(printf %q "$GODOT4_BIN")"
85104
godotBin="$GODOT4_BIN"
86105

@@ -95,7 +114,7 @@ function findGodot() {
95114
log "Found 'godot4.bat' script"
96115
godotBin="godot4.bat"
97116

98-
# This should come last: only use this as a last resort as `godot` may refer to a
117+
# This should come last: only use this as a last resort as `godot` may refer to a
99118
# Godot 3.x installation.
100119
elif command -v godot >/dev/null; then
101120
# Check if `godot` actually is Godot 4.x
@@ -157,7 +176,7 @@ function cmd_test() {
157176
function cmd_itest() {
158177
findGodot && \
159178
run cargo build -p itest "${extraCargoArgs[@]}" && \
160-
run "$godotBin" --path itest/godot --headless -- "[${extraArgs[@]}]"
179+
run "$godotBin" $GODOT_ARGS --path itest/godot --headless -- "[${extraArgs[@]}]"
161180
}
162181

163182
function cmd_doc() {
@@ -176,10 +195,11 @@ function cmd_dok() {
176195
# `itest` compilations and `check.sh` runs. Note that this means some runs are different from CI.
177196
extraCargoArgs=("--no-default-features")
178197
cmds=()
179-
nextArgIsFilter=false
180198
extraArgs=()
199+
apiVersion=""
181200

182-
for arg in "$@"; do
201+
while [[ $# -gt 0 ]]; do
202+
arg="$1"
183203
case "$arg" in
184204
-h | --help | help)
185205
echo "$HELP_TEXT"
@@ -196,29 +216,82 @@ for arg in "$@"; do
196216
;;
197217
-f | --filter)
198218
if [[ "${cmds[*]}" =~ itest ]]; then
199-
nextArgIsFilter=true
219+
if [[ -z "$2" ]]; then
220+
log "-f/--filter requires an argument."
221+
exit 2
222+
fi
223+
224+
extraArgs+=("$2")
225+
shift
200226
else
201227
log "-f/--filter requires 'itest' to be specified as a command."
202228
exit 2
203229
fi
204230
;;
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."
231+
-a | --api-version)
232+
if [[ -z "$2" || "$2" == -* ]]; then
233+
log "-a/--api-version requires an argument."
211234
exit 2
212235
fi
236+
237+
apiVersion="$2"
238+
validate_version_string "$apiVersion"
239+
240+
apiFeature=$(version_to_feature "$apiVersion")
241+
extraCargoArgs+=("--features" "$apiFeature")
242+
243+
log "Using Godot API version $apiVersion with feature $apiFeature"
244+
245+
# Remove "clippy" from the default commands if the API version is specified
246+
# since it can produce unexpected errors.
247+
DEFAULT_COMMANDS=("${DEFAULT_COMMANDS[@]/clippy}")
248+
249+
shift
250+
;;
251+
*)
252+
log "Unrecognized argument '$arg'. Use '$0 --help' to see what's available."
253+
exit 2
213254
;;
214255
esac
256+
shift
215257
done
216258

217259
# Default if no commands are explicitly given.
218260
if [[ ${#cmds[@]} -eq 0 ]]; then
219261
cmds=("${DEFAULT_COMMANDS[@]}")
220262
fi
221263

264+
# Filter out any empty strings and note if clippy will be run.
265+
filtered_commands=()
266+
runClippy=0
267+
for cmd in "${cmds[@]}"; do
268+
if [[ -n "$cmd" ]]; then
269+
filtered_commands+=("$cmd")
270+
271+
if [[ "$cmd" == "clippy" ]]; then
272+
runClippy=1
273+
fi
274+
fi
275+
done
276+
cmds=("${filtered_commands[@]}")
277+
278+
# Display warning about using clippy if an API version was provided.
279+
if [[ "${#apiFeature[@]}" -ne 0 ]]; then
280+
log
281+
# Show different warning depending on if clippy was explicitly requested.
282+
if [[ "$runClippy" -eq 1 ]]; then
283+
log -e "${YELLOW}Warning: Clippy may produce unexpected errors when testing against a specific API version.${END}"
284+
else
285+
log -e "${YELLOW}Warning: Clippy is disabled by default when using a specific Godot API version.${END}"
286+
fi
287+
log -e "${YELLOW}For more information, see issue #1016 on GitHub:${END}"
288+
log -e "${CYAN}https://github.com/godot-rust/gdext/pull/1016#issuecomment-2629002047${END}"
289+
log
290+
fi
291+
292+
log "Checks to run: ${cmds[*]}"
293+
log
294+
222295
################################################################################
223296
# Execution and summary
224297
################################################################################

0 commit comments

Comments
 (0)