Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 27e04eb
  • /
  • testthat
  • /
  • test-build-news.R
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:0a12e8f137316e31ba88b97cc0a4937a9b6aed8d
directory badge Iframe embedding
swh:1:dir:8202d8d3cabcb54cbec8e0f68269e780d6392dd2

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
test-build-news.R
context("test-build-news.R")

test_that("github links are added to news items", {
  skip_if_no_pandoc()

  path <- test_path("assets/news-github-links")
  pkg <- as_pkgdown(path)
  news_tbl <- data_news(pkg)

  user_link <- "<a href='https://github.com/hadley'>@hadley</a>"
  user_link2 <- "<a href='https://github.com/josue-rodriguez'>@josue-rodriguez</a>"
  issue_link <- "<a href='https://github.com/hadley/pkgdown/issues/100'>#100</a>"

  expect_true(grepl(user_link, news_tbl$html))
  expect_true(grepl(user_link2, news_tbl$html))
  expect_true(grepl(issue_link, news_tbl$html))
})

test_that("build_news() uses content in NEWS.md", {
  skip_if_no_pandoc()

  pkg <- test_path("assets/news")

  expect_output(build_news(pkg))
  on.exit(clean_site(pkg))

  lines <- read_lines(path(pkg, "docs", "news", "index.html"))
  test_strings <- c(
    "testpackage", "1.0.0.9000", "1.0.0[^\\.]",
    "sub-heading", "@githubuser", "bullet", "#111"
  )
  expect_true(all(
    vapply(test_strings, function(x) any(grepl(x, lines)), logical(1))
  ))
})

test_that("pkg_timeline fails cleanly for unknown package", {
  skip_on_cran()
  expect_null(pkg_timeline("__XYZ___"))
})

test_that("correct timeline for first ggplot2 releases", {
  skip_on_cran()

  timeline <- pkg_timeline("ggplot2")[1:3, ]
  expected <- data.frame(
    version = c("0.5", "0.5.1", "0.5.2"),
    date = as.Date(c("2007-06-01", "2007-06-09", "2007-06-18")),
    stringsAsFactors = FALSE
  )

  expect_equal(timeline, expected)
})

test_that("multi-page news are rendered", {
  skip_if_no_pandoc()

  path <- test_path("assets/news-multi-page")
  pkg <- as_pkgdown(path)
  on.exit(clean_site(pkg))
  expect_output(build_news(pkg))

  # test that index links are correct
  lines <- read_lines(path(path, "docs", "news", "index.html"))
  expect_true(any(grepl("<a href=\"news-2.0.html\">Version 2.0</a>", lines)))

  # test single page structure
  lines <- read_lines(path(path, "docs", "news", "news-1.0.html"))
  expect_true(any(grepl("<h1>Changelog <small>1.0</small></h1>", lines)))
})


# news_title and version_page -----------------------------------------------

test_that("can recognise common forms of title", {
  version <- news_version(c(
    "pkgdown 1.3.0",
    "pkgdown v1.3.0",
    "pkgdown (development version)"
  ))
  expect_equal(version, c("1.3.0", "1.3.0", "development version"))
})

test_that("correctly collapses version to page for common cases", {
  versions <- c("1.0.0", "1.0.0.0", "1.0.0.9000", "development version")
  pages <- purrr::map_chr(versions, version_page)
  expect_equal(pages, c("1.0", "1.0", "dev", "dev"))
})

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API