
# Unit test: detect hard-coded absolute paths in the code

library(lintr)

detect_hardcoded_paths <- function() {
  
  # Define the directories to check
  directories <- c("modules", "tools")
  
  # Apply absolute_path_linter() to each directory and save results
  files_with_issues <- lapply(directories, function(dir) {
    lint_dir(path = dir, linters = absolute_path_linter(lax = TRUE))
  })

  # Assign names to the list elements
  names(files_with_issues) <- directories

  # Check results and print out the test outcome
  if (any(sapply(files_with_issues, function(x) length(x) > 0))) {
    cat("Test FAILED. Absolute paths found:\n")
    print(files_with_issues)
    return(FALSE)
  } else {
    cat("No absolute paths found in any file.\n")
    return(TRUE)
  }
}

test_that("Check code for absolute paths", {
  expect_true(detect_hardcoded_paths())
})
