aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/redefine.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2019-01-05 19:30:00 -0800
committerDaniel Mueller <deso@posteo.net>2019-01-05 19:30:00 -0800
commitb4516220b95743b485b9bcd8226285255be9c9c4 (patch)
tree389d17e14b012c64f57a0947257d298ebea29789 /nitrocli/src/redefine.rs
parent6d07a0c9d9a9b39247a9727dea2d90eba4e1fe9e (diff)
downloadnitrocli-b4516220b95743b485b9bcd8226285255be9c9c4.tar.gz
nitrocli-b4516220b95743b485b9bcd8226285255be9c9c4.tar.bz2
Emit all output to custom stdio channels
This change continues and concludes the effort of using customizable stdio channels for output of data from the program. It does so by replacing the standard println macro with a custom one that outputs the data to the supplied context's stdout object. Because this object is injected from the main function, it will be possible for tests invoking this function to supply custom Write objects that can buffer this data and make it available for verification purposes.
Diffstat (limited to 'nitrocli/src/redefine.rs')
-rw-r--r--nitrocli/src/redefine.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/nitrocli/src/redefine.rs b/nitrocli/src/redefine.rs
new file mode 100644
index 0000000..a79cb4b
--- /dev/null
+++ b/nitrocli/src/redefine.rs
@@ -0,0 +1,38 @@
+// redefine.rs
+
+// *************************************************************************
+// * Copyright (C) 2019 Daniel Mueller (deso@posteo.net) *
+// * *
+// * This program is free software: you can redistribute it and/or modify *
+// * it under the terms of the GNU General Public License as published by *
+// * the Free Software Foundation, either version 3 of the License, or *
+// * (at your option) any later version. *
+// * *
+// * This program is distributed in the hope that it will be useful, *
+// * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+// * GNU General Public License for more details. *
+// * *
+// * You should have received a copy of the GNU General Public License *
+// * along with this program. If not, see <http://www.gnu.org/licenses/>. *
+// *************************************************************************
+
+// A replacement of the standard println!() macro that requires an
+// execution context as the first argument and prints to its stdout.
+macro_rules! println {
+ ($ctx:expr) => {
+ writeln!($ctx.stdout, "")
+ };
+ ($ctx:expr, $($arg:tt)*) => {
+ writeln!($ctx.stdout, $($arg)*)
+ };
+}
+
+macro_rules! eprintln {
+ ($ctx:expr) => {
+ writeln!($ctx.stderr, "")
+ };
+ ($ctx:expr, $($arg:tt)*) => {
+ writeln!($ctx.stderr, $($arg)*)
+ };
+}