brodieG / unitizer

@@ -300,39 +300,25 @@
Loading
300 300
      # nocov end
301 301
  } }
302 302
  if(identical(global$status@working.directory, 2L)) {
303 -
    if(length(unique(dirname(test.files)) == 1L)) {
304 -
      path <- dirname(test.files[[1L]])
305 -
      pat <- sprintf("(.*\\%s).*", file.path(".Rcheck", "tests", ""))
306 -
      test.dir <- if(grepl(pat, path)) {
307 -
        sub(pat, "\\1", path)
308 -
      } else if(
303 +
    # If likely in a test directory don't change directory.  Might be safer to
304 +
    # check for the R_TESTS environment variable.
305 +
    wd <- getwd()
306 +
    test.dir <- if(grepl("-tests$", wd)) {  # tools::testInstalledPackage
307 +
      wd
308 +
    } else if (grepl("tests", wd) && grepl("\\.Rcheck", dirname(wd))) {
309 +
      wd
310 +
    } else if(length(unique(dirname(test.files)) == 1L)) {
311 +
      if(
309 312
        length(par.dir <- get_package_dir(test.files[[1L]])) &&
310 313
        file_test("-d", file.path(par.dir, "tests"))
311 314
      ) {
315 +
        # Use parent package dir test folder
312 316
        file.path(par.dir, "tests")
313 317
      } else {
314 318
        # File doesn't seem to be in package, so set wd to be the same as
315 319
        # the file
316 -
317 -
        path
320 +
        dirname(test.files[[1L]])
318 321
      }
319 -
      if(!is.null(test.dir)) {
320 -
        dir.set <- try(setwd(test.dir))
321 -
        if(inherits(dir.set, 'try-error')) {
322 -
          # nocov start there really shouldn't be a way to trigger this warning
323 -
          test.dir.err <-
324 -
            if(!is.chr1(test.dir)) "<not character(1L)>" else test.dir
325 -
          warning(
326 -
            word_wrap(collapse="\n",
327 -
              cc(
328 -
                "Working directory state tracking is in mode 2, but we ",
329 -
                "failed setting director to '", test.dir.err, "' so we are  ",
330 -
                "leaving the working directory unchanged."
331 -
            ) ),
332 -
            immediate.=TRUE
333 -
          )
334 -
          # nocov end
335 -
      } }
336 322
    } else {
337 323
      # nocov start
338 324
      # currently no way to get here since there is no way to specify multiple
@@ -352,7 +338,25 @@
Loading
352 338
        "contact maintainer"
353 339
      )
354 340
      # nocov end
355 -
  } }
341 +
    }
342 +
    if(!is.null(test.dir)) {
343 +
      dir.set <- try(setwd(test.dir))
344 +
      if(inherits(dir.set, 'try-error')) {
345 +
        # nocov start there really shouldn't be a way to trigger this warning
346 +
        test.dir.err <-
347 +
          if(!is.chr1(test.dir)) "<not character(1L)>" else test.dir
348 +
        warning(
349 +
          word_wrap(collapse="\n",
350 +
            cc(
351 +
              "Working directory state tracking is in mode 2, but we ",
352 +
              "failed setting director to '", test.dir.err, "' so we are  ",
353 +
              "leaving the working directory unchanged."
354 +
          ) ),
355 +
          immediate.=TRUE
356 +
        )
357 +
        # nocov end
358 +
    } }
359 +
  }
356 360
  # - Parse / Load -------------------------------------------------------------
357 361
358 362
  # Handle pre-load data

@@ -290,10 +290,10 @@
Loading
290 290
    to.up.ids <- vapply(as.list(unitizers)[up.rev], slot, '', 'best.name')
291 291
    meta_word_cat(
292 292
      paste0(
293 -
        "\nThe following unitizer", if(many) "s", " will be upgrade to ",
293 +
        "\nThe following unitizer", if(many) "s", " will be upgraded to ",
294 294
        "version '", as.character(packageVersion('unitizer')), "':\n"
295 295
      ),
296 -
      as.character(UL(paste0(to.up.ids, " (at '", upgraded[up.rev], "'"))),
296 +
      as.character(UL(paste0(to.up.ids, " (at '", upgraded[up.rev], "')"))),
297 297
      width=getOption("width") - 2L
298 298
    )
299 299
    if(!interactive.mode) invokeRestart("unitizerInteractiveFail")

@@ -83,9 +83,10 @@
Loading
83 83
#'     added a test in the middle of the file that uses the random seed).
84 84
#'   \item Working Directory: can be set to the tests directory
85 85
#'     inside the package directory if the test files appear to be inside the
86 -
#'     folder structure of a package.  This mimics R CMD check behavior.  If
87 -
#'     test files are not inside a package directory structure then can be set
88 -
#'     to the test files' directory.
86 +
#'     folder structure of a package, and the test file does not appear to be
87 +
#'     run as part of a check run (e.g. R CMD check,
88 +
#'     `tools::testInstalledPakage`).  If test files are not inside a package
89 +
#'     directory structure then can be set to the test files' directory.
89 90
#'   \item Search Path: can be set to what you would
90 91
#'     typically find in a freshly loaded vanilla R session.  This means any non
91 92
#'     default packages that are loaded when you run your tests are unloaded
Files Coverage
R 91.69%
Project Totals (43 files) 91.69%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading