Skip to content

Commit 43f3641

Browse files
test: support gdvm in check.sh
Allows easily testing against a given version of Godot simply by passing a version to the -g/--godot-version parameter, assuming that gdvm is installed. For example: ./check.sh itest -g 4.3.0
1 parent 7461251 commit 43f3641

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

check.sh

+43-7
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ 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+
-g, --godot-version (works only if GODOT4_BIN is not set and gdvm is
42+
in path) specify the Godot version to use (e.g. 4.3.0).
43+
Will also use the corresponding API feature.
4144
4245
Examples:
4346
check.sh fmt clippy
@@ -78,12 +81,27 @@ function findGodot() {
7881
# $godotBin previously detected.
7982
if [[ -v godotBin ]]; then
8083
return
84+
fi
85+
86+
gdvmArgs=()
8187

8288
# User-defined GODOT4_BIN.
83-
elif [[ -n "$GODOT4_BIN" ]]; then
89+
if [[ -n "$GODOT4_BIN" ]]; then
8490
log "Using environment variable GODOT4_BIN=$(printf %q "$GODOT4_BIN")"
8591
godotBin="$GODOT4_BIN"
8692

93+
# gdvm
94+
elif command -v gdvm >/dev/null; then
95+
log "Found 'gdvm' executable"
96+
godotBin="gdvm"
97+
gdvmArgs+=("run")
98+
99+
if [[ -n "$gdvmGodotVersion" ]]; then
100+
gdvmArgs+=("$gdvmGodotVersion" "--force")
101+
fi
102+
103+
gdvmArgs+=("--console" "--")
104+
87105
# Executable in path.
88106
elif command -v godot4 >/dev/null; then
89107
log "Found 'godot4' executable"
@@ -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" "${gdvmArgs[@]}" --path itest/godot --headless -- "[${extraArgs[@]}]"
161179
}
162180

163181
function cmd_doc() {
@@ -177,6 +195,7 @@ function cmd_dok() {
177195
extraCargoArgs=("--no-default-features")
178196
cmds=()
179197
nextArgIsFilter=false
198+
nextArgIsGodotVersion=false
180199
extraArgs=()
181200

182201
for arg in "$@"; do
@@ -202,10 +221,27 @@ for arg in "$@"; do
202221
exit 2
203222
fi
204223
;;
224+
-g | --godot-version)
225+
nextArgIsGodotVersion=true
226+
;;
205227
*)
206228
if $nextArgIsFilter; then
207229
extraArgs+=("$arg")
208230
nextArgIsFilter=false
231+
elif $nextArgIsGodotVersion; then
232+
gdvmGodotVersion="$arg"
233+
nextArgIsGodotVersion=false
234+
235+
if [[ ! "$gdvmGodotVersion" =~ ^4\.[0-9]+\.[0-9]+$ ]]; then
236+
log "Invalid Godot version string '$gdvmGodotVersion'."
237+
log "The version string should be in the form 'x.x.x' and the major version should be at least 4."
238+
exit 2
239+
fi
240+
241+
# API version is the same but with periods replaced by hyphens, and a .0 patch version is omitted if present.
242+
# E.g. 4.3.0 -> api-4-3, 4.3.1 -> api-4-3-1
243+
apiFeature="godot/api-$(echo "$gdvmGodotVersion" | sed 's/\./-/g' | sed 's/-0$//')"
244+
extraCargoArgs+=("--features" "$apiFeature")
209245
else
210246
log "Unrecognized argument '$arg'. Use '$0 --help' to see what's available."
211247
exit 2

0 commit comments

Comments
 (0)