Skip to content

Commit 8b1f568

Browse files
committed
only assemble message on failure (#159)
1 parent 613352c commit 8b1f568

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

tests/testthat/helper-valid_log.R

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,21 @@ expect_valid_log <- local({
7070

7171
status <- attr(result, "status")
7272

73-
# "inst/test/inspect/logs/2025-03-24T10-39-36-05-00_simple-arithmetic_fQ9mYnqZFhtEuUenPpJgKL.json"
74-
if (length(result) == 1) {
75-
formatted_message <- cli::format_message(c(
76-
"The generated log did not pass the pydantic model:",
77-
glue::glue("{{.field {result[1]}}}")
78-
))
79-
expect(
80-
is.null(status) || status == 0,
81-
formatted_message
82-
)
83-
}
73+
expect(
74+
is.null(status) || status == 0,
75+
formatted_pydantic_error(result)
76+
)
77+
}
78+
})
8479

80+
formatted_pydantic_error <- function(result) {
81+
# "inst/test/inspect/logs/2025-03-24T10-39-36-05-00_simple-arithmetic_fQ9mYnqZFhtEuUenPpJgKL.json"
82+
if (length(result) == 1) {
83+
formatted_message <- cli::format_message(c(
84+
"The generated log did not pass the pydantic model:",
85+
glue::glue("{{.field {result[1]}}}")
86+
))
87+
} else {
8588
# Make the result more readable by removing redundant elements
8689
# and formatting indices with cli (#159)
8790
result <- result[!grepl("For further information visit", result)]
@@ -102,10 +105,5 @@ expect_valid_log <- local({
102105
"",
103106
result_with_breaks
104107
))
105-
106-
expect(
107-
is.null(status) || status == 0,
108-
formatted_message
109-
)
110108
}
111-
})
109+
}

0 commit comments

Comments
 (0)