Skip to content

Visual Studio Code, rebuilt in Rust

Rust
2.5 KB
Raw Blame
#!/bin/bash
# Runs a built-in extension's integration tests (its out/test, as .vscode-test.js and scripts/test-integration.sh run
# them on the reference) against vsrustium and prints mocha's summary.
# Usage, from the repo root on the Studio: port/tools/extension-tests <extension> [workspace folder]
# The extension and its compiled tests come from the untouched 1.148.0 reference checkout, copied next to the
# reference's test runner as the tests' `../../../../test/integration/electron/testrunner` import expects; the
# workspace is a new empty folder unless one is given (.vscode-test.js's `<label>out-<n>` temp folders); a relative
# one is a folder of the extension's copy (markdown-language-features runs in `test-workspace`).
# MOCHA_GREP=<pattern> runs only the matching tests. TESTS=<folder> picks the compiled tests (default out/test;
# scripts/test-integration.sh runs typescript-language-features from out/test/unit). APP=reference runs them in the
# reference build instead.
set -uo pipefail
extension=$1
REF=${REF:-$HOME/Developer/vscode-ref-1.148.0}
OUT=$(cd /tmp && pwd -P)/extension-tests-$extension-$(basename "$PWD")
rm -rf "$OUT" && mkdir -p "$OUT/tree/extensions" "$OUT/tree/test/integration/electron" "$OUT/workspace"
cp -cR "$REF/extensions/$extension" "$OUT/tree/extensions/"
cp "$REF/test/integration/electron/testrunner.js" "$OUT/tree/test/integration/electron/"
ln -s "$REF/node_modules" "$OUT/tree/node_modules"
tests=$OUT/tree/extensions/$extension
workspace=${2:-$OUT/workspace}
[[ $workspace == /* ]] || workspace=$tests/$workspace
args=("$workspace" --user-data-dir "$OUT/user-data" --disable-workspace-trust --extensionDevelopmentPath="$tests" --extensionTestsPath="$tests/${TESTS:-out/test}")
if [[ ${APP:-port} == reference ]]; then
  source port/tools/gui-lock.sh
  SHELL=/bin/bash VSCODE_DEV=1 NODE_ENV=development timeout 600 "$REF/.build/electron/Code - OSS.app/Contents/MacOS/Code - OSS" "$REF" "${args[@]}" \
    --disable-extension GitHub.copilot-chat >"$OUT/log" 2>&1
else
  (cd native && cargo gc build --release -q -p app) || exit 1
  # configuration-editing's extensions.json cases expect js-debug, a product.json built-in a new mirror lacks.
  port/tools/fetch-builtin-extensions >/dev/null || exit 1
  source port/tools/gui-lock.sh
  SHELL=/bin/bash VSCODE_GPUI_EXTENSIONS=$REF/extensions timeout 600 native/target/release/vsrustium "${args[@]}" >"$OUT/log" 2>&1
fi
code=$?
sed $'s/\x1b\\[[0-9;]*m//g' "$OUT/log" | grep -E '^ *([0-9]+ (passing|pending|failing)|✔|[0-9]+\) )' | sed 's/^ *//' | sort -u
echo "exit $code (log $OUT/log)"
exit "$code"