1# 2# test-debugger.R 3# 4# Copyright (C) 2021 by RStudio, PBC 5# 6# Unless you have received this program directly from RStudio pursuant 7# to the terms of a commercial license agreement with RStudio, then 8# this program is licensed to you under the terms of version 3 of the 9# GNU Affero General Public License. This program is distributed WITHOUT 10# ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12# AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13# 14# 15 16library(testthat) 17 18context("debugger") 19 20test_that("deparsing large calls is not overly expensive", { 21 22 # call including large data.frame 23 big <- data.frame(x = as.numeric(1:1E5)) 24 cl <- call("dummy", big) 25 summary <- .rs.callSummary(cl) 26 expect_true(nchar(summary) < 1000) 27 28 # call including large vector 29 data <- as.list(0:200) 30 data[[1L]] <- as.name("c") 31 cl <- as.call(data) 32 summary <- .rs.callSummary(cl) 33 expect_equal(summary, "c(...)") 34 35 # call including large data.frame should be described quickly 36 big <- mtcars[rep.int(1, 1E5)] 37 bigcall <- call("dummy", x = big) 38 time <- system.time(.rs.describeObject(environment(), "bigcall")) 39 expect_true(time[1] < 1) 40 41}) 42 43test_that("we successfully parse the function name from different calls", { 44 45 # regular old call 46 cl <- call("eval", quote(1 + 1)) 47 expect_equal(.rs.functionNameFromCall(cl), "eval") 48 49 # function directly in call object 50 cl <- quote(c(1, 2, 3)) 51 cl[[1L]] <- c 52 expect_equal(.rs.functionNameFromCall(cl), "[Anonymous function]") 53 54}) 55 56test_that("function calls are not mangled into something un-printable", { 57 58 cl <- call("function", pairlist(a = 1, b = 2, c = 3), quote({})) 59 sanitized <- .rs.sanitizeCall(cl) 60 expect_equal(cl, sanitized) 61 62}) 63