Skip to content

Commit

Permalink
Cleaned up tests for #60. Good luck Jeff!
Browse files Browse the repository at this point in the history
  • Loading branch information
richelbilderbeek committed Sep 2, 2021
1 parent ace6e75 commit 8dcab06
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
3 changes: 3 additions & 0 deletions R/check_beast2_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ check_beast2_options_data_types <- function( # nolint long function name indeed,
if (!beautier::is_one_bool(beast2_options$verbose)) {
stop("'verbose' must be one boolean")
}
# Isse 60, Issue #60
# Hi Jeff, I suggest to add 'check_stack_size_kb' here.
# I have written the tests for you at 'test-check_stack_size_kb' :-)
}

#' Check if the filenames in \code{beast2_options} differ
Expand Down
39 changes: 39 additions & 0 deletions tests/testthat/test-check_stack_size_kb.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
test_that("use", {
skip("Fix Issue 60, Fix Issue #60")
# Hi Jeff, here I suggest to add 'check_stack_size_kb',
# you will probably get the same idea after
# reading 'check_beast2_options_data_types'
expect_silent(check_stack_size_kb(stack_size_kb = 1234))
expect_error(
check_stack_size_kb(stack_size_kb = 0),
"'stack_size_kb' must be one non-zero, finite and positive number"
)
expect_error(
check_stack_size_kb(stack_size_kb = -1234),
"'stack_size_kb' must be one non-zero, finite and positive number"
)
expect_error(
check_stack_size_kb(stack_size_kb = NA),
"'stack_size_kb' must be one non-zero, finite and positive number"
)
expect_error(
check_stack_size_kb(stack_size_kb = "nonsense"),
"'stack_size_kb' must be one non-zero, finite and positive number"
)
expect_error(
check_stack_size_kb(stack_size_kb = NULL),
"'stack_size_kb' must be one non-zero, finite and positive number"
)
expect_error(
check_stack_size_kb(stack_size_kb = Inf),
"'stack_size_kb' must be one non-zero, finite and positive number"
)
expect_error(
check_stack_size_kb(stack_size_kb = c()),
"'stack_size_kb' must be one non-zero, finite and positive number"
)
expect_error(
check_stack_size_kb(stack_size_kb = c(1, 2)),
"'stack_size_kb' must be one non-zero, finite and positive number"
)
})
3 changes: 2 additions & 1 deletion tests/testthat/test-create_beast2_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("use", {

test_that("increase stack space", {
expect_equal(1 + 1, 2) # nolint to prevent 'Reason: empty test'
skip("Issue 60")
skip("Issue 60, Issue #60")
# Result in same behavior
expect_silent(
create_beast2_options(
Expand All @@ -18,6 +18,7 @@ test_that("increase stack space", {
)
)
# Must be positive
# Note that the exact error message is tested in 'test-check_stack_size_kb'
expect_error(
create_beast2_options(
stack_size_kb = -1234567
Expand Down
23 changes: 12 additions & 11 deletions tests/testthat/test-create_beast2_run_cmd.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,33 @@ test_that("minimal use", {
)
})

test_that("minimal use", {
expect_equal(1 + 1, 2) # nolint to prevent 'Reason: empty test'
skip("Issue 60")
test_that("use of 'stack_size_kb'", {

# This is existing behavior
cmd <- create_beast2_run_cmd(
input_filename = "something",
input_filename = get_beastier_path("2_4.xml"), # actual file is irrelevant
output_state_filename = "something"
)
expect_equal(0, stringr::str_count(string = cmd, pattern = "-Xss"))
expect_equal(0, length(stringr::str_subset(string = cmd, pattern = "-Xss")))

skip("Issue 60")

cmd <- create_beast2_run_cmd(
input_filename = "something",
output_state_filename = "something",
input_filename = get_beastier_path("2_4.xml"), # actual file is irrelevant
output_state_filename = "something",
stack_size_kb = 2000
)
expect_equal(1, stringr::str_count(string = cmd, pattern = "-Xss"))
expect_true("-Xss2000k" %in% cmd)
expect_equal(1, length(stringr::str_subset(string = cmd, pattern = "-Xss")))
expect_true("-Xss2000k" %in% cmd)


cmd <- create_beast2_run_cmd(
input_filename = "something",
output_state_filename = "something",
stack_size_kb = 1234
)
expect_equal(1, stringr::str_count(string = cmd, pattern = "-Xss"))
expect_true("-Xss1234k" %in% cmd)
expect_equal(1, length(stringr::str_subset(string = cmd, pattern = "-Xss")))
expect_true("-Xss1234k" %in% cmd)

})

Expand Down

0 comments on commit 8dcab06

Please sign in to comment.