From f97b41c16a57eedd15b8b667ce0c1a13ff046ee7 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Sun, 18 Dec 2022 00:04:05 +0100 Subject: [PATCH 1/2] Reorganize tests for `unneeded_concatenation_linter()` Follow the skip vs block pattern in tests layout --- .../test-unneeded_concatenation_linter.R | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/tests/testthat/test-unneeded_concatenation_linter.R b/tests/testthat/test-unneeded_concatenation_linter.R index 476c36be9..ffe647d01 100644 --- a/tests/testthat/test-unneeded_concatenation_linter.R +++ b/tests/testthat/test-unneeded_concatenation_linter.R @@ -1,9 +1,5 @@ -test_that("returns the correct linting", { +test_that("unneeded_concatenation_linter skips allowed usages", { linter <- unneeded_concatenation_linter() - msg_c <- rex::escape("Unneeded concatenation of a constant. Remove the \"c\" call.") - msg_e <- rex::escape( - "Unneeded concatenation without arguments. Replace the \"c\" call by NULL or, whenever possible, vector()" - ) expect_lint("c(x)", NULL, linter) expect_lint("c(1, 2)", NULL, linter) @@ -12,11 +8,33 @@ test_that("returns the correct linting", { expect_lint("lapply(1, c)", NULL, linter) expect_lint("c(a = 1)", NULL, linter) expect_lint("c('a' = 1)", NULL, linter) +}) - expect_lint("c()", list(message = msg_e, line_number = 1L, column_number = 1L), linter) - expect_lint("c(NULL)", list(message = msg_c, line_number = 1L, column_number = 1L), linter) - expect_lint("c(1)", list(message = msg_c, line_number = 1L, column_number = 1L), linter) - expect_lint("c (\n'a' )", list(message = msg_c, line_number = 1L, column_number = 1L), linter) +test_that("unneeded_concatenation_linter blocks disallowed usages", { + linter <- unneeded_concatenation_linter() + msg_c <- rex::escape("Unneeded concatenation of a constant. Remove the \"c\" call.") + msg_e <- rex::escape("Unneeded concatenation without arguments. Replace the \"c\" call by NULL") + + expect_lint( + "c()", + list(message = msg_e, line_number = 1L, column_number = 1L), + linter + ) + expect_lint( + "c(NULL)", + list(message = msg_c, line_number = 1L, column_number = 1L), + linter + ) + expect_lint( + "c(1)", + list(message = msg_c, line_number = 1L, column_number = 1L), + linter + ) + expect_lint( + "c (\n'a' )", + list(message = msg_c, line_number = 1L, column_number = 1L), + linter + ) expect_lint( "c(y, c('c('),\nc())", list( From 6f441de44ac8efab227c753c9a0e1958cf906882 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sat, 17 Dec 2022 15:47:59 -0800 Subject: [PATCH 2/2] avoid escapes --- tests/testthat/test-unneeded_concatenation_linter.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-unneeded_concatenation_linter.R b/tests/testthat/test-unneeded_concatenation_linter.R index ffe647d01..d570fac70 100644 --- a/tests/testthat/test-unneeded_concatenation_linter.R +++ b/tests/testthat/test-unneeded_concatenation_linter.R @@ -12,8 +12,8 @@ test_that("unneeded_concatenation_linter skips allowed usages", { test_that("unneeded_concatenation_linter blocks disallowed usages", { linter <- unneeded_concatenation_linter() - msg_c <- rex::escape("Unneeded concatenation of a constant. Remove the \"c\" call.") - msg_e <- rex::escape("Unneeded concatenation without arguments. Replace the \"c\" call by NULL") + msg_c <- rex::escape('Unneeded concatenation of a constant. Remove the "c" call.') + msg_e <- rex::escape('Unneeded concatenation without arguments. Replace the "c" call by NULL') expect_lint( "c()",