From 4d89f6f096032f2d9ee37a49583f9f2507121a4a Mon Sep 17 00:00:00 2001 From: Dirk Eddelbuettel Date: Wed, 9 Aug 2023 19:53:01 -0500 Subject: [PATCH] Add very basic tttf.r --- ChangeLog | 3 +++ inst/examples/tttf.r | 45 ++++++++++++++++++++++++++++++++++++++++++++ inst/examples/tttl.r | 2 +- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 inst/examples/tttf.r diff --git a/ChangeLog b/ChangeLog index 89cebcd..8d50c66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 * DESCRIPTION (Date, Version): Roll micro version and date diff --git a/inst/examples/tttf.r b/inst/examples/tttf.r new file mode 100755 index 0000000..d8e4975 --- /dev/null +++ b/inst/examples/tttf.r @@ -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) diff --git a/inst/examples/tttl.r b/inst/examples/tttl.r index 81d58f5..4f118d7 100755 --- a/inst/examples/tttl.r +++ b/inst/examples/tttl.r @@ -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") }