Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
LudvigOlsen committed Mar 15, 2020
2 parents a4dc0dd + a4e914d commit 86380ac
Show file tree
Hide file tree
Showing 40 changed files with 2,204 additions and 246 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ matrix:
after_success:
- Rscript -e 'covr::codecov()'
- r: release
name: tidyr-devel
before_script: Rscript -e "remotes::install_github('tidyverse/tidyr')"
name: pgk-devs-devel
before_script:
- Rscript -e "remotes::install_github(paste0('tidyverse/', c('tibble','dplyr')))"
- Rscript -e "remotes::install_github(paste0('mllg/', c('checkmate')))"
- r: release
os: osx
name: release osx
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: xpectr
Title: Generates Expectations for 'testthat' Unit Testing
Version: 0.1.1.9000
Version: 0.2.0
Authors@R:
c(person(given = "Ludvig Renbo",
family = "Olsen",
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export(element_lengths)
export(element_types)
export(gxs_function)
export(gxs_selection)
export(initializeGXSFunctionAddin)
export(initializeTestthatAddin)
export(insertExpectationsAddin)
export(message_if)
export(num_total_elements)
Expand Down
12 changes: 11 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# xpectr 0.1.1.9000
# xpectr 0.2.0

* Adds `initializeGXSFunctionAddin()` addin for initializing a `gxs_function()` call for a selected function.

* Adds `initializeTestthatAddin()` addin for inserting `testthat::test_that()` chunk.

* `gxs_function()` gets argument `extra_combinations` for manually adding extra combinations of argument values. In some simple cases, this can help us avoid multiple calls to `gxs_function()` with different baseline values.

* The `Changed from baseline:` comment adds the changed value when only one argument was changed. This makes it faster to see what is tested.

* Tests are now properly ordered as the specified `args_values`.

# xpectr 0.1.1

Expand Down
51 changes: 41 additions & 10 deletions R/assert_collection_addin.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@

#' @title Inserts code for a checkmate assert collection
#' @description RStudio Addin:
#' Inserts code for initializing and reporting a
#' \code{\link[checkmate:AssertCollection]{checkmate assert collection}}.
#' @description
#' \Sexpr[results=rd, stage=render]{lifecycle::badge("experimental")}
#'
#' RStudio Addin:
#' Inserts code for initializing and reporting a
#' \code{\link[checkmate:AssertCollection]{checkmate assert collection}}.
#'
#' See \code{Details} for how to set a key command.
#' @param add_comments Whether to add comments around. (Logical)
#'
#' This makes it easy for a user to create their own addin without the comments.
#' @param indentation Indentation of the code. (Numeric)
#'
#' \strong{N.B.} Mainly intended for testing the addin programmatically.
#' @param insert Whether to insert the code via
#' \code{\link[rstudioapi:insertText]{rstudioapi::insertText()}}
#' or return it. (Logical)
#'
#' \strong{N.B.} Mainly intended for testing the addin programmatically.
#' @author Ludvig Renbo Olsen, \email{r-pkgs@@ludvigolsen.dk}
#' @export
#' @family addins
Expand Down Expand Up @@ -36,17 +47,36 @@
#'
#' \code{Tools >> Addins >> Browse Addins >> Keyboard Shortcuts}.
#'
#' Find \code{"dput() Selected"} and press its field under \code{Shortcut}.
#' Find \code{"Insert checkmate AssertCollection Code"} and press its field under \code{Shortcut}.
#'
#' Press desired key command, e.g. \code{Alt+C}.
#'
#' Press \code{Apply}.
#'
#' Press \code{Execute}.
#' }
assertCollectionAddin <- function(add_comments = TRUE){
assertCollectionAddin <- function(add_comments = TRUE, insert = TRUE, indentation = NULL){

indentation <- get_indentation()
# Check arguments ####
assert_collection <- checkmate::makeAssertCollection()
checkmate::assert_flag(x = add_comments, add = assert_collection)
checkmate::assert_flag(x = insert, add = assert_collection)
checkmate::assert_integerish(x = indentation, lower = 0,
any.missing = FALSE,
null.ok = TRUE,
add = assert_collection)
checkmate::reportAssertions(assert_collection)
# End of argument checks ####

# Get the indentation
if (is.null(indentation)){
indentation <- tryCatch(
get_indentation(),
error = function(e) {
return(0)
}
)
}

to_insert <- c(
"assert_collection <- checkmate::makeAssertCollection()",
Expand All @@ -63,10 +93,11 @@ assertCollectionAddin <- function(add_comments = TRUE){
)
}

# Insert the code
insert_code(to_insert,
prepare = TRUE,
indentation = indentation)
if (isTRUE(insert)){
insert_code(to_insert, prepare = TRUE, indentation = indentation)
} else {
return(to_insert)
}

invisible()

Expand Down
20 changes: 14 additions & 6 deletions R/dput_addins.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@


#' @title Replaces selected code with its dput() output
#' @description RStudio Addin:
#' @description
#' \Sexpr[results=rd, stage=render]{lifecycle::badge("experimental")}
#'
#' RStudio Addin:
#' Runs \code{\link[base:dput]{dput()}} on the selected code and inserts
#' it instead of the selection.
#'
Expand Down Expand Up @@ -58,22 +61,27 @@ dputSelectedAddin <- function(selection = NULL, insert = TRUE, indentation = 0)
checkmate::assert_string(x = selection, null.ok = TRUE,
add = assert_collection)
checkmate::assert_flag(x = insert, add = assert_collection)
checkmate::assert_number(x = indentation, lower = 0,
add = assert_collection)
checkmate::assert_integerish(x = indentation, lower = 0,
any.missing = FALSE,
null.ok = TRUE,
add = assert_collection)
checkmate::reportAssertions(assert_collection)
# End of argument checks ####

# Get the selection and indentation
if (is.null(selection)){
selection <- get_selection()
indentation <- get_indentation()
selection <- tryCatch(get_selection(),
error = function(e){return("")},
message = function(m){return("")})
indentation <- tryCatch(get_indentation(),
error = function(e){return(0)})
}

# Get parent environment
parent_envir <- parent.frame()

# dput() and insert/return
if (selection != "") {
if (!is.null(selection) && selection != "") {
dput_out <- apply_capture(selection, dput, envir = parent_envir)

if (!isTRUE(insert)) {
Expand Down
2 changes: 0 additions & 2 deletions R/expectation_creators.R
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,6 @@ create_test_comment <- function(what, section = "test",
checkmate::reportAssertions(assert_collection)
# End of argument checks ####



if (indentation > 40){
warning("indentation > 40 characters is ignored.")
indentation <- 40
Expand Down
Loading

0 comments on commit 86380ac

Please sign in to comment.