Repository: LukasKalbertodt/bunt (language: rust)

Issue:
Support omitting format string
For example `println!()` or `writeln!(stream)` would just write a line break.

This mirrors the functionality of the std macros, making these more of a drop in replacement. Note the [write_with_newline](https://rust-lang.github.io/rust-clippy/master/#write_with_newline) clippy lint prefers this short form, which can be annoying since it also triggers when using `writeln` from this crate.


Discussion / hints:

Fix patch:
diff --git a/src/lib.rs b/src/lib.rs
index 43f4b14..1f05a25 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -208,6 +208,9 @@ macro_rules! writeln {
             $target [$($format_str)+] $( $arg )*
         )
     };
+    ($target:expr $(,)?) => {
+        $crate::writeln!($target, "")
+    };
 }
 
 /// Writes formatted data to stdout (with `ColorChoice::Auto`).
@@ -255,6 +258,9 @@ macro_rules! println {
             [$($format_str)+] $( $arg )*
         ).expect("failed to write to stdout in `bunt::println`")
     };
+    () => {
+        std::println!()
+    };
 }
 
 /// Writes formatted data to stderr (with `ColorChoice::Auto`).
@@ -302,6 +308,9 @@ macro_rules! eprintln {
             [$($format_str)+] $( $arg )*
         ).expect("failed to write to stderr in `bunt::eprintln`")
     };
+    () => {
+        std::eprintln!()
+    };
 }
 
 /// Parses the given style specification string and returns the corresponding


Test patch:
diff --git a/tests/main.rs b/tests/main.rs
index 4551df1..7e8906b 100644
--- a/tests/main.rs
+++ b/tests/main.rs
@@ -110,6 +110,19 @@ fn no_move_args() {
     }
 }
 
+#[test]
+fn empty_ln() {
+    // Just make sure they compile, we cannot easily capture and test their output.
+    println!();
+    eprintln!();
+
+
+    let mut b = buf();
+    writeln!(b).unwrap();
+    writeln!(b,).unwrap();
+    assert_eq!(raw_str(&b), "\n\n");
+}
+
 #[test]
 fn arg_referal() {
     check!("27" == "{peter}", peter = 27);