Skip to content

Commit 74add4e

Browse files
committed
100% coverage.
1 parent ef6352d commit 74add4e

11 files changed

Lines changed: 42 additions & 23 deletions

File tree

R/pkg_test.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ summary.pkg_test <- function(object, col = 'file', ...) {
173173
}
174174

175175
# aggregation function
176-
.col_stats <- function(x) { if (is.logical(x)) any(x) else sum(x) }
176+
.col_stats <- function(x) {
177+
if (is.logical(x)) any(x) else sum(x)
178+
}
177179
sdf <- stats::aggregate(df[, data_cols], by = by, .col_stats)
178180
if (length(col)) sdf <- sdf[order(sdf[[col]]), , drop = FALSE] else sdf$rows <- NULL
179181
rownames(sdf) <- NULL

R/pkgs_check.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ pkgs_check <- function(pkgids = names(filter_srcpkgs(src_pkgs, filter)), src_pkg
2525
filter = NULL, lib = ".check", quiet = FALSE, fail_on_error = FALSE, ...)
2626
{
2727
force(src_pkgs)
28-
if (!length(pkgids)) stop('No package to test')
28+
if (!length(pkgids)) {
29+
stop('No package to test')
30+
}
2931
pkgs <- as_srcpkgs(pkgids, src_pkgs)
3032
if (!dir.exists(lib)) dir.create(lib, recursive = TRUE)
3133

@@ -45,9 +47,9 @@ pkgs_check <- function(pkgids = names(filter_srcpkgs(src_pkgs, filter)), src_pkg
4547

4648
summ <- summary(chks)
4749

48-
if (fail_on_error && (any(summ$errors > 0) || any(summ$warnings > 0)))
50+
if (fail_on_error && (any(summ$errors > 0) || any(summ$warnings > 0))) {
4951
cli::cli_abort("checks failed")
52+
}
5053

51-
5254
invisible(chks)
5355
}

R/project_root.R

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,7 @@ parent_dir <- function(dir) {
4040

4141
find_git_dir <- function(here = getwd()) {
4242
if (!length(here)) return(NULL)
43-
git <- find_file_upwards('.git', here)
44-
if (!length(git)) return(NULL)
45-
if (!file.exists(git)) {
46-
# if (!dir.exists(git)) {
47-
# not a directory, e.g. could be a git submodule symlink. retry from the parent dir if any
48-
return(find_git_dir(parent_dir(here)))
49-
}
50-
51-
git
43+
find_file_upwards('.git', here)
5244
}
5345

5446
find_file_upwards <- function(filename, folder = getwd()) {

R/utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ is_condition_true <- function(cond) {
4141
as.logical(cond)
4242
}
4343

44-
is_string <- function(x) length(x) == 1 && is.character(x)
44+
# is_string <- function(x) length(x) == 1 && is.character(x)
4545
is_nz_string <- function(x) length(x) == 1 && is.character(x) && nzchar(x)
4646

4747
is_error <- function(x) inherits(x, "try-error")

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
<!-- badges: start -->
44
[![R-CMD-check](https://github.com/kforner/srcpkgs/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/kforner/srcpkgs/actions/workflows/R-CMD-check.yaml)
5-
65
[![Codecov test coverage](https://codecov.io/gh/kforner/srcpkgs/branch/main/graph/badge.svg)](https://app.codecov.io/gh/kforner/srcpkgs?branch=main)
7-
86
[![CRAN status](https://www.r-pkg.org/badges/version/srcpkgs)](https://CRAN.R-project.org/package=srcpkgs)
97
<!-- badges: end -->
108

dev.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ test(filter = "config")
77
test(filter = "pkg_check")
88
test(filter = "pkg_load")
99
test(filter = "pkg_test")
10+
test(filter = "pkgs_check")
1011
test(filter = "pkgs_test")
12+
test(filter = "project_root")
1113
check()
1214

1315
options(width = Sys.getenv("COLUMNS", 80))

tests/testthat/test-pkg_test.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test_that("pkg_test", {
4040
add_dummy_test_to_srcpkgs(src_pkgs)
4141
### one package with a dep
4242

43-
res <- pkg_test('AA', src_pkgs = src_pkgs, reporter = "silent")
43+
resAA <- res <- pkg_test('AA', src_pkgs = src_pkgs, reporter = "silent")
4444

4545
expect_s3_class(res, "pkg_test")
4646
df <- as.data.frame(res)
@@ -60,6 +60,14 @@ test_that("pkg_test", {
6060
res <- pkg_test('AA', filter = "failure", src_pkgs = src_pkgs, reporter = "silent")
6161
df <- as.data.frame(res)
6262
expect_true(all(df$failed > 0))
63+
64+
### if loaders_hack_enabled
65+
if (! is_loaders_hack_enabled()) {
66+
hack_r_loaders()
67+
on.exit(unhack_r_loaders(), add = TRUE)
68+
}
69+
res <- pkg_test('AA', src_pkgs = src_pkgs, reporter = "silent")
70+
expect_identical(as.data.frame(fix_test_result_timings(res)), as.data.frame(fix_test_result_timings(resAA)))
6371
})
6472

6573

tests/testthat/test-pkgs_check.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ test_that("pkgs_check", {
55
src_pkgs <- examples_srcpkgs_basic()
66
setup_temp_dir()
77

8+
###################################### edge cases ###############################
9+
expect_error(pkgs_check(NULL), 'No package to test')
10+
811
###### with tests
912
add_dummy_test_to_srcpkgs(src_pkgs)
1013
# make BB to fail
1114
writeLines(r"{ stop("aie aie aie") }", file.path(src_pkgs$BB$path, "tests/testthat/setup.R"))
1215

1316
###
14-
chks <- pkgs_check(src_pkgs = src_pkgs, quiet = TRUE)
17+
mute(chks <- pkgs_check(src_pkgs = src_pkgs, quiet = FALSE))
1518

1619
expect_s3_class(chks, "pkgs_check")
1720
expect_true(is.list(chks))
@@ -32,12 +35,11 @@ test_that("pkgs_check", {
3235
expect_identical(sdf[i,], expected)
3336
}
3437

35-
### print
36-
expect_snapshot(print(chks))
37-
3838
#### fail_on_error
3939
expect_error(chks <- pkgs_check(src_pkgs = src_pkgs, quiet = TRUE, fail_on_error = TRUE), "checks failed")
4040

41+
### print
42+
expect_snapshot(print(chks))
4143
})
4244

4345

tests/testthat/test-pkgs_test.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
test_that("pkgs_test_when_no_tests", {
44
src_pkgs <- examples_srcpkgs_basic()
55

6+
### edge cases
7+
expect_error(pkgs_test(NULL), 'No package to test')
8+
69
### no tests at all
710
res <- pkgs_test(src_pkgs = src_pkgs, reporter = "silent", quiet = TRUE)
811

tests/testthat/test-project_root.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ test_that("find_project_root", {
2222
# # dir1 by default
2323
# expect_identical(basename(find_project_root('dir1/')), 'dir1')
2424
# root because of .git file
25-
2625
expect_identical(basename(find_project_root('dir1/')), basename(getwd()))
2726

2827
root3 <- file.path(getwd(), 'dir1/dir2/dir3')
@@ -38,6 +37,16 @@ test_that("find_project_root", {
3837
expect_null(find_project_root(NULL))
3938
})
4039

40+
.find_git_dir <-
41+
test_that("find_git_dir", {
42+
setup_temp_dir()
43+
44+
expect_null(find_git_dir(NULL))
45+
46+
47+
})
48+
49+
4150

4251
test_that("parent_dir", {
4352
expect_identical(parent_dir('/'), NULL)

0 commit comments

Comments
 (0)