Skip to content

Visual Studio Code, rebuilt in Rust

Rust
1.3 KB
Raw Blame
#!/bin/bash
# Runs `cargo gc test` in native/ and prints only compile errors, failed tests and the summary lines.
# Exits non-zero when cargo fails or when the filters match no test, so a mistyped filter cannot pass.
# Usage: port/tools/cargo-test [-p <crate>] [<filter or test flag>...]   (default crate: app; the rest goes after --)
set -uo pipefail
cd "$(dirname "$0")/../../native"
crate=app
if [[ ${1:-} == -p ]]; then
  crate=$2
  shift 2
fi
log=$(mktemp)
trap 'rm -f "$log"' EXIT
cargo gc test -p "$crate" -- "$@" >"$log" 2>&1
status=$?
awk -v status="$status" '
  /^test result:/ {
    ran += $4 + $6
    if ($4 + $6 > 0) { print; printed = 1 }
    failures = 0
    next
  }
  /^error(\[|:)/ { diagnostic = 1 }
  /^failures:$/ { failures = 1 }
  diagnostic || failures { print; printed = 1 }
  diagnostic && /^$/ { diagnostic = 0 }
  { tail[NR % 30] = $0 }
  END {
    # A failure with no error or failures block (a killed test binary): show the end of the log.
    if (status != 0 && !printed) {
      for (i = NR - 29; i <= NR; i++) if (i > 0) print tail[i % 30]
    }
    if (status == 0 && ran == 0) exit 2
  }
' "$log"
matched=$?
if ((status != 0)); then
  exit "$status"
fi
if ((matched == 2)); then
  echo "cargo-test: no test of $crate matches: $*" >&2
  exit 1
fi