1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/expect_lint.R
\name{expect_lint}
\alias{expect_lint}
\alias{expect_no_lint}
\title{Lint expectation}
\usage{
expect_lint(content, checks, ..., file = NULL, language = "en")
expect_no_lint(content, ..., file = NULL, language = "en")
}
\arguments{
\item{content}{a character vector for the file content to be linted, each vector element representing a line of
text.}
\item{checks}{checks to be performed:
\describe{
\item{NULL}{check that no lints are returned.}
\item{single string or regex object}{check that the single lint returned has a matching message.}
\item{named list}{check that the single lint returned has fields that match. Accepted fields are the same as those
taken by \code{\link[=Lint]{Lint()}}.}
\item{list of named lists}{for each of the multiple lints returned, check that it matches the checks in the
corresponding named list (as described in the point above).}
}
Named vectors are also accepted instead of named lists, but this is a compatibility feature that
is not recommended for new code.}
\item{...}{arguments passed to \code{\link[=lint]{lint()}}, e.g. the linters or cache to use.}
\item{file}{if not \code{NULL}, read content from the specified file rather than from \code{content}.}
\item{language}{temporarily override Rs \code{LANGUAGE} envvar, controlling localization of base R error messages.
This makes testing them reproducible on all systems irrespective of their native R language setting.}
}
\value{
\code{NULL}, invisibly.
}
\description{
These are expectation functions to test specified linters on sample code in the \code{testthat} testing framework.
\itemize{
\item \code{expect_lint} asserts that specified lints are generated.
\item \code{expect_no_lint} asserts that no lints are generated.
}
}
\examples{
# no expected lint
expect_no_lint("a", trailing_blank_lines_linter())
# one expected lint
expect_lint("a\n", "trailing blank", trailing_blank_lines_linter())
expect_lint("a\n", list(message = "trailing blank", line_number = 2), trailing_blank_lines_linter())
# several expected lints
expect_lint("a\n\n", list("trailing blank", "trailing blank"), trailing_blank_lines_linter())
expect_lint(
"a\n\n",
list(
list(message = "trailing blank", line_number = 2),
list(message = "trailing blank", line_number = 3)
),
trailing_blank_lines_linter()
)
}
|