From b3e4aa59215116d489c4e0cf68eabeb91e619d98 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Thu, 19 May 2022 12:07:34 -0400 Subject: [PATCH 1/6] grcov wrapper around run-tests.sh --- server/run-tests-with-grcov.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100755 server/run-tests-with-grcov.sh diff --git a/server/run-tests-with-grcov.sh b/server/run-tests-with-grcov.sh new file mode 100755 index 000000000..ebb3aa3ba --- /dev/null +++ b/server/run-tests-with-grcov.sh @@ -0,0 +1,8 @@ +rustup component add llvm-tools-preview + +RUSTFLAGS="-Cinstrument-coverage" +LLVM_PROFILE_FILE="svix-webhooks-%p-%m.profraw" + +./run-tests.sh + +grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/ From 78e089fc3a2a67ad8c01967b130710a174a40463 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Thu, 19 May 2022 16:55:40 +0000 Subject: [PATCH 2/6] gitignore and results streamlining --- server/.gitignore | 3 +++ server/run-tests-with-grcov.sh | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/server/.gitignore b/server/.gitignore index d98cbec7c..544282769 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -18,3 +18,6 @@ Cargo.lock Session.vim .env + +# grcov outputs +*.profraw diff --git a/server/run-tests-with-grcov.sh b/server/run-tests-with-grcov.sh index ebb3aa3ba..8d9715f7f 100755 --- a/server/run-tests-with-grcov.sh +++ b/server/run-tests-with-grcov.sh @@ -1,8 +1,20 @@ +#!/bin/sh -e + +# install deps +cargo install grcov rustup component add llvm-tools-preview +# set env vars RUSTFLAGS="-Cinstrument-coverage" LLVM_PROFILE_FILE="svix-webhooks-%p-%m.profraw" +RUSTC_BOOTSTRAP=1 +# run tests ./run-tests.sh +# back to stable +RUSTC_BOOTSTRAP=0 + +# generate and open report output grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/ +open ./target/debug/coverage/index.html From 8e4de041009ccdf39de9294d3c014646f91360b8 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Thu, 19 May 2022 17:44:22 +0000 Subject: [PATCH 3/6] feedback --- server/run-tests-with-grcov.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/server/run-tests-with-grcov.sh b/server/run-tests-with-grcov.sh index 8d9715f7f..8602a01fc 100755 --- a/server/run-tests-with-grcov.sh +++ b/server/run-tests-with-grcov.sh @@ -1,20 +1,20 @@ #!/bin/sh -e -# install deps -cargo install grcov -rustup component add llvm-tools-preview - -# set env vars +# cleanly run the following commands in their own session +bash -c " +# tell Rust to run with coverage instrumentation RUSTFLAGS="-Cinstrument-coverage" +# give grcov a profile name template for output files LLVM_PROFILE_FILE="svix-webhooks-%p-%m.profraw" +# put the compiler in nightly mode RUSTC_BOOTSTRAP=1 # run tests ./run-tests.sh - -# back to stable -RUSTC_BOOTSTRAP=0 +" || true # generate and open report output grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/ -open ./target/debug/coverage/index.html + +LOCATION="coverage HTML file at $(pwd)/target/debug/coverage/index.html" +echo "$LOCATION" From 7d14cb94cac0e3b06a5ebad96e05f244c359e9f1 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Thu, 19 May 2022 17:47:18 +0000 Subject: [PATCH 4/6] how to use code coverage --- server/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/README.md b/server/README.md index af1002d48..a097c8a6d 100644 --- a/server/README.md +++ b/server/README.md @@ -136,3 +136,9 @@ The easiest way to get these tests to pass is to: Alternatively, if you're only interested in running unit tests, you can just run `cargo test --lib`. These tests don't make any assumptions about the surrounding environment. To run only a specific test (e.g. only the application tests), you can use the `--test` flag to `cargo test` which supports common Unix glob patterns. For example: `cargo test --test '*app*'`. + +# Code Coverage +To get a code coverage report, first make sure you have the following installations: +- `cargo install grcov` +- `rustup component add llvm-tools-preview` +Then, run `./run-tests-with-grcov.sh`, which is a wrapper around `./run-tests.sh` that includes code coverage evaluation and report generation using `grcov`. When it finishes, it will print the location of the report HTML file to your shell. From 2ce88c8a78a9859fb306e1097c2b855883cf1ccc Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Thu, 19 May 2022 18:14:21 +0000 Subject: [PATCH 5/6] escape strings --- server/run-tests-with-grcov.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/run-tests-with-grcov.sh b/server/run-tests-with-grcov.sh index 8602a01fc..13dd81711 100755 --- a/server/run-tests-with-grcov.sh +++ b/server/run-tests-with-grcov.sh @@ -3,9 +3,9 @@ # cleanly run the following commands in their own session bash -c " # tell Rust to run with coverage instrumentation -RUSTFLAGS="-Cinstrument-coverage" +RUSTFLAGS=\"-Cinstrument-coverage\" # give grcov a profile name template for output files -LLVM_PROFILE_FILE="svix-webhooks-%p-%m.profraw" +LLVM_PROFILE_FILE=\"svix-webhooks-%p-%m.profraw\" # put the compiler in nightly mode RUSTC_BOOTSTRAP=1 From e31fe11ba4d12b136099cc4f9d032652b3091406 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Thu, 19 May 2022 18:34:30 +0000 Subject: [PATCH 6/6] simplify location echo --- server/run-tests-with-grcov.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/run-tests-with-grcov.sh b/server/run-tests-with-grcov.sh index 13dd81711..fd1574c40 100755 --- a/server/run-tests-with-grcov.sh +++ b/server/run-tests-with-grcov.sh @@ -16,5 +16,4 @@ RUSTC_BOOTSTRAP=1 # generate and open report output grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/ -LOCATION="coverage HTML file at $(pwd)/target/debug/coverage/index.html" -echo "$LOCATION" +echo "coverage HTML file at $(pwd)/target/debug/coverage/index.html"