build: add server-rs test scripts

This commit is contained in:
2026-04-21 01:42:47 +08:00
parent 440d60d563
commit 6a560236f4
5 changed files with 96 additions and 3 deletions

View File

@@ -0,0 +1,49 @@
[CmdletBinding()]
param(
[Alias("h")]
[switch]$Help,
[string]$Package = ""
)
$ErrorActionPreference = "Stop"
function Write-Usage {
@(
'Usage:'
' ./server-rs/scripts/test.ps1'
' ./server-rs/scripts/test.ps1 -Package api-server'
''
'Notes:'
' 1. Run cargo test for the server-rs workspace by default'
' 2. Use -Package to target one workspace package only'
) -join [Environment]::NewLine
}
if ($Help) {
Write-Usage
exit 0
}
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$serverRsDir = Split-Path -Parent $scriptDir
$manifestPath = Join-Path $serverRsDir "Cargo.toml"
if (-not (Test-Path $manifestPath)) {
throw "Missing server-rs/Cargo.toml, cannot start test script."
}
Write-Host "[server-rs:test] working dir: $serverRsDir"
Push-Location $serverRsDir
try {
if ([string]::IsNullOrWhiteSpace($Package)) {
cargo test --manifest-path $manifestPath
}
else {
Write-Host "[server-rs:test] target package: $Package"
cargo test -p $Package --manifest-path $manifestPath
}
}
finally {
Pop-Location
}

40
server-rs/scripts/test.sh Normal file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'EOF'
Usage:
./server-rs/scripts/test.sh
SERVER_RS_TEST_PACKAGE=api-server ./server-rs/scripts/test.sh
Notes:
1. Run cargo test for the server-rs workspace by default
2. Use SERVER_RS_TEST_PACKAGE to target one workspace package only
EOF
}
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
usage
exit 0
fi
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
SERVER_RS_DIR="$(cd -- "${SCRIPT_DIR}/.." && pwd)"
MANIFEST_PATH="${SERVER_RS_DIR}/Cargo.toml"
if [[ ! -f "${MANIFEST_PATH}" ]]; then
echo "[server-rs:test] Missing ${MANIFEST_PATH}, cannot start test script." >&2
exit 1
fi
echo "[server-rs:test] working dir: ${SERVER_RS_DIR}"
cd "${SERVER_RS_DIR}"
if [[ -n "${SERVER_RS_TEST_PACKAGE:-}" ]]; then
echo "[server-rs:test] target package: ${SERVER_RS_TEST_PACKAGE}"
cargo test -p "${SERVER_RS_TEST_PACKAGE}" --manifest-path "${MANIFEST_PATH}"
else
cargo test --manifest-path "${MANIFEST_PATH}"
fi