Skip to content

Commit

Permalink
Merge pull request #141 from jimhester/testthat_new
Browse files Browse the repository at this point in the history
Use testthat:::expect
  • Loading branch information
jimhester committed Apr 15, 2016
2 parents a769c0b + d14414e commit be98a75
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 56 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r

language: R
sudo: false
cache: packages

addons:
apt:
packages:
libicu-dev

before_script:
- Rscript -e 'devtools::install_github("jimhester/covr")'

after_success:
- Rscript -e 'covr::codecov()'
4 changes: 4 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Imports:
knitr,
stats,
utils
Remotes:
hadley/testthat
Suggests:
rmarkdown
License: MIT + file LICENSE
LazyData: true
VignetteBuilder: knitr
58 changes: 10 additions & 48 deletions R/expect_lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,7 @@ expect_lint <- function(content, checks, ..., file = NULL) {
content <- readChar(file, file.info(file)$size)
}

results <- expectation_lint(content, checks, ...)

reporter <- testthat::get_reporter()

# flatten list if a list of lists
if (is.list(results) &&
is.list(results[[1]]) &&
!testthat::is.expectation(results[[1]])) {

results <- unlist(recursive = FALSE, results)
}

if (testthat::is.expectation(results)) {
reporter$add_result(results)
}
else {
lapply(results, reporter$add_result)
}

invisible(results)
expectation_lint(content, checks, ...)
}

expectation_lint <- function(content, checks, ...) {
Expand All @@ -50,12 +31,11 @@ expectation_lint <- function(content, checks, ...) {
linter_names <- substitute(alist(...))[-1]

if (is.null(checks)) {
return(testthat::expectation(length(lints) %==% 0L,
return(testthat::expect(length(lints) %==% 0L,
paste0(paste(collapse = ", ", linter_names),
" returned ", print(lints),
" lints when it was expected to return none!"),
paste0(paste(collapse = ", ", linter_names),
" returned 0 lints as expected.")))
))
}

if (!is.list(checks)) {
Expand All @@ -64,7 +44,7 @@ expectation_lint <- function(content, checks, ...) {
checks[] <- lapply(checks, fix_names, "message")

if (length(lints) != length(checks)) {
return(testthat::expectation(FALSE,
return(testthat::expect(FALSE,
paste0(paste(collapse = ", ", linter_names),
" did not return ", length(checks),
" lints as expected from content:", content, lints)))
Expand All @@ -77,35 +57,19 @@ expectation_lint <- function(content, checks, ...) {
value <- lint[[field]]
check <- check[[field]]
if (field == "message") {
testthat::expectation(re_matches(value, check),
testthat::expect(re_matches(value, check),
sprintf("lint: %d %s: %s did not match: %s",
itr,
field,
value,
check
),
sprintf("lint: %d %s: %s matched: %s",
itr,
field,
value,
check
)
)
check))
} else {
testthat::expectation(`==`(value, check),
testthat::expect(`==`(value, check),
sprintf("lint: %d %s: %s did not match: %s",
itr,
field,
value,
check
),
sprintf("lint: %d %s: %s matched: %s",
itr,
field,
value,
check
)
)
check))
}
})
},
Expand All @@ -130,12 +94,10 @@ expect_lint_free <- function(...) {
if (has_lints) {
lint_output <- paste(collapse = "\n", capture.output(print(lints)))
}
result <- testthat::expectation(!has_lints,
result <- testthat::expect(!has_lints,
paste(sep = "\n",
"Not lint free",
lint_output),
"lint free")
lint_output))

testthat::get_reporter()$add_result(result)
invisible(result)
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# lintr
[![Build Status](https://app.wercker.com/status/9b57842367f234e4c7e17d01fd8a4a15/s/master "wercker status")](https://app.wercker.com/project/bykey/9b57842367f234e4c7e17d01fd8a4a15)
[![Travis-CI Build Status](https://travis-ci.org/jimhester/lintr.svg?branch=master)](https://travis-ci.org/jimhester/lintr)
[![codecov.io](http://codecov.io/github/jimhester/lintr/coverage.svg?branch=master)](http://codecov.io/github/jimhester/lintr?branch=master)
[![CRAN version](http://www.r-pkg.org/badges/version/lintr)](http://cran.rstudio.com/web/packages/lintr/index.html)

Expand Down
7 changes: 0 additions & 7 deletions wercker.yml

This file was deleted.

0 comments on commit be98a75

Please sign in to comment.