Skip to content

Commit

Permalink
Differentiate between first and subsequent entries for the same funct…
Browse files Browse the repository at this point in the history
…ion (#44)
  • Loading branch information
krlmlr authored Feb 17, 2021
1 parent e0e1169 commit 8c91a38
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions R/debug.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ debug <- function(msg, pkg = environmentName(topenv(parent.frame()))) {

if (tolower(Sys.getenv("DEBUGME_SHOW_STACK", "yes")) != "no") {
level <- update_debug_call_stack_and_compute_level()
continuation <- isTRUE(attr(level, "continuation"))
if (level > 0) {
indent <- paste0(
c(" " , rep(" ", (level - 1) * 2), "+-"),
c(" " , rep(" ", (level - 1) * 2), if (continuation) " -" else "+-"),
collapse = "")
}
}
Expand Down Expand Up @@ -81,8 +82,13 @@ update_debug_call_stack_and_compute_level <- function() {
frames <- sys.frames()

for (call in debug_data$debug_call_stack) {
if (call$nframe < nframe &&
if (call$nframe <= nframe &&
call$id == env_address(frames[[call$nframe]])) {

if (call$nframe == nframe) {
return(structure(call$level, continuation = TRUE))
}

level <- call$level + 1L
break
}
Expand All @@ -101,7 +107,7 @@ update_debug_call_stack_and_compute_level <- function() {
debug_data$debug_call_stack <- list(call)
}

level
structure(level, continuation = FALSE)
}


Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-debug.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ test_that("debug indent", {
expect_match(out, 'debugme +-f1', fixed = TRUE)
expect_match(out, 'debugme +-f2.1', fixed = TRUE)
expect_match(out, 'debugme +-f3', fixed = TRUE)
expect_match(out, 'debugme +-f2.2', fixed = TRUE)
expect_match(out, 'debugme -f2.2', fixed = TRUE)
expect_match(out, 'debugme +-f2.1', fixed = TRUE)
expect_match(out, 'debugme +-f2.2', fixed = TRUE)
expect_match(out, 'debugme -f2.2', fixed = TRUE)
expect_match(out, 'debugme f0.2', fixed = TRUE)

out <- withr::with_envvar(
Expand Down

0 comments on commit 8c91a38

Please sign in to comment.