Skip to content

Commit

Permalink
Add very basic tttf.r
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed Aug 10, 2023
1 parent ff4d5ef commit 4d89f6f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* inst/examples/r2u.r: Add two more options for modifying the Debian
version of a package being built

* inst/examples/tttf.r: Very initial version of a single file
testthat runner (aka 'testthat::test_file()'

2023-07-15 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (Date, Version): Roll micro version and date
Expand Down
45 changes: 45 additions & 0 deletions inst/examples/tttf.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env r
#
# testthat::test_file wrapper
#
# Copyright (C) 2019 - 2023 Dirk Eddelbuettel
#
# Released under GPL (>= 2)

if (!requireNamespace("testthat", quietly=TRUE))
stop("Please install 'testthat' from CRAN.", call. = FALSE)

## load docopt and tinytest from CRAN
suppressMessages({
library(docopt) # we need docopt (>= 0.3) as on CRAN
})

## configuration for docopt
doc <- "Usage: tttf.r [-l LIB] [-h] [-x] ARG
-l --library LIIB load named library
-h --help show this help text
-x --usage show help and short example usage"
opt <- docopt(doc) # docopt parsing

if (opt$usage) {
cat(doc, "\n\n")
cat("where ARG can be a package directory.
Examples:
tttf.r test-testfile.r # run test_file() on the given file
tttf.r is part of littler which brings 'r' to the command-line.
See https://dirk.eddelbuettel.com/code/littler.html for more information.\n")
q("no")
}

if (!file.exists(opt$ARG)) {
stop("No such file.", call. = FALSE)
}

if (!is.null(opt$LIB)) {
library(opt$LIB)
}

testthat::test_file(path=opt$ARG)
2 changes: 1 addition & 1 deletion inst/examples/tttl.r
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Examples:
tttl.r # run test_local() if DESCRIPTION && tests/testthat/
tttl.r # run test_local() if in tests/testthat directory
ttlr.r is part of littler which brings 'r' to the command-line.
tttl.r is part of littler which brings 'r' to the command-line.
See https://dirk.eddelbuettel.com/code/littler.html for more information.\n")
q("no")
}
Expand Down

0 comments on commit 4d89f6f

Please sign in to comment.