From 368fef08fb968eddfb8e05c7be19d441ddc052a6 Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 12 Dec 2024 10:10:09 -0500 Subject: [PATCH] Replace crayon by cli + address some TODOs to add some color --- DESCRIPTION | 3 +-- R/conditions.R | 6 +++--- R/test.R | 8 +++----- tests/testthat/test-test-runTests.R | 2 +- tests/testthat/test-test-server-app.R | 4 ++-- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 11a6c31bf7..87db6224a1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -85,7 +85,7 @@ Imports: later (>= 1.0.0), promises (>= 1.3.2), tools, - crayon, + cli, rlang (>= 0.4.10), fastmap (>= 1.1.1), withr, @@ -210,7 +210,6 @@ Collate: RoxygenNote: 7.3.2 Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RdMacros: lifecycle Config/testthat/edition: 3 Config/Needs/check: shinytest2 diff --git a/R/conditions.R b/R/conditions.R index 164792a8de..241f6403a5 100644 --- a/R/conditions.R +++ b/R/conditions.R @@ -417,11 +417,11 @@ printOneStackTrace <- function(stackTrace, stripResult, full, offset) { ": ", mapply(paste0(st$call, st$loc), st$category, FUN = function(name, category) { if (category == "pkg") - crayon::silver(name) + cli::col_silver(name) else if (category == "user") - crayon::blue$bold(name) + cli::style_bold(cli::col_blue(name)) else - crayon::white(name) + cli::col_white(name) }), "\n" ) diff --git a/R/test.R b/R/test.R index 98b5ce7326..bad1bf1082 100644 --- a/R/test.R +++ b/R/test.R @@ -158,8 +158,7 @@ print.shiny_runtests <- function(x, ..., reporter = "summary") { if (any(x$pass)) { - # TODO in future... use clisymbols::symbol$tick and crayon green - cat("* Success\n") + cli::cat_bullet("Success", bullet = "tick", bullet_col = "green") mapply( x$file, x$pass, @@ -171,9 +170,8 @@ print.shiny_runtests <- function(x, ..., reporter = "summary") { } ) } - if (any(!x$pass)) { - # TODO in future... use clisymbols::symbol$cross and crayon red - cat("* Failure\n") + if (!all(x$pass)) { + cli::cat_bullet("Failure", bullet = "cross", bullet_col = "red") mapply( x$file, x$pass, diff --git a/tests/testthat/test-test-runTests.R b/tests/testthat/test-test-runTests.R index 159060cd67..c42fd0a6cc 100644 --- a/tests/testthat/test-test-runTests.R +++ b/tests/testthat/test-test-runTests.R @@ -122,7 +122,7 @@ test_that("runTests runs as expected without rewiring", { appDir <- test_path(file.path("..", "test-helpers", "app1-standard")) df <- testthat::expect_output( print(runTests(appDir = appDir, assert = FALSE)), - "Shiny App Test Results\\n\\* Success\\n - app1-standard/tests/runner1\\.R\\n - app1-standard/tests/runner2\\.R" + "Shiny App Test Results\\n\\v Success\\n - app1-standard/tests/runner1\\.R\\n - app1-standard/tests/runner2\\.R" ) expect_equal(df, data.frame( diff --git a/tests/testthat/test-test-server-app.R b/tests/testthat/test-test-server-app.R index 4c6a364bde..cab7dff7cf 100644 --- a/tests/testthat/test-test-server-app.R +++ b/tests/testthat/test-test-server-app.R @@ -41,7 +41,7 @@ test_that("runTests works with a dir app that calls modules and uses testServer" app <- test_path("..", "test-modules", "12_counter") run <- testthat::expect_output( print(runTests(app)), - "Shiny App Test Results\\n\\* Success\\n - 12_counter/tests/testthat\\.R" + "Shiny App Test Results\\n\\v Success\\n - 12_counter/tests/testthat\\.R" ) expect_true(all(run$pass)) }) @@ -50,7 +50,7 @@ test_that("runTests works with a dir app that calls modules that return reactive app <- test_path("..", "test-modules", "107_scatterplot") run <- testthat::expect_output( print(runTests(app)), - "Shiny App Test Results\\n\\* Success\\n - 107_scatterplot/tests/testthat\\.R" + "Shiny App Test Results\\n\\v Success\\n - 107_scatterplot/tests/testthat\\.R" ) expect_true(all(run$pass)) })