Skip to content

Commit

Permalink
Add test for OS config dir support
Browse files Browse the repository at this point in the history
  • Loading branch information
klmr committed Nov 13, 2022
1 parent 6fd88c7 commit 3b3f44e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ trim_some <- function(x, num = NULL) {
rex::re_substitutes(x, rex::rex(start, n_times(any, num)), "", global = TRUE, options = "multi-line")
}

local_config <- function(config_dir, contents, .local_envir = parent.frame()) {
config_path <- file.path(config_dir, ".lintr")
local_config <- function(config_dir, contents, filename = ".lintr", .local_envir = parent.frame()) {
config_path <- file.path(config_dir, filename)
writeLines(contents, config_path)
withr::defer(unlink(config_path), envir = .local_envir)
config_path
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ test_that("it uses config home directory settings if provided", {
expect_identical(settings$exclude, "test")
})

test_that("it uses system config directory settings if provided", {
path <- withr::local_tempdir()
config_parent_path <- withr::local_tempdir("config")
config_path <- file.path(config_parent_path, "R", "lintr")
dir.create(config_path, recursive = TRUE)
file <- withr::local_tempfile(tmpdir = path)
local_config(config_path, 'exclude: "test"', filename = "config")

withr::with_envvar(c(R_USER_CONFIG_DIR = config_parent_path), lintr:::read_settings(file))

lapply(setdiff(ls(settings), "exclude"), function(setting) {
expect_identical(settings[[setting]], default_settings[[setting]])
})

expect_identical(settings$exclude, "test")
})

test_that("it errors if the config file does not end in a newline", {
f <- withr::local_tempfile()
cat("linters: linters_with_defaults(closed_curly_linter = NULL)", file = f)
Expand Down

0 comments on commit 3b3f44e

Please sign in to comment.