
# 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 <- unlist(lapply(directories, function(dir) {
    lint_dir(path = dir, linters = absolute_path_linter(lax = TRUE))
  }), recursive = TRUE)
  
  # Check results and print out the test outcome
  if (length(files_with_issues) > 0) {
    cat("Test FAILED. Hard-coded paths found in the following files:\n")
    issues_report <- vapply(files_with_issues, function(l) {
      paste(l$filename, "Line:", l$line_number, "Message:", l$message)
    }, character(1))
    print(issues_report)
    return(FALSE)
  } else {
    cat("Test PASSED😊 No hard-coded paths found in any file.\n")
    return(TRUE)
  }
}

detect_hardcoded_paths()
