Skip to content

Commit

Permalink
Update check_testthat.R
Browse files Browse the repository at this point in the history
  • Loading branch information
cansavvy committed Jul 1, 2024
1 parent 7a06ddd commit 8244b8f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
1 change: 0 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

- name: Check testthat
if: runner.os != 'Windows'
id: check_check
run: |
error_num=$(Rscript --vanilla '.github/workflows/check_testthat.R')
Expand Down
29 changes: 23 additions & 6 deletions .github/workflows/check_testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,38 @@ library(magrittr)
# Find .git root directory
root_dir <- rprojroot::find_root(rprojroot::has_dir(".git"))

# Read in the testthat results
out_file <- list.files(pattern = "testthat.Rout$|Rout.fail$", file.path(root_dir, "check"),
recursive = TRUE, full.names = TRUE)

check_content <- readLines(out_file)
test_result <- grep("\\[ FAIL", check_content, value = TRUE)[1]
test_result <- unlist(strsplit(test_result, "\\||\\[|\\]"))
# Extract testhat results
testthat_check_content <- readLines(out_file)
testthat_result <- grep("\\[ FAIL", testthat_check_content, value = TRUE)[1]
testthat_result <- unlist(strsplit(testthat_result, "\\||\\[|\\]"))

# Read in standard check results
check_content <- readLines(file.path(root_dir, "check", "ottrpal.Rcheck", "00check.log"))

# Extract standard check results
check_result <- grep("Status\\:", check_content, value = TRUE)
check_result <- unlist(strsplit(check_result, ","))
check_result <- stringr::str_remove(check_result, "Status:| ")

# Format the data into a dataframe
test_result_df <- data.frame(result = trimws(test_result)) %>%
testthat_result_df <- data.frame(result = trimws(testthat_result)) %>%
dplyr::filter(result != "") %>%
tidyr::separate(result, sep = " ", into = c("test_name", "num")) %>%
dplyr::mutate(num = as.numeric(num))

fail_num <- test_result_df %>%
dplyr::filter(test_name %in% c("FAIL", "WARN")) %>%
# Do the same for the check results
check_result_df <- data.frame(result = trimws(check_result)) %>%
tidyr::separate(result, sep = " ", into = c("num", "test_name")) %>%
dplyr::mutate(num = as.numeric(num)) %>%
dplyr::select("test_name", "num")

# We only want warnings or errors or fails
fail_num <- dplyr::bind_rows(check_result_df, testthat_result_df) %>%
dplyr::filter(test_name %in% c("FAIL", "WARN", "WARNINGs", "ERROR")) %>%
dplyr::summarize(total = sum(num))

fail_num <- as.character(fail_num$total)
Expand Down

0 comments on commit 8244b8f

Please sign in to comment.