Skip to content
Merged
Changes from 2 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
34 changes: 30 additions & 4 deletions tests/testthat/helper-valid_log.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,40 @@ expect_valid_log <- local({
stdout = TRUE,
stderr = TRUE
)

# "inst/test/inspect/logs/2025-03-24T10-39-36-05-00_simple-arithmetic_fQ9mYnqZFhtEuUenPpJgKL.json"
if (length(result) == 1) {
formatted_message <- cli::format_message(c(
"The generated log did not pass the pydantic model:",
glue::glue("{{.field {result[1]}}}")
))
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simplify this control flow, I am going to remove this else and then return early from the if condition.

# Get rid of elements starting with "For further information visit"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove most of these "what" comments in favor of one "why" comment

    # Make the result more readable by removing redundant elements
    # and formatting indices with cli (#159)

result <- result[!grepl("For further information visit", result)]
# Add .field CLI on the fields
result_length <- length(result)
field_positions <- seq(2, result_length, by = 2)

for (pos in field_positions) {
result[pos] <- glue::glue("{{.field {result[pos]}}}")
}

result_with_breaks <- result[1] # Start with first element
for (i in seq(2, length(result), by = 2)) {
result_with_breaks <- c(result_with_breaks, "", result[i:(i + 1)])
}

formatted_message <- cli::format_message(c(
"The generated log did not pass the pydantic model:",
"",
result_with_breaks
))
}
status <- attr(result, "status")

expect(
is.null(status) || status == 0,
paste0(
c("The generated log did not pass the pydantic model: ", result),
collapse = "\n"
)
formatted_message
)
}
})
Loading