---
title: "Tests and Coverage"
date: "`r format(Sys.time(), '%d %B, %Y %H:%M:%S')`"
---

This output is created by [covrpage](https://github.com/yonicd/covrpage).

```{r load,include=FALSE}
library(covr     , warn.conflicts = FALSE , quietly = TRUE)
library(knitr    , warn.conflicts = FALSE , quietly = TRUE)
library(magrittr , warn.conflicts = FALSE , quietly = TRUE)

```

```{r tests, include=FALSE}
#test_x <- testthat::test_dir('testthat')
this_pkg <- basename(normalizePath('..'))
test_x <- testthat::test_check(this_pkg,reporter = testthat::default_reporter(),stop_on_failure = FALSE,stop_on_warning = FALSE)

skip <- length(test_x)>0
failed <- FALSE
```

```{r maps, include=FALSE}
test_m <- covrpage::map_testthat('testthat')
```


```{r, include=FALSE}
test_x_short <- test_x%>%
  covrpage::testthat_summary(type='short')

test_x_long <- test_x%>%
  covrpage::testthat_summary(type='long')

```
 
```{r, include=FALSE,eval=skip}
test_skip <- test_x_long[test_x_long$status!='PASS',c('file','test')]

test_skip$file <- gsub('#(.*?)$','',basename(test_skip$file))

test_skip <- merge(test_skip,test_m)

failed <- any(test_x_long$status%in%c('ERROR','FAILED'))

```

```{r, include=FALSE,eval=!skip}

test_skip <- test_m

```

## Coverage

Coverage summary is created using the [covr](https://github.com/r-lib/covr) package.

```{r,include=FALSE}
cvr <- covrpage::coverage_skip(test_path = '../tests/testthat', test_skip = test_skip)
```

```{r,echo=FALSE,eval=failed}
cat(sprintf('%s Not All Tests Passed\n  Coverage statistics are approximations of the non-failing tests.\n  Use with caution\n\n For further investigation check in testthat summary tables.',covrpage:::emos[[platform()]][['WARNING']]))
```

```{r,echo=FALSE}
cvr%>%
  covrpage::covr_summary(failed = failed)%>%
  knitr::kable(digits = 2,
             col.names = c('Object','Coverage (%)'),align = c('l','c'))

```

<br>

## Unit Tests

Unit Test summary is created using the [testthat](https://github.com/r-lib/testthat) package.

```{r,echo=FALSE,warning=FALSE,message=FALSE,eval=!skip}
cat('All tests were skipped')
```

```{r,echo=FALSE,warning=FALSE,message=FALSE,eval=skip}

test_x_short%>%
  knitr::kable()

```

<details `r sprintf('%s',if(skip) test_details(test_x_short))`>
  <summary> Show Detailed Test Results </summary>

```{r,echo=FALSE,warning=FALSE,message=FALSE,eval=!skip}
cat('All tests were skipped')
```

```{r,echo=FALSE,warning=FALSE,message=FALSE,eval=skip}

test_x_long%>%
  knitr::kable()

```

```{r,echo=FALSE}
if(length(names(test_x_long))>0){
if('icon'%in%names(test_x_long)){
  emos <- covrpage:::emos[[covrpage:::platform()]]
  knitr::kable(t(c('Failed' = emos[['FAILED']],'Warning' = emos[['WARNING']], 'Skipped' = emos[['SKIPPED']])))
}  
}
```

</details>

<details>
  <summary> Session Info </summary>
  
```{r,echo=FALSE,warning=FALSE,message=FALSE}

x <- covrpage:::sinfo()

x$info%>%
  knitr::kable()

x$pkgs%>%
  knitr::kable()

```

</details>

`r sprintf('<!--- Final Status : %s --->', test_to_badge(test_x_short))`
