Skip to content

Commit

Permalink
test: Adding extra tests for codecov computing in inflate and inflate…
Browse files Browse the repository at this point in the history
…_all

We checks whether codecov updates accordingly when we add extra tests in our flat files

#256
  • Loading branch information
yohann committed Jun 17, 2024
1 parent f29d4e2 commit 36ffcc5
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
45 changes: 45 additions & 0 deletions dev/flat_inflate_all.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,50 @@ usethis::with_project(dummypackage, {
)
})
# We add a "real" unit test in our flat file to reach a 100% coverage
flat_content <- readLines(dev_file1)
flat_content[grepl("expect_true", flat_content)] <- "expect_equal(flat1_rmd(), 1)"
writeLines(flat_content, dev_file1)
capture.output(
inflate_all(
pkg = dummypackage,
check = FALSE,
codecov = TRUE
),
file = console_output_file,
type = "message"
)
test_that("inflate outputs compute codecov correctly", {
res <- readLines(console_output_file)
expect_true(
any(grepl(
pattern = "Computing code coverage - it might take some time",
x = res
))
)
expect_true(
any(grepl(
pattern = "R/flat1_rmd.R: 100.00%",
x = res
))
)
expect_true(
any(grepl(
pattern = paste(
basename(dummypackage),
"Coverage: 100.00%"
),
x = res
))
)
})
capture.output(
inflate_all(
check = FALSE,
Expand All @@ -1046,6 +1090,7 @@ usethis::with_project(dummypackage, {
type = "message"
)
test_that("inflate does not compute codecov if not asked", {
res <- readLines(console_output_file)
Expand Down
33 changes: 33 additions & 0 deletions tests/testthat/test-inflate-part3.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ usethis::with_project(dummypackage, {
)
})

# We add a "real" unit test in our flat file to reach a 100% coverage
flat_content <- readLines(dev_file1)
flat_content[grepl("expect_true", flat_content)] <- "expect_equal(flat1_rmd(), 1)"
writeLines(flat_content, dev_file1)

capture.output(
inflate(
Expand All @@ -111,6 +115,35 @@ usethis::with_project(dummypackage, {
file = console_output_file,
type = "message"
)

test_that("inflate outputs compute codecov correctly", {
res <- readLines(console_output_file)

expect_true(
any(grepl(
pattern = "Computing code coverage - it might take some time",
x = res
))
)

expect_true(
any(grepl(
pattern = "R/flat1_rmd.R: 100.00%",
x = res
))
)


expect_true(
any(grepl(
pattern = paste(
basename(dummypackage),
"Coverage: 100.00%"
),
x = res
))
)
})
})

unlink(console_output_file)
Expand Down
45 changes: 45 additions & 0 deletions tests/testthat/test-inflate_all.R
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,50 @@ usethis::with_project(dummypackage, {
)
})

# We add a "real" unit test in our flat file to reach a 100% coverage
flat_content <- readLines(dev_file1)
flat_content[grepl("expect_true", flat_content)] <- "expect_equal(flat1_rmd(), 1)"
writeLines(flat_content, dev_file1)

capture.output(
inflate_all(
pkg = dummypackage,
check = FALSE,
codecov = TRUE
),
file = console_output_file,
type = "message"
)

test_that("inflate outputs compute codecov correctly", {
res <- readLines(console_output_file)

expect_true(
any(grepl(
pattern = "Computing code coverage - it might take some time",
x = res
))
)

expect_true(
any(grepl(
pattern = "R/flat1_rmd.R: 100.00%",
x = res
))
)


expect_true(
any(grepl(
pattern = paste(
basename(dummypackage),
"Coverage: 100.00%"
),
x = res
))
)
})

capture.output(
inflate_all(
check = FALSE,
Expand All @@ -759,6 +803,7 @@ usethis::with_project(dummypackage, {
type = "message"
)


test_that("inflate does not compute codecov if not asked", {
res <- readLines(console_output_file)

Expand Down

0 comments on commit 36ffcc5

Please sign in to comment.