tests/testthat/helper-syncr.R

## The most awkward thing here is doing the mocking up directory
## structures to mess with.
create_dirs <- function(root, x) {
  for (i in x) {
    dir.create(file.path(root, i), FALSE, TRUE)
  }
}

random_file <- function(path, max_len) {
  n <- sample(max_len)
  pool <- c(0:9, LETTERS, letters, " ", "\n")
  writeLines(paste(c(sample(pool, n, TRUE), "\n"), collapse=""), path)
}

## This might move into the package at some point
diff_bin <- function() {
  Sys_which("diff")
}

diff_dirs <- function(path1, path2) {
  system3(diff_bin(), c("-rq", path1, path2))$code == 0L
}

with_wd <- function(wd, expr) {
  owd <- setwd(wd)
  on.exit(setwd(owd))
  expr
}
mrc-ide/syncr documentation built on May 15, 2019, 1:43 p.m.