diff --git a/R/file_mod.R b/R/file_mod.R index 1b17af8..3f29018 100644 --- a/R/file_mod.R +++ b/R/file_mod.R @@ -8,6 +8,8 @@ parse_parameter_names <- function(filenames) { if(nrow(matches) == 0) { return(NULL) + } else if(length(filenames) == 1 && filenames[[1]] == "") { + return(NULL) } else { return(unique(paste0(matches[,2], "_", matches[,3]))) } @@ -16,8 +18,10 @@ parse_parameter_names <- function(filenames) { #' Get publication IDs modified since a specified commit #' #' @param last_commit The commit ID to check to -get_modified_files <- function(last_commit) { - sys_string <- paste0("git diff --name-only ", last_commit, " HEAD") +get_modified_files <- function(last_commit, end_commit = "HEAD") { + end_commit <- paste0(" ", end_commit) + + sys_string <- paste0("git diff --name-only ", last_commit, end_commit) files <- system(sys_string, intern = TRUE) modified_via_params <- files[startsWith(files, "parameters")] |> diff --git a/tests/testthat/test-file-mod.R b/tests/testthat/test-file-mod.R new file mode 100644 index 0000000..a97bebf --- /dev/null +++ b/tests/testthat/test-file-mod.R @@ -0,0 +1,12 @@ +test_that("parse_parameter_names returns correct pub ID", { + expect_equal(parse_parameter_names("kozak_1988.csv"), "kozak_1988") + + empty_parse <- parse_parameter_names("") + expect_true(is.null(empty_parse)) +}) + +test_that("get_modified_files returns valid pub IDs", { + check <- get_modified_files("32006ca", "018e79d") + + expect_equal(check, "sharma_2015") +}) \ No newline at end of file diff --git a/tests/testthat/test-publication-processing.R b/tests/testthat/test-publication-processing.R index 7b831fe..82b274f 100644 --- a/tests/testthat/test-publication-processing.R +++ b/tests/testthat/test-publication-processing.R @@ -98,4 +98,4 @@ test_that("get_current_pub_ids_params returns valid publication ids", { # All pub_ids contain only characters before the year all(grepl("^[a-zA-Z]+_\\d{4}[a-zA-Z]?$", current_pub_ids)) -}) \ No newline at end of file +})