mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
maint/dev ~ improve code coverage scripting
This commit is contained in:
parent
9711e5ad42
commit
ec964d1b36
6 changed files with 147 additions and 93 deletions
59
util/build-code_coverage.BAT
Normal file
59
util/build-code_coverage.BAT
Normal file
|
@ -0,0 +1,59 @@
|
|||
@setLocal
|
||||
@echo off
|
||||
set "ERRORLEVEL="
|
||||
|
||||
@rem ::# spell-checker:ignore (abbrevs/acronyms) gcno
|
||||
@rem ::# spell-checker:ignore (CMD) COMSPEC ERRORLEVEL
|
||||
@rem ::# spell-checker:ignore (jargon) toolchain
|
||||
@rem ::# spell-checker:ignore (rust) Ccodegen Cinline Coverflow Cpanic RUSTC RUSTDOCFLAGS RUSTFLAGS RUSTUP Zpanic
|
||||
@rem ::# spell-checker:ignore (utils) genhtml grcov lcov sccache uutils
|
||||
|
||||
@rem ::# ref: https://github.com/uutils/coreutils/pull/1476
|
||||
|
||||
set "FEATURES_OPTION=--features feat_os_windows"
|
||||
|
||||
cd "%~dp0.."
|
||||
call echo [ "%CD%" ]
|
||||
|
||||
for /f "tokens=*" %%G in ('%~dp0\show-utils.BAT %FEATURES_OPTION%') do set UTIL_LIST=%%G
|
||||
REM echo UTIL_LIST=%UTIL_LIST%
|
||||
set "CARGO_INDIVIDUAL_PACKAGE_OPTIONS="
|
||||
for %%H in (%UTIL_LIST%) do (
|
||||
if DEFINED CARGO_INDIVIDUAL_PACKAGE_OPTIONS call set "CARGO_INDIVIDUAL_PACKAGE_OPTIONS=%%CARGO_INDIVIDUAL_PACKAGE_OPTIONS%% "
|
||||
call set "CARGO_INDIVIDUAL_PACKAGE_OPTIONS=%%CARGO_INDIVIDUAL_PACKAGE_OPTIONS%%-puu_%%H"
|
||||
)
|
||||
REM echo CARGO_INDIVIDUAL_PACKAGE_OPTIONS=%CARGO_INDIVIDUAL_PACKAGE_OPTIONS%
|
||||
|
||||
REM call cargo clean
|
||||
|
||||
set "CARGO_INCREMENTAL=0"
|
||||
set "RUSTC_WRAPPER=" &@REM ## NOTE: RUSTC_WRAPPER=='sccache' breaks code coverage calculations (uu_*.gcno files are not created during build)
|
||||
@REM set "RUSTFLAGS=-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zno-landing-pads"
|
||||
set "RUSTFLAGS=-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
|
||||
set "RUSTDOCFLAGS=-Cpanic=abort"
|
||||
set "RUSTUP_TOOLCHAIN=nightly-gnu"
|
||||
call cargo build %FEATURES_OPTION%
|
||||
call cargo test --no-run %FEATURES_OPTION%
|
||||
call cargo test --quiet %FEATURES_OPTION%
|
||||
call cargo test --quiet %FEATURES_OPTION% %CARGO_INDIVIDUAL_PACKAGE_OPTIONS%
|
||||
|
||||
if NOT DEFINED COVERAGE_REPORT_DIR set COVERAGE_REPORT_DIR=target\debug\coverage-win
|
||||
call rm -r "%COVERAGE_REPORT_DIR%" 2>NUL
|
||||
|
||||
set GRCOV_IGNORE_OPTION=--ignore build.rs --ignore "/*" --ignore "[A-Za-z]:/*" --ignore "C:/Users/*"
|
||||
set GRCOV_EXCLUDE_OPTION=--excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()"
|
||||
@rem ::# * build LCOV coverage file
|
||||
REM echo call grcov . --output-type lcov --output-path "%COVERAGE_REPORT_DIR%/../lcov.info" --branch %GRCOV_IGNORE_OPTION% %GRCOV_EXCLUDE_OPTION%
|
||||
call grcov . --output-type lcov --output-path "%COVERAGE_REPORT_DIR%/../lcov.info" --branch %GRCOV_IGNORE_OPTION% %GRCOV_EXCLUDE_OPTION%
|
||||
@rem ::# * build HTML
|
||||
@rem ::# -- use `genhtml` if available for display of additional branch coverage information
|
||||
set "ERRORLEVEL="
|
||||
call genhtml --version 2>NUL 1>&2
|
||||
if NOT ERRORLEVEL 1 (
|
||||
echo call genhtml target/debug/lcov.info --prefix "%CD%" --output-directory "%COVERAGE_REPORT_DIR%" --branch-coverage --function-coverage ^| grep ": [0-9]"
|
||||
call genhtml target/debug/lcov.info --prefix "%CD%" --output-directory "%COVERAGE_REPORT_DIR%" --branch-coverage --function-coverage | grep ": [0-9]"
|
||||
) else (
|
||||
echo call grcov . --output-type html --output-path "%COVERAGE_REPORT_DIR%" --branch %GRCOV_IGNORE_OPTION%
|
||||
call grcov . --output-type html --output-path "%COVERAGE_REPORT_DIR%" --branch %GRCOV_IGNORE_OPTION%
|
||||
)
|
||||
if ERRORLEVEL 1 goto _undefined_ 2>NUL || @for %%G in ("%COMSPEC%") do @title %%nG & @"%COMSPEC%" /d/c exit %ERRORLEVEL%
|
56
util/build-code_coverage.sh
Normal file
56
util/build-code_coverage.sh
Normal file
|
@ -0,0 +1,56 @@
|
|||
#!/bin/sh
|
||||
|
||||
# spell-checker:ignore (abbrevs/acronyms) HTML gcno llvm
|
||||
# spell-checker:ignore (jargon) toolchain
|
||||
# spell-checker:ignore (rust) Ccodegen Cinline Coverflow Cpanic RUSTC RUSTDOCFLAGS RUSTFLAGS RUSTUP Zpanic
|
||||
# spell-checker:ignore (shell) OSID esac
|
||||
# spell-checker:ignore (utils) genhtml grcov lcov readlink sccache uutils
|
||||
|
||||
FEATURES_OPTION="--features feat_os_unix"
|
||||
|
||||
ME_dir="$(dirname -- $(readlink -fm -- "$0"))"
|
||||
REPO_main_dir="$(dirname -- "${ME_dir}")"
|
||||
|
||||
cd "${REPO_main_dir}"
|
||||
echo "[ \"$PWD\" ]"
|
||||
|
||||
UTIL_LIST=$("${ME_dir}"/show-utils.sh ${FEATURES_OPTION})
|
||||
CARGO_INDIVIDUAL_PACKAGE_OPTIONS=""
|
||||
for UTIL in ${UTIL_LIST}; do
|
||||
if [ -n "${CARGO_INDIVIDUAL_PACKAGE_OPTIONS}" ]; then CARGO_INDIVIDUAL_PACKAGE_OPTIONS="${CARGO_INDIVIDUAL_PACKAGE_OPTIONS} "; fi
|
||||
CARGO_INDIVIDUAL_PACKAGE_OPTIONS="${CARGO_INDIVIDUAL_PACKAGE_OPTIONS}-puu_${UTIL}"
|
||||
done
|
||||
# echo "CARGO_INDIVIDUAL_PACKAGE_OPTIONS=${CARGO_INDIVIDUAL_PACKAGE_OPTIONS}"
|
||||
|
||||
# cargo clean
|
||||
|
||||
export CARGO_INCREMENTAL=0
|
||||
export RUSTC_WRAPPER="" ## NOTE: RUSTC_WRAPPER=='sccache' breaks code coverage calculations (uu_*.gcno files are not created during build)
|
||||
# export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zno-landing-pads"
|
||||
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
|
||||
export RUSTDOCFLAGS="-Cpanic=abort"
|
||||
export RUSTUP_TOOLCHAIN="nightly-gnu"
|
||||
cargo build ${FEATURES_OPTION}
|
||||
cargo test --no-run ${FEATURES_OPTION}
|
||||
cargo test --quiet ${FEATURES_OPTION}
|
||||
cargo test --quiet ${FEATURES_OPTION} ${CARGO_INDIVIDUAL_PACKAGE_OPTIONS}
|
||||
|
||||
export COVERAGE_REPORT_DIR
|
||||
if [ -z "${COVERAGE_REPORT_DIR}" ]; then COVERAGE_REPORT_DIR="${REPO_main_dir}/target/debug/coverage-nix"; fi
|
||||
rm -r "${COVERAGE_REPORT_DIR}" 2>/dev/null
|
||||
mkdir -p "${COVERAGE_REPORT_DIR}"
|
||||
|
||||
## NOTE: `grcov` is not accepting environment variable contents as options for `--ignore` or `--excl_br_line`
|
||||
# export GRCOV_IGNORE_OPTION="--ignore build.rs --ignore '/*' --ignore '[A-Za-z]:/*' --ignore 'C:/Users/*'"
|
||||
# export GRCOV_EXCLUDE_OPTION="--excl-br-line '^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()'"
|
||||
# * build LCOV coverage file
|
||||
grcov . --output-type lcov --output-path "${COVERAGE_REPORT_DIR}/../lcov.info" --branch --ignore build.rs --ignore '/*' --ignore '[A-Za-z]:/*' --ignore 'C:/Users/*' --excl-br-line '^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()'
|
||||
# * build HTML
|
||||
# -- use `genhtml` if available for display of additional branch coverage information
|
||||
genhtml --version 2>/dev/null 1>&2
|
||||
if [ $? -eq 0 ]; then
|
||||
genhtml "${COVERAGE_REPORT_DIR}/../lcov.info" --output-directory "${COVERAGE_REPORT_DIR}" --branch-coverage --function-coverage | grep ": [0-9]"
|
||||
else
|
||||
grcov . --output-type html --output-path "${COVERAGE_REPORT_DIR}" --branch --ignore build.rs --ignore '/*' --ignore '[A-Za-z]:/*' --ignore 'C:/Users/*' --excl-br-line '^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()'
|
||||
fi
|
||||
if [ $? -ne 0 ]; then exit 1 ; fi
|
16
util/show-code_coverage.BAT
Normal file
16
util/show-code_coverage.BAT
Normal file
|
@ -0,0 +1,16 @@
|
|||
@setLocal
|
||||
@echo off
|
||||
|
||||
@rem:: # spell-checker:ignore (shell/CMD) COMSPEC ERRORLEVEL
|
||||
|
||||
set "ME_dir=%~dp0."
|
||||
set "REPO_main_dir=%ME_dir%\.."
|
||||
|
||||
set "ERRORLEVEL="
|
||||
set "COVERAGE_REPORT_DIR=%REPO_main_dir%\target\debug\coverage-win"
|
||||
|
||||
call "%ME_dir%\build-code_coverage.BAT"
|
||||
if ERRORLEVEL 1 goto _undefined_ 2>NUL || @for %%G in ("%COMSPEC%") do @title %%nG & @"%COMSPEC%" /d/c exit %ERRORLEVEL%
|
||||
|
||||
call start "" "%COVERAGE_REPORT_DIR%"\index.html
|
||||
if ERRORLEVEL 1 goto _undefined_ 2>NUL || @for %%G in ("%COMSPEC%") do @title %%nG & @"%COMSPEC%" /d/c exit %ERRORLEVEL%
|
16
util/show-code_coverage.sh
Normal file
16
util/show-code_coverage.sh
Normal file
|
@ -0,0 +1,16 @@
|
|||
#!/bin/sh
|
||||
|
||||
# spell-checker:ignore (vars) OSID
|
||||
|
||||
ME_dir="$(dirname -- $(readlink -fm -- "$0"))"
|
||||
REPO_main_dir="$(dirname -- "${ME_dir}")"
|
||||
|
||||
export COVERAGE_REPORT_DIR="${REPO_main_dir}/target/debug/coverage-nix"
|
||||
|
||||
"${ME_dir}/build-code_coverage.sh"
|
||||
if [ $? -ne 0 ]; then exit 1 ; fi
|
||||
|
||||
case ";$OSID_tags;" in
|
||||
*";wsl;"* ) powershell.exe -c $(wslpath -w "${COVERAGE_REPORT_DIR}"/index.html) ;;
|
||||
* ) xdg-open --version >/dev/null 2>&1 && xdg-open "${COVERAGE_REPORT_DIR}"/index.html || echo "report available at '\"${COVERAGE_REPORT_DIR}\"/index.html'" ;;
|
||||
esac ;
|
|
@ -1,43 +0,0 @@
|
|||
@setLocal
|
||||
@echo off
|
||||
|
||||
@rem ::# spell-checker:ignore (abbrevs/acronyms) gcno
|
||||
@rem ::# spell-checker:ignore (CMD) COMSPEC ERRORLEVEL
|
||||
@rem ::# spell-checker:ignore (jargon) toolchain
|
||||
@rem ::# spell-checker:ignore (rust) Ccodegen Cinline Coverflow RUSTC RUSTFLAGS RUSTUP
|
||||
@rem ::# spell-checker:ignore (utils) genhtml grcov lcov sccache uutils
|
||||
|
||||
set BIN=uutils
|
||||
|
||||
set "FEATURES_OPTION=--features windows"
|
||||
|
||||
cd "%~dp0.."
|
||||
call echo [ "%CD%" ]
|
||||
|
||||
call cargo clean
|
||||
|
||||
set CARGO_INCREMENTAL=0
|
||||
set "RUSTC_WRAPPER=" &@REM ## NOTE: RUSTC_WRAPPER=='sccache' breaks code coverage calculations (uu_*.gcno files are not created during build)
|
||||
set "RUSTFLAGS=-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zno-landing-pads"
|
||||
set RUSTUP_TOOLCHAIN=nightly-x86_64-pc-windows-gnu
|
||||
call cargo build %FEATURES_OPTION%
|
||||
call cargo test --no-run %FEATURES_OPTION%
|
||||
call cargo test --quiet %FEATURES_OPTION%
|
||||
|
||||
set COVERAGE_REPORT_DIR=target\debug\coverage-win
|
||||
call rm -r "%COVERAGE_REPORT_DIR%" 2>NUL
|
||||
|
||||
set GRCOV_IGNORE_OPTION=--ignore build.rs --ignore "/*" --ignore "[A-Za-z]:/*"
|
||||
@rem ::# * build LCOV coverage file
|
||||
call grcov . --output-type lcov --output-path "%COVERAGE_REPORT_DIR%/../lcov.info" --branch %GRCOV_IGNORE_OPTION%
|
||||
@rem ::# * build HTML
|
||||
@rem ::# -- use `genhtml` if available for display of additional branch coverage information
|
||||
call genhtml --version 2>NUL 1>&2
|
||||
if NOT ERRORLEVEL 1 (
|
||||
call genhtml target/debug/lcov.info --output-directory "%COVERAGE_REPORT_DIR%" --branch-coverage --function-coverage
|
||||
) else (
|
||||
call grcov . --output-type html --output-path "%COVERAGE_REPORT_DIR%" --branch %GRCOV_IGNORE_OPTION%
|
||||
)
|
||||
if ERRORLEVEL 1 goto _undefined_ 2>NUL || @for %%G in ("%COMSPEC%") do @title %%nG & @"%COMSPEC%" /d/c exit %ERRORLEVEL%
|
||||
|
||||
call start "" "%COVERAGE_REPORT_DIR%"\index.html
|
|
@ -1,50 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# spell-checker:ignore (abbrevs/acronyms) HTML gcno llvm
|
||||
# spell-checker:ignore (jargon) toolchain
|
||||
# spell-checker:ignore (rust) Ccodegen Cinline Coverflow RUSTC RUSTFLAGS RUSTUP
|
||||
# spell-checker:ignore (shell) OSID esac
|
||||
# spell-checker:ignore (utils) genhtml grcov lcov readlink sccache uutils
|
||||
|
||||
BIN=uutils
|
||||
|
||||
FEATURES_OPTION="--features unix"
|
||||
|
||||
cd "$(dirname -- $(readlink -fm -- "$0"/..))"
|
||||
echo "[ \"$PWD\" ]"
|
||||
|
||||
cargo clean
|
||||
|
||||
export CARGO_INCREMENTAL=0
|
||||
export RUSTC_WRAPPER="" ## NOTE: RUSTC_WRAPPER=='sccache' breaks code coverage calculations (uu_*.gcno files are not created during build)
|
||||
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zno-landing-pads"
|
||||
export RUSTUP_TOOLCHAIN=nightly
|
||||
cargo build ${FEATURES_OPTION}
|
||||
cargo test --no-run ${FEATURES_OPTION}
|
||||
cargo test --quiet ${FEATURES_OPTION}
|
||||
|
||||
export COVERAGE_REPORT_DIR="target/debug/coverage-nix"
|
||||
rm -r "${COVERAGE_REPORT_DIR}" 2>/dev/null
|
||||
mkdir -p "${COVERAGE_REPORT_DIR}"
|
||||
|
||||
# GRCOV_IGNORE_OPTION="--ignore build.rs --ignore \"/cargo/*\" --ignore \"/rustc/*\" --ignore \"${HOME}/.cargo/*\" --ignore \"${PWD}/rustc/*\""
|
||||
export GRCOV_IGNORE_OPTION="--ignore build.rs --ignore \"/*\" --ignore \"[A-Za-z]:/*\""
|
||||
## FixME: `grcov . ... ${GRCOV_IGNORE_OPTION}` fails, completely ignoring the contents of ${GRCOV_IGNORE_OPTION}
|
||||
# * build LCOV coverage file
|
||||
## FixME: grcov . --output-type lcov --output-path "${COVERAGE_REPORT_DIR}/../lcov.info" --branch ${GRCOV_IGNORE_OPTION}
|
||||
grcov . --output-type lcov --output-path "${COVERAGE_REPORT_DIR}/../lcov.info" --branch --ignore build.rs --ignore '/*' --ignore '[A-Za-z]:/*'
|
||||
# * build HTML
|
||||
# -- use `genhtml` if available for display of additional branch coverage information
|
||||
genhtml --version 2>/dev/null 1>&2
|
||||
if [ $? -eq 0 ]; then
|
||||
genhtml "${COVERAGE_REPORT_DIR}/../lcov.info" --output-directory "${COVERAGE_REPORT_DIR}" --branch-coverage --function-coverage
|
||||
else
|
||||
## FixME: grcov . --output-type html --output-path "${COVERAGE_REPORT_DIR}" --branch ${GRCOV_IGNORE_OPTION}
|
||||
grcov . --output-type html --output-path "${COVERAGE_REPORT_DIR}" --branch --ignore build.rs --ignore '/*' --ignore '[A-Za-z]:/*'
|
||||
fi
|
||||
if [ $? -ne 0 ]; then exit 1 ; fi
|
||||
|
||||
case ";$OSID_tags;" in
|
||||
*";wsl;"* ) powershell.exe -c "${COVERAGE_REPORT_DIR}"/index.html ;;
|
||||
* ) xdg-open --version >/dev/null 2>&1 && xdg-open "${COVERAGE_REPORT_DIR}"/index.html || echo "report available at '\"${COVERAGE_REPORT_DIR}\"/index.html'" ;;
|
||||
esac ;
|
Loading…
Add table
Add a link
Reference in a new issue