[latex3-commits] [git/LaTeX3-latex3-l3build] experimental: Added output stream handlers. (f7eb4cd)
Paulo Roberto Massa Cereda
cereda.paulo at gmail.com
Tue Aug 6 18:33:12 CEST 2019
Repository : https://github.com/latex3/l3build
On branch : experimental
Link : https://github.com/latex3/l3build/commit/f7eb4cd970efdc49fb1c20fe8ec935e49095b01b
>---------------------------------------------------------------
commit f7eb4cd970efdc49fb1c20fe8ec935e49095b01b
Author: Paulo Roberto Massa Cereda <cereda.paulo at gmail.com>
Date: Tue Aug 6 13:33:12 2019 -0300
Added output stream handlers.
- Added functions to write to both standard output and error.
- Added function variants with linebreak support.
- Removed unused variables from a couple of tests.
>---------------------------------------------------------------
f7eb4cd970efdc49fb1c20fe8ec935e49095b01b
l3build-text.lua | 45 ++++++++++++++++++++++++++++++++++++
unittests/test_l3build-arguments.lua | 8 +++----
2 files changed, 49 insertions(+), 4 deletions(-)
diff --git a/l3build-text.lua b/l3build-text.lua
index 787f78d..8e18ca0 100644
--- a/l3build-text.lua
+++ b/l3build-text.lua
@@ -40,6 +40,11 @@ utils.config = package.config
utils.sub = string.sub
utils.find = string.find
utils.byte = string.byte
+utils.tostring = tostring
+utils.io = io
+
+l3text.stdout = {}
+l3text.stderr = {}
--- Ensures the variable holds any value or falls back to a default value.
-- This function ensures the variable holds any value or falls back to a
@@ -209,5 +214,45 @@ function l3text.wrap(text, width, shift, first)
return (first and pad(' ', shift) or '') .. wrapped
end
+--- Prints the provided parameter in the standard output, with no linebreak.
+-- This function prints the provided parameter in the standard output,
+-- without adding a trailing linebreak. The parameter is properly converted
+-- to its string representation based on the underlying `tostring` function, as
+-- a typical `print` implementation does.
+-- @param The parameter to be printed in the standard output.
+function l3text.stdout.print(a)
+ utils.io.write(utils.tostring(a))
+end
+
+--- Prints the provided parameter in the standard output, with a linebreak.
+-- This function prints the provided parameter in the standard output,
+-- adding a trailing linebreak. The parameter is properly converted to its
+-- string representation based on the underlying `tostring` function, as a
+-- typical `print` implementation does.
+-- @param The parameter to be printed in the standard output.
+function l3text.stdout.println(a)
+ utils.io.write(utils.tostring(a) .. l3text.linebreak())
+end
+
+--- Prints the provided parameter in the standard error, with no linebreak.
+-- This function prints the provided parameter in the standard error,
+-- without adding a trailing linebreak. The parameter is properly converted
+-- to its string representation based on the underlying `tostring` function, as
+-- a typical `print` implementation does.
+-- @param The parameter to be printed in the standard error.
+function l3text.stderr.print(a)
+ utils.io.stderr:write(utils.tostring(a))
+end
+
+--- Prints the provided parameter in the standard error, with a linebreak.
+-- This function prints the provided parameter in the standard error,
+-- adding a trailing linebreak. The parameter is properly converted to its
+-- string representation based on the underlying `tostring` function, as a
+-- typical `print` implementation does.
+-- @param The parameter to be printed in the standard error.
+function l3text.stderr.println(a)
+ utils.io.stderr:write(utils.tostring(a) .. l3text.linebreak())
+end
+
-- export module
return l3text
diff --git a/unittests/test_l3build-arguments.lua b/unittests/test_l3build-arguments.lua
index 1c932cb..00b013f 100644
--- a/unittests/test_l3build-arguments.lua
+++ b/unittests/test_l3build-arguments.lua
@@ -48,12 +48,12 @@ function testValidTarget()
end
function testInvalidTarget()
- local a, b = l3args.argparse(targets, options, { 'chekc' })
+ local _, b = l3args.argparse(targets, options, { 'chekc' })
lu.assertTrue(b['target'])
end
function testInvalidTarget()
- local a, b = l3args.argparse(targets, options, { 'chekc' })
+ local _, b = l3args.argparse(targets, options, { 'chekc' })
lu.assertTrue(b['target'])
end
@@ -177,13 +177,13 @@ function testDuplicateShortParametricOptions()
end
function testInvalidOptions()
- local a, b = l3args.argparse(targets, options, { 'check', '-v=2.1' })
+ local _, b = l3args.argparse(targets, options, { 'check', '-v=2.1' })
lu.assertEquals(b['invalid'], { '--version' })
lu.assertEquals(b['remainder'], { '2.1' })
end
function testUnknownOptions()
- local a, b = l3args.argparse(targets, options, { 'check', '-abc=2.1' })
+ local _, b = l3args.argparse(targets, options, { 'check', '-abc=2.1' })
lu.assertEquals(b['unknown'], { '-abc' })
lu.assertEquals(b['remainder'], { '2.1' })
end
More information about the latex3-commits
mailing list