Skip to content

Commit

Permalink
Merge a6602a2 into a973b9c
Browse files Browse the repository at this point in the history
  • Loading branch information
robertzk committed Aug 7, 2017
2 parents a973b9c + a6602a2 commit a0eefff
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## 0.3.0.5.9004

* Fix usage of `base` parameter in `$find` method with idempotent resources.

## 0.3.0.5.9003

* Fix NA detection in `%|||%` operator to work with POSIXct objects.
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Expand Up @@ -5,7 +5,7 @@ Description: Director is responsible for managing and loading resources in
consecutive loads of resources (so that we can tell if a script was modified
since we last ran it) and defining parsers that allow us to generalize from
the pernicious simple linear execution that is common to R.
Version: 0.3.0.5.9003
Version: 0.3.0.5.9004
Authors@R: c(person("Robert", "Krzyzanowski",
email = "technoguyrob@gmail.com", role = c("aut", "cre")))
Depends:
Expand Down
13 changes: 11 additions & 2 deletions R/director-find.R
Expand Up @@ -97,6 +97,9 @@ find_ <- function(director, pattern, method, base, by_mtime) {

all_files <- list.files(file.path(director$root(), base),
pattern = "\\.[rR]$", recursive = TRUE)
if (nzchar(base)) {
all_files <- file.path(base, all_files)
}
all_files <- strip_r_extension(all_files)

## We will use the `apply_pattern` helper below, so all patterns should
Expand All @@ -113,7 +116,7 @@ find_ <- function(director, pattern, method, base, by_mtime) {
## we would find files that contain "foo" as a substring.
resources <- apply_pattern(pattern, all_files)

if (nzchar(base)) resources <- file.path(base, resources)
# if (nzchar(base)) resources <- file.path(base, resources)
sort_by_mtime(resources, by_mtime, director)
}

Expand All @@ -134,7 +137,13 @@ sort_by_mtime <- function(files, by_mtime, director) {
}

exact_find <- function(director, pattern, base) {
if (nzchar(base)) pattern <- file.path(base, pattern)
if (nzchar(base)) {
if (nzchar(pattern)) {
pattern <- file.path(base, pattern)
} else {
pattern <- base
}
}

## A resource "foo" can correspond to either "foo.r", "foo.R",
## "foo/foo.r", or "foo/foo.R".
Expand Down
14 changes: 12 additions & 2 deletions tests/testthat/test-director_find.R
Expand Up @@ -107,15 +107,25 @@ test_that("it can find files with multiple extensions", {
test_that("it correctly does an exact match on idempotent resources", {
within_file_structure(list(uno = list(dos = list('dos.R'))), { d <- director(tempdir)
expect_identical('uno/dos', d$find("uno/dos", method = "exact"),
info = "Exact matching shoudl find uno/dos as an idempotent resource.")
info = "Exact matching should find uno/dos as an idempotent resource.")
})
})

test_that("it correctly does an exact match on idempotent resources with base", {
within_file_structure(list(uno = list(dos = list('dos.R'))), { d <- director(tempdir)
expect_identical('uno/dos', d$find("dos", base = "uno", method = "exact"),
info = "Exact matching shoudl find uno/dos as an idempotent resource.")
info = "Exact matching should find uno/dos as an idempotent resource.")
})
})

test_that("it only find a single idempotent resource when the base is the resource", {
within_file_structure(list(uno = list('uno.R', 'bar.R')), { d <- director(tempdir)
expect_identical('uno', d$find(base = "uno", method = "partial"),
info = "Partial matching should find uno as an idempotent resource.")
expect_identical('uno', d$find(base = "uno", method = "exact"),
info = "Exact matching should find uno as an idempotent resource.")
})
})



0 comments on commit a0eefff

Please sign in to comment.