Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"permissions": {
"allow": [
"Bash(find:*)"
"Bash(find:*)",
"Bash(R:*)"
],
"deny": []
}
},
"$schema": "https://json.schemastore.org/claude-code-settings.json"
}
16 changes: 8 additions & 8 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ testthat is R's most popular unit testing framework, used by thousands of CRAN p

## Key Development Commands

### Testing
- `devtools::test()` or `Ctrl/Cmd+Shift+T` in RStudio - Run all tests
- `devtools::test_file("tests/testthat/test-filename.R")` - Run tests in a specific file
- `testthat::test_local()` - Run tests for local source package
- `testthat::test_package("testthat")` - Run tests for installed package
- `R CMD check` - Full package check including tests
General advice:
* When running R from the console, always run it with `--quiet --vanilla`
* Always run `air format .` after generating code

### Development tools

### Building and Installation
- `devtools::load_all()` or `Ctrl/Cmd+Shift+L` - Load package for development
- `devtools::test()` - Run all tests
- `devtools::test_file("tests/testthat/test-filename.R")` - Run tests in a specific file
- `devtools::load_all()` - Load package for development
- `devtools::document()` - Generate documentation
- `devtools::check()` - Run R CMD check
- `devtools::install()` - Install package locally
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# testthat (development version)

* `JunitReporter()` no longer fails with `"no applicable method for xml_add_child"` for warnings outside of tests (#1913). Additionally, warnings now save their backtraces.
* `JunitReporter()` strips ANSI escapes in more placese (#1852, #2032).
* `try_again()` is now publicised. The first argument is now the number of retries, not tries (#2050).
* `vignette("custom-expectations)` has been overhauled to make it much clearer how to create high-quality expectations (#2113, #2132, #2072).
Expand Down
8 changes: 8 additions & 0 deletions R/reporter-junit.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ JunitReporter <- R6::R6Class(
time <- self$elapsed_time()
self$suite_time <- self$suite_time + time

# If no context was started (e.g., warnings outside tests), create a default one
if (is.null(self$suite)) {
self$start_context(context %||% "(unknown)")
}

# XML node for test case
name <- test %||% "(unnamed)"
testcase <- xml2::xml_add_child(
Expand Down Expand Up @@ -147,6 +152,9 @@ JunitReporter <- R6::R6Class(
} else if (expectation_skip(result)) {
xml2::xml_add_child(testcase, "skipped", message = first_line(result))
self$skipped <- self$skipped + 1
} else if (expectation_warning(result)) {
warning_node <- xml2::xml_add_child(testcase, "system-out")
xml2::xml_text(warning_node) <- cli::ansi_strip(format(result))
}
},

Expand Down
7 changes: 6 additions & 1 deletion tests/testthat/_snaps/reporter-junit.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@
</testcase>
</testsuite>
<testsuite name="Warnings" timestamp="1999:12:31 23:59:59" hostname="nodename" tests="2" skipped="1" failures="0" errors="0" time="0">
<testcase time="0" classname="Warnings" name="warnings_get_backtraces"/>
<testcase time="0" classname="Warnings" name="warnings_get_backtraces">
<system-out>def
Backtrace:
x
1. \-f()</system-out>
</testcase>
<testcase time="0" classname="Warnings" name="warnings_get_backtraces">
<skipped message="Reason: empty test ('reporters/tests.R:44:1')"/>
</testcase>
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-reporter-junit.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,17 @@ test_that("ANSI escapes are stripped from all user text in XML", {

expect_no_error(xml2::read_xml(tmp))
})

test_that("warnings outside context don't cause xml_add_child errors", {
skip_if_not_installed("xml2")

tmp <- withr::local_tempfile(fileext = ".xml")
reporter <- JunitReporterMock$new(file = tmp)
reporter$start_reporter()

# This would previously fail with "no applicable method for 'xml_add_child'"
expect_no_error({
reporter$add_result(NULL, "test", new_expectation("warning", "test"))
})
reporter$end_reporter()
})
Loading