From 13e53691bc42e39c8ee4a22342e573f8986caa6b Mon Sep 17 00:00:00 2001 From: brodieG Date: Wed, 22 Nov 2017 19:07:53 -0500 Subject: [PATCH 1/5] fix regression introduced when fixing 245 --- R/faux_prompt.R | 11 +++++++---- R/prompt.R | 7 ++++++- tests/testthat/testthat.misc.R | 13 ++++++++++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/R/faux_prompt.R b/R/faux_prompt.R index 77553f7f..e1e6476b 100644 --- a/R/faux_prompt.R +++ b/R/faux_prompt.R @@ -10,16 +10,19 @@ faux_prompt <- function( ) { res <- character() repeat { - res <- paste0(res, read_line(prompt), if(length(res)) '\n' else "") - res.parse <- tryCatch( - parsed <- parse(text=res), + res.parse <- tryCatch({ + res <- paste0(res, read_line(prompt), if(length(res)) '\n' else "") + parsed <- parse(text=res) + }, error=function(e) { if(!isTRUE(grepl(" unexpected end of input\n", conditionMessage(e)))) { - stop(simpleError(conditionMessage(e), res)) + e$call <- if(length(res)) res else NULL + stop(e) } } ) prompt <- `continue` if(is.expression(res.parse)) { return(res.parse) } } + NULL } diff --git a/R/prompt.R b/R/prompt.R index d393d7f4..21fe5dbc 100644 --- a/R/prompt.R +++ b/R/prompt.R @@ -113,7 +113,12 @@ unitizer_prompt <- function( prompt.txt <- sprintf("%s> ", "unitizer") old.opt <- options(warn=1) - val <- tryCatch(faux_prompt(prompt.txt), simpleError=function(e) e) + on.exit(options(old.opt)) + val <- tryCatch( + faux_prompt(prompt.txt), + simpleError=function(e) e + ) + on.exit(NULL) options(old.opt) if(inherits(val, "simpleError")) { diff --git a/tests/testthat/testthat.misc.R b/tests/testthat/testthat.misc.R index 51491617..d6eb2108 100644 --- a/tests/testthat/testthat.misc.R +++ b/tests/testthat/testthat.misc.R @@ -285,7 +285,7 @@ test_that("relativize_path", { c( as.list( rep( - "..", + "..", length( unlist(strsplit(getwd(), .Platform$file.sep, fixed=TRUE)) ) - 1L @@ -381,3 +381,14 @@ test_that("diff conditionList", { ) ) expect_is(diffobj::diffObj(cond1, cond1), "Diff") }) + +test_that("Condition object structure", { + # We're assuming a particular structure for the condition object in + # `faux_prompt` and `unitizer_prompt` so we put in a test here to make sure it + # doesn't change + + cond <- simpleError('hello') + expect_true(is.list(cond)) + expect_true(identical(names(cond), c('message', 'call'))) + expect_true(identical(class(cond), c('simpleError', 'error', 'condition'))) +}) From d2e51c9ee09dc5d105a0fde039dbe601d8a4696c Mon Sep 17 00:00:00 2001 From: brodieG Date: Thu, 23 Nov 2017 13:47:06 -0500 Subject: [PATCH 2/5] change dir to pkg dir --- R/get.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/R/get.R b/R/get.R index 5cfe5914..390e79fd 100644 --- a/R/get.R +++ b/R/get.R @@ -309,6 +309,13 @@ infer_unitizer_location.character <- function( if(!(identical(type, "d") && at.package.dir) && test.fun(store.id)) return(store.id) + # If we're not at the package directory, check to see if we are in a package + # directory and change directory to that + + if(!at.package.dir && length(pkg.dir.tmp <- get_package_dir(dir.store.id))) { + at.package.dir <- TRUE + dir.store.id <- pkg.dir.tmp + } if(at.package.dir) { test.base <- file.path(dir.store.id, "tests", "unitizer") if(!file_test("-d", test.base)) From 383ab199cb50da1304cb79ac99d0bcbfcadb4c0d Mon Sep 17 00:00:00 2001 From: brodieG Date: Thu, 23 Nov 2017 14:17:56 -0500 Subject: [PATCH 3/5] fix not-in-tests case --- R/get.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/get.R b/R/get.R index 390e79fd..140dec4a 100644 --- a/R/get.R +++ b/R/get.R @@ -310,9 +310,13 @@ infer_unitizer_location.character <- function( return(store.id) # If we're not at the package directory, check to see if we are in a package - # directory and change directory to that + # directory and change directory to that, but only do that if we're not + # already matching an actual directory - if(!at.package.dir && length(pkg.dir.tmp <- get_package_dir(dir.store.id))) { + if( + !at.package.dir && !is.null(file.store.id) && + length(pkg.dir.tmp <- get_package_dir(dir.store.id)) + ) { at.package.dir <- TRUE dir.store.id <- pkg.dir.tmp } From d819e1aeeb7bc1abfe3ec3dfcfed97e83e6c9e36 Mon Sep 17 00:00:00 2001 From: brodieG Date: Thu, 23 Nov 2017 14:39:56 -0500 Subject: [PATCH 4/5] add tests for 225 --- tests/testthat/testthat.get.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/testthat/testthat.get.R b/tests/testthat/testthat.get.R index 278fa236..43c716dc 100644 --- a/tests/testthat/testthat.get.R +++ b/tests/testthat/testthat.get.R @@ -385,6 +385,11 @@ local({ infer(file.path(base.dir2, "z"), type="u"), "tests/unitizer/zzz\\.unitizer$" ) + # Random file without setting working dir first + + f.test2 <- infer('tests2') + expect_match(f.test2, "unitizer/tests2.R$") + # Interactive mode unitizer:::read_line_set_vals(c("26", "Q")) From cc392dc342236673c4ab2fafc7eddbc0b7597f7c Mon Sep 17 00:00:00 2001 From: brodieG Date: Thu, 23 Nov 2017 14:40:56 -0500 Subject: [PATCH 5/5] NEWS --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 29380a50..9d30e2b8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,8 @@ ## v1.4.5 * Colors in test browser working again. +* [#225](https://github.com/brodieG/unitizer/issues/225) Inferring file + locations when not in pkg top level. * [#237](https://github.com/brodieG/unitizer/issues/237) Option to turn off diffs. * [#239](https://github.com/brodieG/unitizer/issues/239) Document issues with