message: [easy] Maintain the code coverage script
  adapt ignore option
  early fail in case of inexistant to-be-tested dir
  ask for nightly to be compatible with RUSTFLAGS
  shellcheck and formatting
  Closes:
  Approved by: davidiw
diff: #!/bin/bash
  # Check that the test directory and report path arguments are provided
  -if [ $# -lt 2 ]
  +if [ $# -lt 2 ] || ! [ -d "$1" ]
  then
  echo "Usage: $0 <testdir> <outdir> [--batch]"
  echo "All tests in <testdir> and its subdirectories will be run to measure coverage."
  @@ -12,7 +12,7 @@ fi
  # User prompts will be skipped if '--batch' is given as the third argument
  SKIP_PROMPTS=0
  -if [ $# -eq 3 -a "$3" == "--batch" ]
  +if [ $# -eq 3 ] && [ "$3" == "--batch" ]
  then
  SKIP_PROMPTS=1
  fi
  @@ -25,7 +25,7 @@ COVERAGE_DIR=$2
  # This needs to run in libra
  LIBRA_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd)"
  -if [ $(pwd) != $LIBRA_DIR ]
  +if [ "$(pwd)" != "$LIBRA_DIR" ]
  then
  echo "Error: This needs to run from libra/, not in $(pwd)" >&2
  exit 1
  @@ -70,32 +70,32 @@ then
  fi
  # Set the flags necessary for coverage output
  -export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Coverflow-checks=off -Zno-landing-pads"
  +export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Coverflow-checks=off -Zno-landing-pads -Cpasses=insert-gcov-profiling"
  export CARGO_INCREMENTAL=0
  # Clean the project
  echo "Cleaning project..."
  -(cd $TEST_DIR; cargo clean)
  +(cd "$TEST_DIR"; cargo +nightly clean)
  # Run tests
  echo "Running tests..."
  -while read line; do
  - dirline=$(realpath $(dirname $line));
  - (cd $dirline; cargo test)
  -done < <(find $TEST_DIR -name 'Cargo.toml')
  +while read -r line; do
  + dirline=$(realpath $(dirname "$line"));
  + (cd "$dirline"; cargo test)
  +done < <(find "$TEST_DIR" -name 'Cargo.toml')
  # Make the coverage directory if it doesn't exist
  -if [ ! -d $COVERAGE_DIR ]; then
  - mkdir $COVERAGE_DIR;
  +if [ ! -d "$COVERAGE_DIR" ]; then
  + mkdir "$COVERAGE_DIR";
  fi
  # Generate lcov report
  echo "Generating lcov report at ${COVERAGE_DIR}/lcov.info..."
  -grcov target -t lcov --llvm --branch --ignore-dir "/*" -o $COVERAGE_DIR/lcov.info
  +grcov target -t lcov --llvm --branch --ignore "/*" -o "$COVERAGE_DIR/lcov.info"
  # Generate HTML report
  echo "Generating report at ${COVERAGE_DIR}..."
  # Flag "--ignore-errors source" ignores missing source files
  -genhtml -o $COVERAGE_DIR --show-details --highlight --ignore-errors source --legend $COVERAGE_DIR/lcov.info
  +genhtml -o "$COVERAGE_DIR" --show-details --highlight --ignore-errors source --legend "$COVERAGE_DIR/lcov.info"
  echo "Done. Please view report at ${COVERAGE_DIR}/index.html"
  