Skip to content

Commit

Permalink
Improve test detction.
Browse files Browse the repository at this point in the history
Reduce generic test detection. (in snap files)
Add test for NEWS
Enable back h1 to have code inside.
  • Loading branch information
olivroy committed Jun 3, 2024
1 parent 6ab0c3f commit 752d92b
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 15 deletions.
5 changes: 3 additions & 2 deletions R/outline-criteria.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ o_is_test_that <- function(x) {
}

o_is_generic_test <- function(x) {
stringr::str_detect(x, "works\"|correctly\"|properly\"|expected\"")
# remove " detection to avoid discovering snapshot files.
stringr::str_detect(x, "works|correctly|properly|expected")
}

# Returns table or plot titles.
Expand Down Expand Up @@ -102,7 +103,7 @@ o_is_section_title <- function(x, roxy_section = FALSE) {
uninteresting_headings <- paste(
"(Tidy\\s?T(uesday|emplate)|Readme|Wrangle|Devel)$|error=TRUE",
"url\\{|Error before installation|unreleased|Function ID$|Function Introduced",
"Examples$|Newly broken$|Newly fixed$|In both$|Installation$|MIT License|nocov|With cli$|sourceCode|Detect #'",
"Usage$|Examples?$|Newly broken$|Newly fixed$|In both$|Installation$|MIT License|nocov|With cli$|sourceCode|Detect #'",
sep = "|"
)
# potential section titles
Expand Down
2 changes: 1 addition & 1 deletion R/outline.R
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ keep_outline_element <- function(.data) {
# still regular comments in .md files
# what to keep in .md docs

(is_md & (is_chunk_cap | (is_section_title & before_and_after_empty & !is_a_comment_or_code))) |
(is_md & (is_chunk_cap | (is_section_title & before_and_after_empty))) |
# What to keep in .R files
(!is_md & is_section_title_source) |
# What to keep anywhere
Expand Down
57 changes: 45 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ bench::mark(
#> # A tibble: 1 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 outline <- proj_outline() 524ms 524ms 1.91 20.9MB 3.82
#> 1 outline <- proj_outline() 489ms 524ms 1.91 21.2MB 3.81
```

<details>
Expand Down Expand Up @@ -278,26 +278,62 @@ outline
#> `i` Second level
#> `i` TODO this is an item- `Done✔?`
#> `i` Last title
#> `i` `function_name()` title
#>
#> ── `tests/testthat/_snaps/browse-pkg.md`
#> `i` browse_pkg() works
#>
#> ── `tests/testthat/_snaps/case-if-any.md`
#> `i` case_if_any() basic work
#> `i` wrong cases error
#>
#> ── `tests/testthat/_snaps/dplyr-plus.md`
#> `i` filter_if_any() errors with across()
#> `i` adds rows in front, but warns the user
#> `i` summarise_with_total() works
#> `i` slice_min_max() works
#> `i` na_if2() works with expr and values
#>
#> ── `tests/testthat/_snaps/eda-identity.md`
#> `i` Side effects are what's intended in interactive sessions
#>
#> ── `tests/testthat/_snaps/escape-inline-markup.md`
#> `i` escape_markup() works
#> `i` replace_r_var() works
#>
#> ── `tests/testthat/_snaps/markup.md`
#> `i` link_gh_issue() + markup_href() work
#>
#> ── `tests/testthat/_snaps/outline-criteria.md`
#> `i` No outline criteria are untested
#>
#> ── `tests/testthat/_snaps/outline.md`
#> `i` file_outline() works
#> `i` alpha and work_only arguments work
#> `i` file_outline() is a data frame
#> `i` pattern works as expected
#>
#> ── `tests/testthat/_snaps/proj-list.md`
#> `i` proj_file() works
#>
#> ── `tests/testthat/_snaps/quarto-help.md`
#> `i` href_name_url() works
#> `i` quarto_help() works
#>
#> ── `tests/testthat/_snaps/rename.md`
#> `i` rename_files2(): prevents file renaming if conflicts
#> `i` rename_files2(): is easier to test messages with no action
#> `i` rename_files2(): renames files if forced to do so
#> `i` rename_files2(): doesn't check for references if file name is short
#> `i` rename_files2(): priorizes references if name is generic or widely used in files
#> `i` rename_files2(): can accept overridden preferences
#> `i` rename_files2(): relaxes its conditions for figures
#> `i` rename_files2(): calls check_referenced_files()
#> `i` Helper files returns the expected input
#>
#> ── `tests/testthat/_snaps/screenshot.md`
#> `i` screenshot() does nothing in non-interactive sessions
#>
#> ── `tests/testthat/_snaps/todo.md`
#> `i` Marking a TODO item as done works
#>
Expand All @@ -307,12 +343,10 @@ outline
#> `i` case_if_any() can use a newly created variable (#8 (<https://github.com/olivroy/reuseme/issues/8>))
#>
#> ── `tests/testthat/test-dplyr-plus.R`
#> `i` filter_if_any() errors correctly when using `by` instead of `.by`
#> `i` filter_if_any() errors with across()
#> `i` TODO improve this error- `Done✔?`
#> `i` adds rows in front, but warns the user
#> `i` summarise_with_total() keeps factors
#> `i` na_if2() works with expr and values
#>
#> ── `tests/testthat/test-eda-identity.R`
#> `i` Returns identity
Expand Down Expand Up @@ -340,21 +374,15 @@ outline
#> `i` TODO change tests for data frame size when stable (efficiency). As stil…- `Done✔?`
#> `i` file_outline() with only title doesn't error
#> `i` file_outline() contains function calls
#> `i` dir_outline() works with no error
#>
#> ── `tests/testthat/test-rename.R`
#> `i` Helper files returns the expected input
#> `i` force and action are deprecated
#>
#> ── `tests/testthat/test-screenshot.R`
#> `i` screenshot() does nothing in non-interactive sessions
#>
#> ── `tests/testthat/test-todo.R`
#> `i` Marking TODO as done detects tags
#> `i` TODO items are correctly stripped
#>
#> ── `tests/testthat/test-utils.R`
#> `i` Windows is recognized correctly.
#>
#> ── `TODO.R`
#> `i` TODO screenshot make the behaviour different when vignettes vs articl…- `Done✔?`
Expand Down Expand Up @@ -388,18 +416,23 @@ outline
#>
#> ── `NEWS.md`
#> `i` reuseme (development version)
#> `i` reuseme 0.0.2
#> `i` reuseme 0.0.1
#>
#> ── `README.Rmd`
#> `i` reuseme
#> `i` Installation
#> `i` Getting started
#> `i` Example
#> `i` hello
#> `i` Extend usethis functionality
#> `i` Proposing a data analysis workflow
#> `i` Outline speed
#>
#> ── `tests/testthat/_outline/NEWS.md`
#> `i` Package 202a20.9000
#> `i` Package (development)
#> `i` Pac
#> `i` Package 1.0-0
#> `i` Package 0.9-0
#> `i` Package 0.1-0
```

</p>
Expand Down
34 changes: 34 additions & 0 deletions tests/testthat/_outline/NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Package 202a20.9000

* Test news file for different versioning

## Ignore second-level heading.

# Package (development)

# Pac

# Package 1.0-16

# Package 1.0-0

# Package 0.9-8

# Package 0.9-7

# Package 0.9-6

# Package 0.9-5


# Package 0.9-0

# Package 0.5-4

# Package 0.2-2

# Package 0.1-1

* Ignore patch versions when many versions.

# Package 0.1-0
7 changes: 7 additions & 0 deletions tests/testthat/test-outline.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ test_that("file_outline() works", {
)
})

test_that("file_outline() works for NEWS", {
expect_equal(
nrow(file_outline(path = test_path("_outline", "NEWS.md"))),
6
)
})

test_that("alpha and work_only arguments work", {
my_test_file <- test_path("_outline/my-analysis.R")
rlang::local_interactive(TRUE)
Expand Down

0 comments on commit 752d92b

Please sign in to comment.