Skip to content

Commit 901263b

Browse files
fix issue with getNamespaceExports tested order
1 parent 1cdc1d5 commit 901263b

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

R/utils.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ stale_package_check = function(con) {
147147
code = tryCatch(parse(con), error = identity)
148148
if (inherits(code, 'error')) {
149149
cat('Failed to parse R script, please fix syntax errors first\n')
150+
cat(' failed with: ', conditionMessage(code), '\n', sep = '')
150151
return(invisible())
151152
}
152153

@@ -166,13 +167,13 @@ stale_package_check = function(con) {
166167
)
167168

168169
for (pkg in all_packages) {
169-
fns = getNamespaceExports(pkg)
170+
fns = sort(getNamespaceExports(pkg)) # for #13
170171

171172
used = fns %in% all_plain_calls
172173
if (any(used))
173-
cat('Functions matched from package ', pkg, ':\n\t',
174-
paste(fns[used], collapse = ', '), '\n', sep = '')
175-
else cat('**No exported functions matched from ', pkg, '**\n', sep = '')
174+
cat('Functions matched from package ', pkg, ':\n\t', toString(fns[used]), '\n', sep = '')
175+
else
176+
cat('**No exported functions matched from ', pkg, '**\n', sep = '')
176177
}
177178
return(invisible())
178179
}

tests/testthat/test-utils.R

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
context('Utility functions')
22

33
test_that('stale_package_check works', {
4-
script_dir = 'stale_package_test_scripts'
4+
stale_package_path <- function(path) test_path('stale_package_test_scripts', path)
5+
56
expect_output(
6-
stale_package_check(file.path(script_dir, 'simple.R')),
7+
stale_package_check(stale_package_path('simple.R')),
78
paste(
8-
c("Functions matched from package stats:", "\tdensity, rnorm",
9-
"Functions matched from package tools:", "\tfile_ext",
9+
c("Functions matched from package stats:",
10+
paste0("\t", toString(sort(c("density", "rnorm")))),
11+
"Functions matched from package tools:",
12+
"\tfile_ext",
1013
"**No exported functions matched from tcltk**"),
1114
collapse = '\n'
1215
),
1316
fixed = TRUE
1417
)
1518

1619
expect_output(
17-
stale_package_check(file.path(script_dir, 'use_namespace_call.R')),
20+
stale_package_check(stale_package_path('use_namespace_call.R')),
1821
'**No exported functions matched from stats**',
1922
fixed = TRUE
2023
)
2124

2225
expect_output(
23-
stale_package_check(file.path(script_dir, 'wont-parse.R')),
26+
stale_package_check(stale_package_path('wont_parse.R')),
2427
'Failed to parse R script, please fix syntax errors first',
2528
fixed = TRUE
2629
)
2730

2831
expect_output(
29-
stale_package_check(file.path(script_dir, 'no_library.R')),
32+
stale_package_check(stale_package_path('no_library.R')),
3033
'No library() or require() calls found',
3134
fixed = TRUE
3235
)

0 commit comments

Comments
 (0)