Skip to content

Commit

Permalink
test: Add basic code coverage script
Browse files Browse the repository at this point in the history
For now it only tests the wasi-fyi tests.

Needs to be extended with all the other tests.
  • Loading branch information
theduke committed Feb 25, 2024
1 parent 114e724 commit 3cb6296
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions scripts/code-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

set -Eeuxo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# get absolute path of the root dir
ROOT_DIR="$( cd "${DIR}/.." && pwd )"

export CARGO_TARGET_DIR="$ROOT_DIR/target/llvm-cov"

# Set the environment variables needed to get coverage.
source <(cargo llvm-cov show-env --export-prefix)

# Remove artifacts that may affect the coverage results.
# This command should be called after show-env.
# cargo llvm-cov clean --workspace
# Above two commands should be called before build binaries.

# Build rust binaries.
cargo build --locked -p wasmer-cli -F singlepass,cranelift --release

# cargo-llvm-cov expects the debug binaries to be in /debug.
# We compile with --release because otherwise running is way too slow.
# So we copy the release binaries to /debug, which makes things work.
rm -rf "$CARGO_TARGET_DIR/debug"
cp -r "$CARGO_TARGET_DIR/release" "$CARGO_TARGET_DIR/debug"

# Commands using binaries in target/, including `cargo test` and other cargo subcommands.

TEST_RUNNER="$CARGO_TARGET_DIR/release/wasmer" $ROOT_DIR/tests/wasi-fyi/test.sh

# Generate reports.
cargo llvm-cov report --html

0 comments on commit 3cb6296

Please sign in to comment.