From 44dc05a43c3520546084388ae2ad0b0321393b0f Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 8 May 2025 23:55:33 -0700 Subject: [PATCH 01/13] Optionally make partial coverage "uncovered" --- NEWS.md | 5 ++++ R/compiled.R | 11 ++++++-- tests/testthat/TestCompiled/R/TestCompiled.R | 4 +++ tests/testthat/TestCompiled/src/simple.cc | 7 +++++ .../tests/testthat/test-TestCompiled.R | 6 +++++ tests/testthat/test-Compiled.R | 26 +++++++++++++------ 6 files changed, 49 insertions(+), 10 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0174a7d3..f9516415 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # covr (development version) +* Support for excluding partially-covered lines in compiled code (@MichaelChirico, #604). + Use `options(covr.gcov_exclude_partial_lines = TRUE)` to require every statement on a line be + executed before the line is counted a "covered". For example, `if (verbose) Rprintf("hi\n");` + would require a test under `verbose=true` in this stricter setting. + * Messages are now displayed using cli instead of crayon (@olivroy, #591). * covr now uses `testthat::with_mocked_bindings()` for its internal testing (@olivroy, #595). diff --git a/R/compiled.R b/R/compiled.R index 65b67a40..9fa9c32f 100644 --- a/R/compiled.R +++ b/R/compiled.R @@ -16,7 +16,7 @@ parse_gcov <- function(file, package_path = "") { } re <- rex::rex(any_spaces, - capture(name = "coverage", some_of(digit, "-", "#", "=")), + capture(name = "coverage", some_of(digit, "-", "#", "="), maybe("*")), ":", any_spaces, capture(name = "line", digits), ":" @@ -29,7 +29,14 @@ parse_gcov <- function(file, package_path = "") { matches <- na.omit(matches) # gcov lines which have no coverage - matches$coverage[matches$coverage == "#####"] <- 0 # nolint + matches$coverage[matches$coverage == "#####"] <- "0" # nolint + + partial_coverage_idx <- endsWith(matches$coverage, "*") + if (isTRUE(getOption("covr.gcov_exclude_partial_lines", FALSE))) { + matches$coverage[partial_coverage_idx] <- "0" + } else { + matches$coverage[partial_coverage_idx] <- sub("[*]$", "", matches$coverage[partial_coverage_idx]) + } # gcov lines which have parse error, so make untracked matches$coverage[matches$coverage == "====="] <- "-" diff --git a/tests/testthat/TestCompiled/R/TestCompiled.R b/tests/testthat/TestCompiled/R/TestCompiled.R index 03f3d297..9c3abd9a 100644 --- a/tests/testthat/TestCompiled/R/TestCompiled.R +++ b/tests/testthat/TestCompiled/R/TestCompiled.R @@ -12,3 +12,7 @@ simple3 <- function(x) { simple4 <- function(x) { .Call(simple4_, x) # nolint } + +simple5 <- function(x) { + .Call(simple5_, x) # nolint +} diff --git a/tests/testthat/TestCompiled/src/simple.cc b/tests/testthat/TestCompiled/src/simple.cc index eca4d816..2c58878d 100644 --- a/tests/testthat/TestCompiled/src/simple.cc +++ b/tests/testthat/TestCompiled/src/simple.cc @@ -28,3 +28,10 @@ extern "C" SEXP simple_(SEXP x) { extern "C" SEXP simple3_(SEXP x) { return simple2_(x); } + +// multi-expression lines allow for partially executed blocks +extern "C" SEXP simple5_(SEXP x) { + if (REAL(x)[0] > 0) return Rf_ScalarLogical(TRUE); + if (REAL(x)[0] < 0) return NA_REAL; + return Rf_ScalarLogical(FALSE); +} diff --git a/tests/testthat/TestCompiled/tests/testthat/test-TestCompiled.R b/tests/testthat/TestCompiled/tests/testthat/test-TestCompiled.R index 22a098fc..db27b592 100644 --- a/tests/testthat/TestCompiled/tests/testthat/test-TestCompiled.R +++ b/tests/testthat/TestCompiled/tests/testthat/test-TestCompiled.R @@ -14,3 +14,9 @@ test_that("compiled function simple4 works", { expect_equal(simple4(3L), 1L) expect_equal(simple4(-1L), -1L) }) + +test_that("compiled function simple5 works", { + # positive, negative values are tested in if() conditions, + # but both evaluate to '0' --> branch code is not executed. + expect_false(simple5(0)) +}) diff --git a/tests/testthat/test-Compiled.R b/tests/testthat/test-Compiled.R index f93e7b85..41d166ea 100644 --- a/tests/testthat/test-Compiled.R +++ b/tests/testthat/test-Compiled.R @@ -6,28 +6,25 @@ test_that("Compiled code coverage is reported including code in headers", { simple_cc <- cov[cov$filename == "src/simple.cc", ] expect_equal(simple_cc[simple_cc$first_line == "10", "value"], 4) - expect_equal(simple_cc[simple_cc$first_line == "16", "value"], 3) - expect_equal(simple_cc[simple_cc$first_line == "19", "value"], 0) - expect_equal(simple_cc[simple_cc$first_line == "21", "value"], 1) - expect_equal(simple_cc[simple_cc$first_line == "23", "value"], 4) + # partial coverage counts as coverage by default + expect_equal(simple_cc[simple_cc$first_line == "34", "value"], 1) + expect_equal(simple_cc[simple_cc$first_line == "35", "value"], 1) + expect_equal(simple_cc[simple_cc$first_line == "36", "value"], 1) # This header contains a C++ template, which requires you to run gcov for # each object file separately and merge the results together. simple_h <- cov[cov$filename == "src/simple-header.h", ] expect_equal(simple_h[simple_h$first_line == "12", "value"], 4) - expect_equal(simple_h[simple_h$first_line == "18", "value"], 3) - expect_equal(simple_h[simple_h$first_line == "21", "value"], 0) - expect_equal(simple_h[simple_h$first_line == "23", "value"], 1) - expect_equal(simple_h[simple_h$first_line == "25", "value"], 4) + expect_true(all(unique(cov$filename) %in% c("R/TestCompiled.R", "src/simple-header.h", "src/simple.cc", "src/simple4.cc"))) }) @@ -106,3 +103,16 @@ test_that("tally_coverage includes compiled code", { unique(tall$filename), c("R/TestCompiled.R", "src/simple-header.h", "src/simple.cc", "src/simple4.cc")) }) + +test_that("Partial coverage can be optionally excluded", { + skip_on_cran() + skip_if(is_win_r41()) + withr::local_options(list(covr.gcov_exclude_partial_lines = TRUE)) + + cov <- as.data.frame(package_coverage("TestCompiled", relative_path = TRUE)) + + simple_cc <- cov[cov$filename == "src/simple.cc", ] + expect_equal(simple_cc[simple_cc$first_line == "34", "value"], 0) + expect_equal(simple_cc[simple_cc$first_line == "35", "value"], 0) + expect_equal(simple_cc[simple_cc$first_line == "36", "value"], 1) +}) From 9a29efdf77c3b4c2cad830af8ec3559cedca2be3 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Fri, 9 May 2025 12:34:43 -0700 Subject: [PATCH 02/13] debugging --- tests/testthat/test-Compiled.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-Compiled.R b/tests/testthat/test-Compiled.R index 41d166ea..51436a20 100644 --- a/tests/testthat/test-Compiled.R +++ b/tests/testthat/test-Compiled.R @@ -2,7 +2,7 @@ test_that("Compiled code coverage is reported including code in headers", { skip_on_cran() skip_if(is_win_r41()) - cov <- as.data.frame(package_coverage("TestCompiled", relative_path = TRUE)) + cov <- as.data.frame(package_coverage("TestCompiled", relative_path = TRUE, quiet=FALSE)) simple_cc <- cov[cov$filename == "src/simple.cc", ] expect_equal(simple_cc[simple_cc$first_line == "10", "value"], 4) @@ -31,7 +31,7 @@ test_that("Compiled code coverage is reported including code in headers", { test_that("Can pass path to relative_path argument", { skip_on_cran() skip_if(is_win_r41()) - cov <- as.data.frame(package_coverage("TestCompiled", relative_path = ".")) + cov <- as.data.frame(package_coverage("TestCompiled", relative_path = ".", quiet=FALSE)) expect_true(all(unique(cov$filename) %in% c( "TestCompiled/R/TestCompiled.R", @@ -85,7 +85,7 @@ test_that("Warning thrown for empty gcov output", { withr::local_options(covr.gcov_args='-n') expect_snapshot( - . <- package_coverage("TestCompiled", relative_path=TRUE), + . <- package_coverage("TestCompiled", relative_path=TRUE, quiet=FALSE), transform = function(x) gsub(getwd(), "", x) ) }) @@ -94,7 +94,7 @@ test_that("tally_coverage includes compiled code", { skip_on_cran() skip_if(is_win_r41()) - cov <- package_coverage(test_path("TestCompiled")) + cov <- package_coverage(test_path("TestCompiled"), quiet=FALSE) tall <- tally_coverage(cov) expect_named(tall, c("filename", "functions", "line", "value")) @@ -109,7 +109,7 @@ test_that("Partial coverage can be optionally excluded", { skip_if(is_win_r41()) withr::local_options(list(covr.gcov_exclude_partial_lines = TRUE)) - cov <- as.data.frame(package_coverage("TestCompiled", relative_path = TRUE)) + cov <- as.data.frame(package_coverage("TestCompiled", relative_path = TRUE, quiet=FALSE)) simple_cc <- cov[cov$filename == "src/simple.cc", ] expect_equal(simple_cc[simple_cc$first_line == "34", "value"], 0) From d45ab4b2f8b58b7c80a0cf34697137abf775ed0d Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sat, 10 May 2025 09:48:13 -0700 Subject: [PATCH 03/13] progress --- tests/testthat/TestCompiled/NAMESPACE | 1 + tests/testthat/TestCompiled/src/simple.cc | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/TestCompiled/NAMESPACE b/tests/testthat/TestCompiled/NAMESPACE index 3d40da6b..e30beaa6 100644 --- a/tests/testthat/TestCompiled/NAMESPACE +++ b/tests/testthat/TestCompiled/NAMESPACE @@ -3,3 +3,4 @@ useDynLib(TestCompiled,simple_) useDynLib(TestCompiled,simple3_) useDynLib(TestCompiled,simple4_) +useDynLib(TestCompiled,simple5_) diff --git a/tests/testthat/TestCompiled/src/simple.cc b/tests/testthat/TestCompiled/src/simple.cc index 2c58878d..c584b6d2 100644 --- a/tests/testthat/TestCompiled/src/simple.cc +++ b/tests/testthat/TestCompiled/src/simple.cc @@ -32,6 +32,6 @@ extern "C" SEXP simple3_(SEXP x) { // multi-expression lines allow for partially executed blocks extern "C" SEXP simple5_(SEXP x) { if (REAL(x)[0] > 0) return Rf_ScalarLogical(TRUE); - if (REAL(x)[0] < 0) return NA_REAL; + if (REAL(x)[0] < 0) return Rf_ScalarLogical(NA_LOGICAL); return Rf_ScalarLogical(FALSE); } From e21c26907752f31de6a9f523064e919324e9514a Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sat, 10 May 2025 12:27:12 -0700 Subject: [PATCH 04/13] revert debugging --- tests/testthat/test-Compiled.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-Compiled.R b/tests/testthat/test-Compiled.R index 51436a20..41d166ea 100644 --- a/tests/testthat/test-Compiled.R +++ b/tests/testthat/test-Compiled.R @@ -2,7 +2,7 @@ test_that("Compiled code coverage is reported including code in headers", { skip_on_cran() skip_if(is_win_r41()) - cov <- as.data.frame(package_coverage("TestCompiled", relative_path = TRUE, quiet=FALSE)) + cov <- as.data.frame(package_coverage("TestCompiled", relative_path = TRUE)) simple_cc <- cov[cov$filename == "src/simple.cc", ] expect_equal(simple_cc[simple_cc$first_line == "10", "value"], 4) @@ -31,7 +31,7 @@ test_that("Compiled code coverage is reported including code in headers", { test_that("Can pass path to relative_path argument", { skip_on_cran() skip_if(is_win_r41()) - cov <- as.data.frame(package_coverage("TestCompiled", relative_path = ".", quiet=FALSE)) + cov <- as.data.frame(package_coverage("TestCompiled", relative_path = ".")) expect_true(all(unique(cov$filename) %in% c( "TestCompiled/R/TestCompiled.R", @@ -85,7 +85,7 @@ test_that("Warning thrown for empty gcov output", { withr::local_options(covr.gcov_args='-n') expect_snapshot( - . <- package_coverage("TestCompiled", relative_path=TRUE, quiet=FALSE), + . <- package_coverage("TestCompiled", relative_path=TRUE), transform = function(x) gsub(getwd(), "", x) ) }) @@ -94,7 +94,7 @@ test_that("tally_coverage includes compiled code", { skip_on_cran() skip_if(is_win_r41()) - cov <- package_coverage(test_path("TestCompiled"), quiet=FALSE) + cov <- package_coverage(test_path("TestCompiled")) tall <- tally_coverage(cov) expect_named(tall, c("filename", "functions", "line", "value")) @@ -109,7 +109,7 @@ test_that("Partial coverage can be optionally excluded", { skip_if(is_win_r41()) withr::local_options(list(covr.gcov_exclude_partial_lines = TRUE)) - cov <- as.data.frame(package_coverage("TestCompiled", relative_path = TRUE, quiet=FALSE)) + cov <- as.data.frame(package_coverage("TestCompiled", relative_path = TRUE)) simple_cc <- cov[cov$filename == "src/simple.cc", ] expect_equal(simple_cc[simple_cc$first_line == "34", "value"], 0) From db322a3e8b108dacc94b516e34a32ecdcd13355b Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sat, 10 May 2025 12:40:56 -0700 Subject: [PATCH 05/13] debugging again --- R/compiled.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/compiled.R b/R/compiled.R index 9fa9c32f..770aa0d7 100644 --- a/R/compiled.R +++ b/R/compiled.R @@ -5,6 +5,7 @@ parse_gcov <- function(file, package_path = "") { } lines <- readLines(file) + writeLines(c("gcov result:", file, lines)) source_file <- rex::re_matches(lines[1], rex::rex("Source:", capture(name = "source", anything)))$source # retrieve full path to the source files From dd82be01b1f3d5b3bb1551c84a6c47432eb211f0 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sat, 10 May 2025 12:45:34 -0700 Subject: [PATCH 06/13] is it just icov? --- tests/testthat/test-Compiled.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-Compiled.R b/tests/testthat/test-Compiled.R index 41d166ea..4ab3ea76 100644 --- a/tests/testthat/test-Compiled.R +++ b/tests/testthat/test-Compiled.R @@ -107,6 +107,7 @@ test_that("tally_coverage includes compiled code", { test_that("Partial coverage can be optionally excluded", { skip_on_cran() skip_if(is_win_r41()) + skip_if(uses_icc()) withr::local_options(list(covr.gcov_exclude_partial_lines = TRUE)) cov <- as.data.frame(package_coverage("TestCompiled", relative_path = TRUE)) From b9a10cd4416a5368022c6ff5096eaf0f55e81a5d Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sat, 10 May 2025 12:47:46 -0700 Subject: [PATCH 07/13] revert debug --- R/compiled.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/compiled.R b/R/compiled.R index 770aa0d7..9fa9c32f 100644 --- a/R/compiled.R +++ b/R/compiled.R @@ -5,7 +5,6 @@ parse_gcov <- function(file, package_path = "") { } lines <- readLines(file) - writeLines(c("gcov result:", file, lines)) source_file <- rex::re_matches(lines[1], rex::rex("Source:", capture(name = "source", anything)))$source # retrieve full path to the source files From 9899c352346e8b24152f9dc15d0c3945b1aa8572 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sat, 10 May 2025 12:52:45 -0700 Subject: [PATCH 08/13] print gcov version, or at least attempt to --- tests/testthat/test-Compiled.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-Compiled.R b/tests/testthat/test-Compiled.R index 4ab3ea76..e2017757 100644 --- a/tests/testthat/test-Compiled.R +++ b/tests/testthat/test-Compiled.R @@ -108,6 +108,7 @@ test_that("Partial coverage can be optionally excluded", { skip_on_cran() skip_if(is_win_r41()) skip_if(uses_icc()) + system('gcov --version') withr::local_options(list(covr.gcov_exclude_partial_lines = TRUE)) cov <- as.data.frame(package_coverage("TestCompiled", relative_path = TRUE)) From 367a139669390f85db74bb71e22fc8d5d3d97d1d Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sat, 10 May 2025 14:19:35 -0700 Subject: [PATCH 09/13] testthat.R instead... --- tests/testthat.R | 1 + tests/testthat/test-Compiled.R | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat.R b/tests/testthat.R index d6da5a81..6876a9e2 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -9,4 +9,5 @@ library(testthat) library(covr) +system('gcov --version') test_check("covr") diff --git a/tests/testthat/test-Compiled.R b/tests/testthat/test-Compiled.R index e2017757..4ab3ea76 100644 --- a/tests/testthat/test-Compiled.R +++ b/tests/testthat/test-Compiled.R @@ -108,7 +108,6 @@ test_that("Partial coverage can be optionally excluded", { skip_on_cran() skip_if(is_win_r41()) skip_if(uses_icc()) - system('gcov --version') withr::local_options(list(covr.gcov_exclude_partial_lines = TRUE)) cov <- as.data.frame(package_coverage("TestCompiled", relative_path = TRUE)) From 1555bd194b6ac037147b899635b7c4c13ab36cc0 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sun, 11 May 2025 13:41:01 -0700 Subject: [PATCH 10/13] more debugging --- R/compiled.R | 1 + tests/testthat.R | 3 +++ 2 files changed, 4 insertions(+) diff --git a/R/compiled.R b/R/compiled.R index 9fa9c32f..50663b58 100644 --- a/R/compiled.R +++ b/R/compiled.R @@ -5,6 +5,7 @@ parse_gcov <- function(file, package_path = "") { } lines <- readLines(file) + writeLines(c("Coverage for", file, lines)) source_file <- rex::re_matches(lines[1], rex::rex("Source:", capture(name = "source", anything)))$source # retrieve full path to the source files diff --git a/tests/testthat.R b/tests/testthat.R index 6876a9e2..b9509db0 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -10,4 +10,7 @@ library(testthat) library(covr) system('gcov --version') +system('gcov --help') +system('man gcov | cat') +package_coverage('testthat/TestCompiled', quiet=FALSE) test_check("covr") From eec4c716893b1eb62cb20e3bde8f3cad148fe2bd Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sun, 11 May 2025 13:52:54 -0700 Subject: [PATCH 11/13] Does -a help? --- R/compiled.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/compiled.R b/R/compiled.R index 50663b58..d404d936 100644 --- a/R/compiled.R +++ b/R/compiled.R @@ -87,7 +87,7 @@ run_gcov <- function(path, quiet = TRUE, clean = TRUE, } run_gcov_one <- function(src) { system_check(gcov_path, - args = c(gcov_args, src, "-p", "-o", dirname(src)), + args = c(gcov_args, src, "-a", "-p", "-o", dirname(src)), quiet = quiet, echo = !quiet) gcov_outputs <- list.files(path, pattern = rex::rex(".gcov", end), recursive = TRUE, full.names = TRUE) if (clean) { From 2089341f33945ca6ac35a08833e641c03c33e204 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sun, 11 May 2025 14:07:59 -0700 Subject: [PATCH 12/13] revert debugging helpers --- R/compiled.R | 3 +-- tests/testthat.R | 4 ---- tests/testthat/test-Compiled.R | 1 - 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/R/compiled.R b/R/compiled.R index d404d936..9fa9c32f 100644 --- a/R/compiled.R +++ b/R/compiled.R @@ -5,7 +5,6 @@ parse_gcov <- function(file, package_path = "") { } lines <- readLines(file) - writeLines(c("Coverage for", file, lines)) source_file <- rex::re_matches(lines[1], rex::rex("Source:", capture(name = "source", anything)))$source # retrieve full path to the source files @@ -87,7 +86,7 @@ run_gcov <- function(path, quiet = TRUE, clean = TRUE, } run_gcov_one <- function(src) { system_check(gcov_path, - args = c(gcov_args, src, "-a", "-p", "-o", dirname(src)), + args = c(gcov_args, src, "-p", "-o", dirname(src)), quiet = quiet, echo = !quiet) gcov_outputs <- list.files(path, pattern = rex::rex(".gcov", end), recursive = TRUE, full.names = TRUE) if (clean) { diff --git a/tests/testthat.R b/tests/testthat.R index b9509db0..d6da5a81 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -9,8 +9,4 @@ library(testthat) library(covr) -system('gcov --version') -system('gcov --help') -system('man gcov | cat') -package_coverage('testthat/TestCompiled', quiet=FALSE) test_check("covr") diff --git a/tests/testthat/test-Compiled.R b/tests/testthat/test-Compiled.R index 4ab3ea76..41d166ea 100644 --- a/tests/testthat/test-Compiled.R +++ b/tests/testthat/test-Compiled.R @@ -107,7 +107,6 @@ test_that("tally_coverage includes compiled code", { test_that("Partial coverage can be optionally excluded", { skip_on_cran() skip_if(is_win_r41()) - skip_if(uses_icc()) withr::local_options(list(covr.gcov_exclude_partial_lines = TRUE)) cov <- as.data.frame(package_coverage("TestCompiled", relative_path = TRUE)) From dcaf816e622ba357fa7db3de92756a79f0bb1aa3 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sun, 11 May 2025 14:36:46 -0700 Subject: [PATCH 13/13] progress, maybe, i dunno, i give up --- R/compiled.R | 30 ++++++++++++++++++++++++++++++ R/icc.R | 10 +++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/R/compiled.R b/R/compiled.R index 9fa9c32f..f8f315f7 100644 --- a/R/compiled.R +++ b/R/compiled.R @@ -56,6 +56,36 @@ parse_gcov <- function(file, package_path = "") { line_coverages(source_file, matches, values, functions) } +supports_simple_partial_coverage <- function(gcov_path = getOption("covr.gcov_path", "")) { + if (!nzchar(gcov_path)) { + stop("Please set covr.gcov_path first") + } + tmp_dir <- tempfile() + dir.create(tmp_dir) + old_wd <- setwd(tmp_dir) + on.exit({ + setwd(old_wd) + unlink(tmp_dir, recursive = TRUE) + }) + + cat(file = "test.cc", ' +#include + +int main(int argc, char *argv[]) { + int verbose = 0; + if (argc > 1 && argv[1][0] == \'v\') { + verbose = 1; + } + if (verbose) printf("Verbose mode is ON\\n"); + printf("Program finished\\n"); + return 0; +} +') + system2(r_compiler(), c("-fprofile-arcs", "-ftest-coverage", "test.cc", "-o", "test.o")) + system2("./test.o") + system2(gcov_path, "test.cc") +} + # for mocking readLines <- NULL file.exists <- NULL diff --git a/R/icc.R b/R/icc.R index 4c050904..e0f481bb 100644 --- a/R/icc.R +++ b/R/icc.R @@ -119,8 +119,7 @@ run_icov <- function(path, quiet = TRUE, class = "coverage") } -# check if icc is used -uses_icc <- function() { +r_compiler <- function() { compiler <- tryCatch( { system2(file.path(R.home("bin"), "R"), @@ -128,5 +127,10 @@ uses_icc <- function() { stdout = TRUE) }, warning = function(e) NA_character_) - isTRUE(any(grepl("\\bicc\\b", compiler))) + compiler +} + +# check if icc is used +uses_icc <- function() { + isTRUE(any(grepl("\\bicc\\b", r_compiler()))) }