Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use public interface to test internal functions: Part-4 #1774

Merged
merged 10 commits into from
Nov 26, 2022
2 changes: 1 addition & 1 deletion tests/testthat/test-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test_that("as.data.frame.lints", {
# Convert lints to data.frame
lints <- structure(list(l1, l2), class = "lints")
expect_s3_class(
df <- lintr:::as.data.frame.lints(lints),
df <- as.data.frame(lints),
"data.frame"
)

Expand Down
32 changes: 21 additions & 11 deletions tests/testthat/test-use_lintr.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,34 @@ test_that("use_lintr works as expected", {
lintr_file <- use_lintr(path = tmp)
expect_true(file.exists(lintr_file))

# check that newly created file is in the root directory
expect_identical(
normalizePath(lintr_file, winslash = "/"),
file.path(normalizePath(tmp, winslash = "/"), ".lintr")
)

# can't generate if a .lintr already exists
expect_error(use_lintr(path = tmp), "Found an existing configuration")

# read_settings() works with the generated file
expect_silent(lintr:::read_settings(tmp))
lintr:::read_settings(NULL)

expect_identical(
normalizePath(lintr:::find_config(tmp)),
normalizePath(lintr_file)
)
# check that `read_settings()` works with the generated file
# this can be checked by checking lintr runs successfully
lints <- lint_dir(tmp)
expect_length(lints, 0L)
})

test_that("use_lintr with type = full also works", {
tmp <- withr::local_tempdir()

# type = "full" also works with read_settings()
use_lintr(path = tmp, type = "full")
expect_silent(lintr:::read_settings(tmp))
lintr:::read_settings(NULL)
lintr_file <- use_lintr(path = tmp, type = "full")
expect_true(file.exists(lintr_file))

# check that newly created file is in the root directory
expect_identical(
normalizePath(lintr_file, winslash = "/"),
file.path(normalizePath(tmp, winslash = "/"), ".lintr")
)

lints <- lint_dir(tmp)
expect_length(lints, 0L)
})