Skip to content

Commit

Permalink
start work on opinions cf #76
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Apr 11, 2018
1 parent 5b82013 commit 46da104
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 12 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ Imports:
readr,
desc,
usethis,
whisker
Suggests: testthat,
whisker,
tibble
Suggests:
testthat,
jsonvalidate,
covr,
knitr,
Expand All @@ -51,7 +53,6 @@ Suggests: testthat,
magrittr,
xml2,
dplyr (>= 0.7.0),
tibble,
purrr,
printr
VignetteBuilder: knitr
Expand Down
54 changes: 54 additions & 0 deletions R/give_opinions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#' Function giving opinions about a package
#'
#' @param pkg_path
#'
#' @return A data.frame of opinions
#' @export
#'
give_opinions <- function(pkg_path = .){
descr_path <- file.path(pkg_path, "DESCRIPTION")
# opinions about DESCRIPTION
descr_issues <- give_opinions_desc(descr_path)


fixmes <- descr_issues
fixmes$package <- as.character(descr$get("Package"))
}

give_opinions_desc <- function(descr_path){
descr <- desc::desc(descr_path)
# Authors
if (inherits( try(descr$get_authors(), silent = TRUE),
'try-error')){
authors_fixme <- "The syntax Authors@R instead of plain Author and Maintainer is recommended in particular because it allows richer metadata" # no lint
}else{
authors_fixme <- NULL
}

# URL
if(is.na(descr$get("URL"))){
url_fixme <- "URL field. Indicate the URL to your code repository."
}else{
url_fixme <- NULL
}

# BugReports
if(is.na(descr$get("BugReports"))){
bugreports_fixme <- "BugReports field. Indicate where to report bugs, e.g. GitHub issue tracker."
}else{
bugreports_fixme <- NULL
}

fixmes <- c(authors_fixme, url_fixme, bugreports_fixme)
fixmes <- fixmes[!is.null(fixmes)]

if(length(fixmes) >0){

tibble::tibble(where = "DESCRIPTION",
fixme = fixmes)
}else{
NULL
}


}
9 changes: 0 additions & 9 deletions tests/testthat/test-codemeta_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@ testthat::test_that("We can use a preset id", {
codemeta_description(f, id = "https://doi.org/10.looks.like/doi")
})

testthat::test_that("Error if no URL", {
f <- system.file("examples/DESCRIPTION_no_URL", package = "codemetar")
expect_error(codemeta_description(f))
})

testthat::test_that("Warning if no BugReports", {
f <- system.file("examples/DESCRIPTION_Rforge", package = "codemetar")
cm <- codemeta_description(f)
expect_equal(cm$codeRepository, "http://surveillance.R-Forge.R-project.org/")
})

testthat::test_that("Works R-forge", {
f <- system.file("examples/DESCRIPTION_two_URLs", package = "codemetar")
Expand Down
22 changes: 22 additions & 0 deletions tests/testthat/test-give_opinions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
context("test-give_opinions.R")

testthat::test_that("Message if no URL", {
f <- system.file("examples/DESCRIPTION_no_URL", package = "codemetar")
desc_fixmes <- give_opinions_desc(f)
expect_is(desc_fixmes, "data.frame")
expect_equal(desc_fixmes$where, "DESCRIPTION")
expect_true(any(grepl("URL", desc_fixmes$fixme)))
})

testthat::test_that("Message if no BugReports", {
f <- system.file("examples/DESCRIPTION_no_bugreports", package = "codemetar")
desc_fixmes <- give_opinions_desc(f)
expect_is(desc_fixmes, "data.frame")
expect_equal(desc_fixmes$where, "DESCRIPTION")
expect_true(any(grepl("BugReports", desc_fixmes$fixme)))
})

testhat::test_that("No message if ok description"){
f <- system.file("examples/DESCRIPTION_Rforge", package = "codemetar")
expect_is(give_opinions_desc(f), NULL)
}

0 comments on commit 46da104

Please sign in to comment.