|
| 1 | +## ---- description_authors ---- |
| 2 | + |
| 3 | +test_that("description_authors extracts names from local DESCRIPTION", { |
| 4 | + testthat::skip_if_not_installed("desc") |
| 5 | + desc_path <- system.file("DESCRIPTION", package = "echogithub") |
| 6 | + testthat::skip_if(desc_path == "", message = "echogithub not installed") |
| 7 | + d <- desc::desc(desc_path) |
| 8 | + res <- echogithub:::description_authors(desc_file = d, |
| 9 | + names_only = TRUE, |
| 10 | + verbose = FALSE) |
| 11 | + testthat::expect_true(is.character(res)) |
| 12 | + testthat::expect_true(nchar(res) > 0) |
| 13 | + ## Should contain the known first author |
| 14 | + testthat::expect_true(grepl("Brian", res)) |
| 15 | + testthat::expect_true(grepl("Schilder", res)) |
| 16 | +}) |
| 17 | + |
| 18 | +test_that("description_authors returns full author info when names_only=FALSE", { |
| 19 | + testthat::skip_if_not_installed("desc") |
| 20 | + desc_path <- system.file("DESCRIPTION", package = "echogithub") |
| 21 | + testthat::skip_if(desc_path == "", message = "echogithub not installed") |
| 22 | + d <- desc::desc(desc_path) |
| 23 | + res <- echogithub:::description_authors(desc_file = d, |
| 24 | + names_only = FALSE, |
| 25 | + verbose = FALSE) |
| 26 | + testthat::expect_true(is.character(res)) |
| 27 | + ## Should have email or role info when names_only=FALSE |
| 28 | + testthat::expect_true(nchar(res) > 0) |
| 29 | +}) |
| 30 | + |
| 31 | +test_that("description_authors with add_html=TRUE wraps in HTML tags", { |
| 32 | + testthat::skip_if_not_installed("desc") |
| 33 | + desc_path <- system.file("DESCRIPTION", package = "echogithub") |
| 34 | + testthat::skip_if(desc_path == "", message = "echogithub not installed") |
| 35 | + d <- desc::desc(desc_path) |
| 36 | + res <- echogithub:::description_authors(desc_file = d, |
| 37 | + names_only = TRUE, |
| 38 | + add_html = TRUE, |
| 39 | + verbose = FALSE) |
| 40 | + testthat::expect_true(grepl("<h4>", res)) |
| 41 | + testthat::expect_true(grepl("<i>", res)) |
| 42 | + testthat::expect_true(grepl("Authors:", res)) |
| 43 | +}) |
| 44 | + |
| 45 | +test_that("description_authors returns collapsed string for multiple authors", { |
| 46 | + testthat::skip_if_not_installed("desc") |
| 47 | + desc_path <- system.file("DESCRIPTION", package = "echogithub") |
| 48 | + testthat::skip_if(desc_path == "", message = "echogithub not installed") |
| 49 | + d <- desc::desc(desc_path) |
| 50 | + res <- echogithub:::description_authors(desc_file = d, |
| 51 | + names_only = TRUE, |
| 52 | + verbose = FALSE) |
| 53 | + ## echogithub has multiple authors, so there should be a comma separator |
| 54 | + testthat::expect_true(grepl(",", res)) |
| 55 | +}) |
| 56 | + |
| 57 | +## ---- description_extract_i ---- |
| 58 | + |
| 59 | +test_that("description_extract_i extracts default fields", { |
| 60 | + testthat::skip_if_not_installed("desc") |
| 61 | + testthat::skip_if_not_installed("rworkflows") |
| 62 | + desc_path <- system.file("DESCRIPTION", package = "echogithub") |
| 63 | + testthat::skip_if(desc_path == "", message = "echogithub not installed") |
| 64 | + d <- desc::desc(desc_path) |
| 65 | + res <- echogithub:::description_extract_i( |
| 66 | + desc_file = d, |
| 67 | + fields = c("owner", "repo", "authors"), |
| 68 | + verbose = FALSE |
| 69 | + ) |
| 70 | + testthat::expect_true(is.list(res)) |
| 71 | + testthat::expect_true("owner" %in% names(res)) |
| 72 | + testthat::expect_true("repo" %in% names(res)) |
| 73 | + testthat::expect_true("authors" %in% names(res)) |
| 74 | +}) |
| 75 | + |
| 76 | +test_that("description_extract_i extracts owner correctly", { |
| 77 | + testthat::skip_if_not_installed("desc") |
| 78 | + testthat::skip_if_not_installed("rworkflows") |
| 79 | + desc_path <- system.file("DESCRIPTION", package = "echogithub") |
| 80 | + testthat::skip_if(desc_path == "", message = "echogithub not installed") |
| 81 | + d <- desc::desc(desc_path) |
| 82 | + res <- echogithub:::description_extract_i( |
| 83 | + desc_file = d, |
| 84 | + fields = c("owner"), |
| 85 | + verbose = FALSE |
| 86 | + ) |
| 87 | + testthat::expect_equal(res$owner, "RajLabMSSM") |
| 88 | +}) |
| 89 | + |
| 90 | +test_that("description_extract_i extracts repo correctly", { |
| 91 | + testthat::skip_if_not_installed("desc") |
| 92 | + testthat::skip_if_not_installed("rworkflows") |
| 93 | + desc_path <- system.file("DESCRIPTION", package = "echogithub") |
| 94 | + testthat::skip_if(desc_path == "", message = "echogithub not installed") |
| 95 | + d <- desc::desc(desc_path) |
| 96 | + res <- echogithub:::description_extract_i( |
| 97 | + desc_file = d, |
| 98 | + fields = c("repo"), |
| 99 | + verbose = FALSE |
| 100 | + ) |
| 101 | + testthat::expect_equal(res$repo, "echogithub") |
| 102 | +}) |
| 103 | + |
| 104 | +test_that("description_extract_i returns NULL when desc_file is NULL", { |
| 105 | + testthat::skip_if_not_installed("rworkflows") |
| 106 | + res <- echogithub:::description_extract_i(desc_file = NULL, |
| 107 | + verbose = FALSE) |
| 108 | + testthat::expect_null(res) |
| 109 | +}) |
| 110 | + |
| 111 | +test_that("description_extract_i extracts DESCRIPTION-native fields", { |
| 112 | + testthat::skip_if_not_installed("desc") |
| 113 | + testthat::skip_if_not_installed("rworkflows") |
| 114 | + desc_path <- system.file("DESCRIPTION", package = "echogithub") |
| 115 | + testthat::skip_if(desc_path == "", message = "echogithub not installed") |
| 116 | + d <- desc::desc(desc_path) |
| 117 | + res <- echogithub:::description_extract_i( |
| 118 | + desc_file = d, |
| 119 | + fields = c("Package", "Version"), |
| 120 | + verbose = FALSE |
| 121 | + ) |
| 122 | + testthat::expect_true("Package" %in% names(res)) |
| 123 | + testthat::expect_equal(res$Package, "echogithub") |
| 124 | +}) |
| 125 | + |
| 126 | +test_that("description_extract_i as_datatable returns data.table", { |
| 127 | + testthat::skip_if_not_installed("desc") |
| 128 | + testthat::skip_if_not_installed("rworkflows") |
| 129 | + desc_path <- system.file("DESCRIPTION", package = "echogithub") |
| 130 | + testthat::skip_if(desc_path == "", message = "echogithub not installed") |
| 131 | + d <- desc::desc(desc_path) |
| 132 | + res <- echogithub:::description_extract_i( |
| 133 | + desc_file = d, |
| 134 | + fields = c("Package"), |
| 135 | + as_datatable = TRUE, |
| 136 | + verbose = FALSE |
| 137 | + ) |
| 138 | + testthat::expect_true(data.table::is.data.table(res)) |
| 139 | +}) |
| 140 | + |
| 141 | +test_that("description_extract_i extracts github_url field", { |
| 142 | + testthat::skip_if_not_installed("desc") |
| 143 | + testthat::skip_if_not_installed("rworkflows") |
| 144 | + desc_path <- system.file("DESCRIPTION", package = "echogithub") |
| 145 | + testthat::skip_if(desc_path == "", message = "echogithub not installed") |
| 146 | + d <- desc::desc(desc_path) |
| 147 | + res <- echogithub:::description_extract_i( |
| 148 | + desc_file = d, |
| 149 | + fields = c("github_url"), |
| 150 | + verbose = FALSE |
| 151 | + ) |
| 152 | + testthat::expect_true("github_url" %in% names(res)) |
| 153 | + testthat::expect_true(grepl("github.com", res$github_url)) |
| 154 | +}) |
0 commit comments