From baab6569c2f5b83790285a4743eaca76b7ef12cc Mon Sep 17 00:00:00 2001 From: MLopez-Ibanez <2620021+MLopez-Ibanez@users.noreply.github.com> Date: Mon, 1 Dec 2025 11:22:55 +0000 Subject: [PATCH 1/4] Run coverage with DEBUG=1 and exclude unreachable lines. * .github/workflows/R.yml: Run coverage with DEBUG=1. * c/: Exclude unreachable lines. * python/pyproject.toml [tool.coverage.report]: Exclude nocov lines. * python/tox.ini (.pkg-cov): Set MOOCORE_DEBUG=1. --- .github/workflows/R.yml | 1 + c/cmdline.h | 2 +- c/gcc_attribs.h | 12 ++++++------ c/hv4d_priv.h | 4 ++-- c/hvapprox.c | 2 +- c/main-hvapprox.c | 2 +- c/nondominated.h | 4 ++-- c/pow_int.h | 4 ++-- python/pyproject.toml | 5 +++++ python/tox.ini | 3 ++- 10 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.github/workflows/R.yml b/.github/workflows/R.yml index faeb3cdd..50e1a1bf 100644 --- a/.github/workflows/R.yml +++ b/.github/workflows/R.yml @@ -162,6 +162,7 @@ jobs: env: NOT_CRAN: false run: | + options(covr.flags=c(DEBUG="1")) coverage <- covr::package_coverage(type="all", quiet=FALSE, clean = FALSE, commentDonttest = FALSE, commentDontrun = FALSE, flags="R", install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")) diff --git a/c/cmdline.h b/c/cmdline.h index 0a1ab5e2..79bac619 100644 --- a/c/cmdline.h +++ b/c/cmdline.h @@ -270,7 +270,7 @@ static inline void default_cmdline_handler(int opt) usage(); exit(EXIT_SUCCESS); default: - unreachable(); + unreachable(); // COVR_EXCL_LINE # nocov } } diff --git a/c/gcc_attribs.h b/c/gcc_attribs.h index 908522e2..87249081 100644 --- a/c/gcc_attribs.h +++ b/c/gcc_attribs.h @@ -121,14 +121,14 @@ #if (defined(__GNUC__) && __GNUC__ >= 3) || defined(__clang__) -# define likely(x) __builtin_expect(!!(x), 1) -# define unlikely(x) __builtin_expect(!!(x), 0) +# define likely(x) __builtin_expect(!!(x), 1) +# define unlikely(x) __builtin_expect(!!(x), 0) #elif (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) -# define likely(x) (x) [[likely]] -# define unlikely(x) (x) [[unlikely]] +# define likely(x) (x) [[likely]] +# define unlikely(x) (x) [[unlikely]] #else -# define likely(x) (x) -# define unlikely(x) (x) +# define likely(x) (x) +# define unlikely(x) (x) #endif #ifdef _MSC_VER diff --git a/c/hv4d_priv.h b/c/hv4d_priv.h index 0adaddfc..7150d90f 100644 --- a/c/hv4d_priv.h +++ b/c/hv4d_priv.h @@ -156,7 +156,7 @@ restart_base_setup_z_and_closest(dlnode_t * restrict list, dlnode_t * restrict n } p = p->next[0]; } - unreachable(); + unreachable(); // COVR_EXCL_LINE # nocov } // FIXME: This is very similar to the loop in hvc3d_list() but it doesn't use p->last_slice_z @@ -211,7 +211,7 @@ one_contribution_3d(dlnode_t * restrict newp) lastz = px[2]; p = p->next[0]; } - unreachable(); + unreachable(); // COVR_EXCL_LINE # nocov } /* Compute the hypervolume indicator in d=4 by iteratively computing the one diff --git a/c/hvapprox.c b/c/hvapprox.c index d42c443c..9755a4e3 100644 --- a/c/hvapprox.c +++ b/c/hvapprox.c @@ -434,7 +434,7 @@ int_of_power_of_sin_from_0_to_b(dimension_t m, double b) return 0.13994993409141898*b - cos_b*sin_b*( 0.03125*POW(sin_b, 30) + 31/960.*POW(sin_b, 28) + 899/26880.*POW(sin_b, 26) + 8091/232960.*POW(sin_b, 24) + 13485/372736.*POW(sin_b, 22) + 310155/8200192.*POW(sin_b, 20) + 186093/4685824.*POW(sin_b, 18) + 392863/9371648.*POW(sin_b, 16) + 6678671/149946368.*POW(sin_b, 14) + 100180065/2099249152.*POW(sin_b, 12) + 33393355/645922816.*POW(sin_b, 10) + 6678671/117440512.*POW(sin_b, 8) + 60108039/939524096.*POW(sin_b, 6) + 0.07463996484875679*POW(sin_b, 4) + 0.093299956060945988*POW(sin_b, 2) + 0.13994993409141898); default: - unreachable(); + unreachable(); // COVR_EXCL_LINE # nocov } #undef POW } diff --git a/c/main-hvapprox.c b/c/main-hvapprox.c index f40ca597..639b092d 100644 --- a/c/main-hvapprox.c +++ b/c/main-hvapprox.c @@ -173,7 +173,7 @@ hvapprox_file (const char *filename, double *reference, volume = hv_approx_hua_wang(&data[nobj * cumsize], nobj, cumsizes[n] - cumsize, reference, maximise, nsamples); break; default: - unreachable(); + unreachable(); // COVR_EXCL_LINE # nocov } if (volume == 0.0) { diff --git a/c/nondominated.h b/c/nondominated.h index ba3d4020..bf07dadb 100644 --- a/c/nondominated.h +++ b/c/nondominated.h @@ -474,7 +474,7 @@ find_dominated_point_(const double * restrict points, dimension_t dim, size_t si return find_dominated_point_agree_( points, dim, size, keep_weakly, AGREE_MAXIMISE, /*minmax=*/NULL); default: - unreachable(); + unreachable(); // # nocov } } @@ -525,7 +525,7 @@ find_nondominated_set_(const double * restrict points, dimension_t dim, size_t s return find_nondominated_set_agree_( points, dim, size, nondom, keep_weakly, AGREE_MAXIMISE, /*minmax=*/NULL); default: - unreachable(); + unreachable(); // # nocov } } diff --git a/c/pow_int.h b/c/pow_int.h index 9e252538..1c8e3396 100644 --- a/c/pow_int.h +++ b/c/pow_int.h @@ -42,7 +42,7 @@ fast_pow_uint_max32(double base, uint_fast8_t exp) case 30: { b15 = fast_pow_uint_max32(base, 15); return b15 * b15; } case 31: { b15 = fast_pow_uint_max32(base, 15); return b15 * b15 * base; } case 32: { b16 = fast_pow_uint_max32(base, 16); return b16 * b16; } - default: unreachable(); + default: unreachable(); // COVR_EXCL_LINE # nocov } } @@ -103,7 +103,7 @@ fast_powl_uint_max32(long double base, uint_fast8_t exp) case 30: { b15 = fast_powl_uint_max32(base, 15); return b15 * b15; } case 31: { b15 = fast_powl_uint_max32(base, 15); return b15 * b15 * base; } case 32: { b16 = fast_powl_uint_max32(base, 16); return b16 * b16; } - default: unreachable(); + default: unreachable(); // COVR_EXCL_LINE # nocov } } diff --git a/python/pyproject.toml b/python/pyproject.toml index 2c2f0132..28f7174d 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -192,6 +192,11 @@ faulthandler_timeout = 10 doctest_optionflags = "NUMBER" addopts = [ "--import-mode=importlib", "--durations=5", "--durations-min=1.0" ] +[tool.coverage.report] +exclude_also = [ + '# nocov', +] + [tool.mypy] python_version = "3.11" # Strictness (recommended for library code) diff --git a/python/tox.ini b/python/tox.ini index 9fca1910..4c7b4e30 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -35,7 +35,7 @@ commands = coverage run --source={envsitepackagesdir}/moocore,tests -m pytest --doctest-modules --import-mode=importlib {envsitepackagesdir}/moocore tests coverage report -m coverage xml - gcovr --print-summary --delete -r {toxinidir} {toxinidir} --xml=c_coverage.xml --exclude '.*/moocore\._libmoocore.c' --fail-under-line 1 + gcovr --exclude-unreachable-branches --print-summary --delete -r {toxinidir} {toxinidir} --xml=c_coverage.xml --exclude '.*/moocore\._libmoocore.c' --fail-under-line 1 [testenv:docs] description = Build documentation @@ -55,6 +55,7 @@ passenv = MOOCORE_DEBUG setenv = .pkg-cov: CFLAGS={env:CFLAGS:--coverage -UNDEBUG -DDEBUG=1} .pkg-cov: LDFLAGS=--coverage + .pkg-cov: MOOCORE_DEBUG=1 .pkg-release: MOOCORE_DEBUG=0 .pkg-debug: MOOCORE_DEBUG=1 From 2d88f983a80e5fb25862d9718d55ecc4c5439497 Mon Sep 17 00:00:00 2001 From: MLopez-Ibanez <2620021+MLopez-Ibanez@users.noreply.github.com> Date: Mon, 1 Dec 2025 16:33:23 +0000 Subject: [PATCH 2/4] r/src/Makevars: Use MOOCORE_DEBUG isntead of DEBUG. --- .github/workflows/R.yml | 5 +++-- r/Makefile | 2 +- r/src/Makevars | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/R.yml b/.github/workflows/R.yml index 50e1a1bf..cc04e5a0 100644 --- a/.github/workflows/R.yml +++ b/.github/workflows/R.yml @@ -162,10 +162,11 @@ jobs: env: NOT_CRAN: false run: | - options(covr.flags=c(DEBUG="1")) - coverage <- covr::package_coverage(type="all", quiet=FALSE, clean = FALSE, + coverage <- withr::with_makevars(c(MOOCORE_DEBUG="1"), + covr::package_coverage(type="all", quiet=FALSE, clean = FALSE, commentDonttest = FALSE, commentDontrun = FALSE, flags="R", install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")) + ) print(coverage) covr::to_cobertura(coverage) list.files("../", pattern="*.xml", recursive=TRUE) diff --git a/r/Makefile b/r/Makefile index 7b6799c3..5bfdbf1d 100644 --- a/r/Makefile +++ b/r/Makefile @@ -89,7 +89,7 @@ check: build ifdef TEST _R_CHECK_FORCE_SUGGESTS_=false NOT_CRAN=true $(Reval) 'devtools::test(filter="$(TEST)")' else - cd $(BINDIR) && (_R_CHECK_FORCE_SUGGESTS_=false NOT_CRAN=true DEBUG=1 R CMD check --run-donttest --run-dontrun --timings $(PACKAGE)_$(PACKAGEVERSION).tar.gz; cat $(PACKAGE).Rcheck/$(PACKAGE)-Ex.timings) + cd $(BINDIR) && (_R_CHECK_FORCE_SUGGESTS_=false NOT_CRAN=true MOOCORE_DEBUG=1 R CMD check --run-donttest --run-dontrun --timings $(PACKAGE)_$(PACKAGEVERSION).tar.gz; cat $(PACKAGE).Rcheck/$(PACKAGE)-Ex.timings) endif show: diff --git a/r/src/Makevars b/r/src/Makevars index 62367473..a8acfdf0 100644 --- a/r/src/Makevars +++ b/r/src/Makevars @@ -4,8 +4,8 @@ # In particular, add the following to ~/.R/Makevars: # LTO_OPT=-flto LTO=$(LTO_OPT) -DEBUG=0 -PKG_CPPFLAGS=-DR_PACKAGE -DDEBUG=$(DEBUG) -I./libmoocore/ +MOOCORE_DEBUG?=0 +PKG_CPPFLAGS=-DR_PACKAGE -DDEBUG=$(MOOCORE_DEBUG) -I./libmoocore/ MOOCORE_SRC_FILES = hv3dplus.c hv4d.c hv_contrib.c hv.c hvapprox.c hvc3d.c pareto.c whv.c whv_hype.c avl.c eaf3d.c eaf.c io.c rng.c mt19937/mt19937.c SOURCES = $(MOOCORE_SRC_FILES:%=libmoocore/%) init.c Rmoocore.c @@ -19,7 +19,7 @@ all: exes $(SHLIB) $(SHLIB): $(OBJECTS) exes: $(SHLIB) - $(MAKE) -C libmoocore all march=none CC="$(CC)" CFLAGS="$(CFLAGS)" WARN_CFLAGS="" OPT_CFLAGS="" DEBUG=$(DEBUG) EXE=$(EXEEXT) BINDIR=$(PWD) + $(MAKE) -C libmoocore all march=none CC="$(CC)" CFLAGS="$(CFLAGS)" WARN_CFLAGS="" OPT_CFLAGS="" DEBUG=$(MOOCORE_DEBUG) EXE=$(EXEEXT) BINDIR=$(PWD) @-$(RM) libmoocore/*.o clean: From c20e31f7a8e03ba1d036901dfae18a17b97c6cdc Mon Sep 17 00:00:00 2001 From: MLopez-Ibanez <2620021+MLopez-Ibanez@users.noreply.github.com> Date: Mon, 1 Dec 2025 16:46:06 +0000 Subject: [PATCH 3/4] r/ Disable LTO when running coverage. --- .github/workflows/R.yml | 2 +- c/Makefile | 2 +- r/Makefile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/R.yml b/.github/workflows/R.yml index cc04e5a0..29d4d2fe 100644 --- a/.github/workflows/R.yml +++ b/.github/workflows/R.yml @@ -162,7 +162,7 @@ jobs: env: NOT_CRAN: false run: | - coverage <- withr::with_makevars(c(MOOCORE_DEBUG="1"), + coverage <- withr::with_makevars(c(MOOCORE_DEBUG="1", LTO_OPT=""), covr::package_coverage(type="all", quiet=FALSE, clean = FALSE, commentDonttest = FALSE, commentDontrun = FALSE, flags="R", install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")) diff --git a/c/Makefile b/c/Makefile index a6989410..a7b2c29a 100644 --- a/c/Makefile +++ b/c/Makefile @@ -226,7 +226,7 @@ $(CXXSHLIB): $(LIBHV_OBJS) $(CXX) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ $(SHLIB_LDFLAGS) clean: - @-$(RM) *.s *.i + @-$(RM) *.s *.i *.gcda mt19937/*.gcda @-$(RM) config.status config.log @-$(RM) Hypervolume_MEX.mex @-$(RM) $(SHLIB) $(CXXSHLIB) diff --git a/r/Makefile b/r/Makefile index 5bfdbf1d..9e5328ea 100644 --- a/r/Makefile +++ b/r/Makefile @@ -112,7 +112,7 @@ winbuild winbuild_: $(Reval) "devtools::check_win_devel()" covr: - $(Reval) "Sys.setenv(NOT_CRAN='true');covr::report(covr::package_coverage(type='all', quiet=FALSE), browse=TRUE)" + $(Reval) "Sys.setenv(NOT_CRAN='true');covr::report(withr::with_makevars(c(MOOCORE_DEBUG='1', LTO_OPT=''), covr::package_coverage(type='all', commentDonttest=FALSE, commentDontrun=FALSE, quiet=FALSE)), browse=TRUE)" benchmarks: quick-install $(RM) ./vignettes/articles/bench/*.rds From 8bc8fa5b842d37b9f52710506a3c487e346d97d0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Dec 2025 17:02:02 +0000 Subject: [PATCH 4/4] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/tox-dev/pyproject-fmt: v2.11.0 → v2.11.1](https://github.com/tox-dev/pyproject-fmt/compare/v2.11.0...v2.11.1) - [github.com/astral-sh/ruff-pre-commit: v0.14.3 → v0.14.7](https://github.com/astral-sh/ruff-pre-commit/compare/v0.14.3...v0.14.7) - [github.com/sphinx-contrib/sphinx-lint: v1.0.1 → v1.0.2](https://github.com/sphinx-contrib/sphinx-lint/compare/v1.0.1...v1.0.2) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0dbc5ae0..ee6c2983 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,14 +49,14 @@ repos: - id: tox-ini-fmt - repo: https://github.com/tox-dev/pyproject-fmt - rev: "v2.11.0" + rev: "v2.11.1" hooks: - id: pyproject-fmt additional_dependencies: ["tox>=4.12.1"] - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.14.3 + rev: v0.14.7 hooks: # Run the formatter. - id: ruff-format @@ -68,6 +68,6 @@ repos: require_serial: true - repo: https://github.com/sphinx-contrib/sphinx-lint - rev: v1.0.1 + rev: v1.0.2 hooks: - id: sphinx-lint